No provider for MapEventsManagerService
See original GitHub issueIntended 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:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
hi, I will try to explain better,
ac-map
is the provider for all the util services likeMapEventsManagerService
. it uses angular dependency injection soac-map
component will look something like that:Therefor in order to have access to a service that is provided by a child component you have 2 ways:
@ChildView()
decorator: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 byac-map
because it is per map instance.I have managed to handle the click event using the
ViewChild
approach. The problem was related to theEventRegistrationInput
object: that options prevented the click event to fire up. I guess I’m closing this…