angular-google-maps icon indicating copy to clipboard operation
angular-google-maps copied to clipboard

trouble importing GoogleMapsAPIWrapper

Open jonathan-chin opened this issue 10 years ago • 9 comments

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 avatar Oct 16 '16 21:10 jonathan-chin

@jonathan-chin

  1. Remove directives: [MapCluster] line from your component

  2. Change your map-cluster.ts from @Component to @Directive

    @Directive({
      selector: 'map-cluster',
    })
    
  3. I create a public property and assign map object to so i can reuse it but it's up to you

  4. Now you can access your google map object

  5. Now, to actually use MarkerClusterer you need to get your MarkerManager the same way and get list of markers from it before populating clusterer

    export 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 avatar Oct 17 '16 04:10 david-mart

@david-mart thanks. I tried some of the changes you suggested. what import statements should I use for map-cluster.ts?

jonathan-chin avatar Oct 17 '16 04:10 jonathan-chin

@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 avatar Oct 17 '16 04:10 david-mart

@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 avatar Oct 17 '16 04:10 jonathan-chin

@jonathan-chin have you tried import { GoogleMapsAPIWrapper } from 'angular2-google-maps/core'; ?

david-mart avatar Oct 17 '16 05:10 david-mart

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 avatar Oct 17 '16 05:10 david-mart

@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.

jonathan-chin avatar Oct 17 '16 05:10 jonathan-chin

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"

sadeajayi avatar Aug 29 '17 03:08 sadeajayi

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.

stale[bot] avatar Nov 13 '18 23:11 stale[bot]