trouble importing GoogleMapsAPIWrapper
Issue description I'm trying to incorporate the marker clusterer code and the first step is to get access to the native google maps object. I've poured through the issues and it seems I can do gain access by importing GoogleMapsAPIWrapper
map.ts
...
import {MapCluster} from "../../components/map-cluster/map-cluster";
...
@Component({
...
directives: [MapCluster]
})
export class MapPage{ ... }
map.html
<sebm-google-map [latitude]="lat" [longitude]="lng" [zoom]="16">
<map-cluster></map-cluster>
</sebm-google-map>
map-clusterer.ts
import {Component} from "@angular/core";
import { GoogleMapsAPIWrapper } from 'angular2-google-maps/core/services';
@Component({
selector: "map-cluster",
templateUrl: "map-cluster.html"
})
export class MapCluster {
constructor(private _wrapper: GoogleMapsAPIWrapper) {
console.log("start");
this._wrapper.getNativeMap().then((map)=>{
console.log(map);
map.setMapTypeId('satellite');
})
}
}
error: bundle dev failed: Module /home/jon/Projects/sma/node_modules/angular2-google-maps/core/index.js does not export GoogleMapsAPIWrapper (imported by /home/jon/Projects/sma/src/components/map-cluster/map-cluster.ts)
I've been trying every which way and combination of import statements, with angular2-google-maps 0.14.0 and 0.15.0. help?
@jonathan-chin
-
Remove
directives: [MapCluster]line from your component -
Change your
map-cluster.tsfrom@Componentto@Directive@Directive({ selector: 'map-cluster', }) -
I create a public property and assign map object to so i can reuse it but it's up to you
-
Now you can access your google map object
-
Now, to actually use MarkerClusterer you need to get your
MarkerManagerthe same way and get list of markers from it before populating clustererexport class MapCluster { googleMap: any; constructor(private gmapsApi: GoogleMapsAPIWrapper, private markerManager: MarkerManager) { this.gmapsApi.getNativeMap().then(map => { this.googleMap = map; this.markerManager.returnMarkers().then(markers => { this.markerClusterer = new MarkerClusterer(this.googleMap, markers); }); }); } ...
@david-mart thanks. I tried some of the changes you suggested. what import statements should I use for map-cluster.ts?
@jonathan-chin i put the module in separate folder because i am trying to customize it a little, so mine looks like this
import { GoogleMapsAPIWrapper } from "../../../modules/googlemaps/services/google-maps-api-wrapper";
import { Directive } from '@angular/core';
import { MarkerManager } from "../../../modules/googlemaps/services/managers/marker-manager";
So you get the idea, it has to be the direct path to file
@david-mart hmm, I still can't get it:
import {GoogleMapsAPIWrapper} from "../../../node_modules/angular2-google-maps/core/services/google-maps-api-wrapper";
the files that exist there are
google-maps-api-wrapper.d.ts google-maps-api-wrapper.js google-maps-api-wrapper.js.map
Thanks for your help. I just started transitioning for angularjs to angular2 last week.
@jonathan-chin have you tried import { GoogleMapsAPIWrapper } from 'angular2-google-maps/core'; ?
Also, i strongly recommend using WebStorm - it takes care of importing pretty much automatically. If there's a type you hit alt+enter and you get your class imported automatically or get prompted to chose if there are multiple choices
@david-mart just tried importing from angular2-google-maps/core and I get the same issue.
any ideas?
as for IDEs, they're usually not in my workflow.
I am having an issue as well with marker clustering using angular2. I get errors like this when trying to access my map page
"error_handler.js:54 EXCEPTION: Uncaught (in promise): Error: DI Error Error: DI Error at NoProviderError.ZoneAwareError (http://localhost:4200/polyfills.bundle.js:7047:33) at NoProviderError.BaseError [as constructor] (http://localhost:4200/vendor.bundle.js:30257:16) at NoProviderError"
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.