question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No provider for MapEventsManagerService

See original GitHub issue

Intended outcome: I am trying to handle the left click on the ac-map.

Actual outcome: Firstly I tried to inject the MapEventsManagerService in the constructor of my component but I got No provider for MapEventsManagerService error in console.

//ts file
@Component(...)
private provider = Cesium.ArcGisMapServerImageryProvider;
export class SomeComponent{
  constructor(private eventManager: MapEventsManagerService){
    const eventRegistration: EventRegistrationInput = {
      event: CesiumEvent.LEFT_CLICK, // event type enum. [required!]
      modifier: CesiumEventModifier.CTRL, // event modifier enum. [optional]
      entityType: AcEntity, // raise event only if AcEntity is clicked. [optional] 
      priority: 0, // event priority, default 0 . [optional]
      pick: PickOptions.PICK_FIRST // entity pick option, default PickOptions.NO_PICK. [optional]
    };
    const clickEvent = this.eventManager.register(eventRegistration).subscribe((result) => {
    	  console.log('map click', result.movement, 'primitives:', result.primitives, 'entities', result.entities);
    	});
  } 
}

I even changed the entityType: AcEntity to entityType: AcMapComponent because I thought it’d make a difference.

//html
<ac-map></ac-map>

Secondly I tried to take a reference to the ac-map component with @ViewChild, i.e.

@ViewChild(AcMapComponent) acmap: AcMapComponent;
...
ngOnInit() { // I used the ngOnInit to register the event because the property acmap is set after the constructor calls
    var eventManager = this.acmap.getMapEventsManager();
    ...
    // same code as above
}

In this case the error No provider for MapEventsManagerService doesn’t show up, but nothing happens when clicking the map.

How to reproduce the issue: In order to reproduce this issue, it is enough to create a template file which consists of a ac-map component, then create and subscribe to the map click event as stated in the readme. I also tried to include a ac-map-layer-provider like this:

<ac-map>
    <ac-map-layer-provider  *ngIf="true"
                            [provider]="provider"
                            [options]="{
                                url : 'https://server.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer'
                            }">
    </ac-map-layer-provider>
</ac-map>

Version

  • angular-cesium@0.0.38

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
eitanfrcommented, Dec 11, 2017

hi, I will try to explain better, ac-map is the provider for all the util services like MapEventsManagerService . it uses angular dependency injection so ac-map component will look something like that:

@Component({
  selector: 'ac-map',
  providers: [MapEventsManagerService, ...]
})
class AcMapComponent {}

Therefor in order to have access to a service that is provided by a child component you have 2 ways:

  • Create child component and ask for it in the constructor , example
  • Use angular @ChildView() decorator:
// in your component
@ChildView(AcMapComponent) acMap;

ngAfterViewInit() {
  this.acMap.getMapEventsManager();
}
  • Another way is to use our MapsManagerService as shown here. this service allows you to reach your map components any where in your code.

MapEventsManagerService and other util services must be provided by ac-map because it is per map instance.

0reactions
danigrosucommented, Dec 12, 2017

I have managed to handle the click event using the ViewChild approach. The problem was related to the EventRegistrationInput object: that options prevented the click event to fire up. I guess I’m closing this…

Read more comments on GitHub >

github_iconTop Results From Across the Web

MapEventsManagerService - Angular Cesium
File. projects/angular-cesium/src/lib/angular-cesium/services/map-events-mananger/map-events-manager.ts. Description. Manages all map events.
Read more >
Angular no provider for NameService - Stack Overflow
I have tried adding a service in app.module.shared.ts in @NgModule section : providers: [DataManagerService] but still get the error : Error: No provider...
Read more >
angular-cesium - npm
Create map based applications using cesium and angular2 components. Focusing on high performance with easy usage. Check out our Demo that ...
Read more >
NG0201: No provider for {token} found! - Angular
A provider is a mapping that supplies a value that you can inject into the constructor of a class in your application. Read...
Read more >
angular-cesium: Docs, Community, Tutorials, Reviews
MapEventsManagerService is a util service for managing all the map events (Click, Mouse_up...), it expose easy API for entity selection, event priority ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found