अंततः यह काम कर रहा है। agm-map
का एक बाल घटक बनाना था और लोड पर एक आउटपुट बनाना था, मूल Google मानचित्र एपीआई रैपर पकड़ता है और मेरे मूल मानचित्र घटक में गुजरता है। काश वे इसे बनाते हैं ताकि आप नियमित agm-map
घटक में gmaps एपीआई रैपर को पकड़ सकें। पैनटो के साथ भी काम करता है।
PARENT घटक मार्कअप
<agm-map [latitude]='lat' [longitude]='lng'
[usePanning]='true'>
<agm-marker *ngFor='let location of locations'
[latitude]='location.latitude'
[longitude]='location.longitude'
[iconUrl]='location.icon'
(markerClick)='markerClicked(location)'></agm-marker>
<core-map-content (onMapLoad)='loadAPIWrapper($event)'></core-map-content>
</agm-map>
PARENT घटक
/**
* Map Component
* API Docs: https://angular-maps.com/docs/api/latest/ts/
*/
import { GoogleMapsAPIWrapper } from '@agm/core';
import { Component, Input } from '@angular/core';
declare var google:any;
@Component({
selector: 'core-map',
styleUrls: [ './map.component.scss' ],
templateUrl: './map.component.html',
})
export class MapComponent {
@Input() lat: number;
@Input() lng: number;
@Input() locations: {};
map: any;
constructor(
public gMaps: GoogleMapsAPIWrapper,
) {}
public loadAPIWrapper(map) {
this.map = map;
}
public markerClicked = (markerObj) => {
const position = new google.maps.LatLng(markerObj.latitude, markerObj.longitude);
this.map.panTo(position);
}
}
बाल घटक
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { GoogleMapsAPIWrapper } from '@agm/core';
@Component({
selector: 'core-map-content',
template: '',
})
export class MapContentComponent implements OnInit {
@Output() onMapLoad: EventEmitter<{}> = new EventEmitter<{}>();
constructor(public gMaps: GoogleMapsAPIWrapper) {}
ngOnInit() {
this.gMaps.getNativeMap().then((map) => {
this.onMapLoad.emit(map);
});
}
}
स्रोत
2017-06-02 16:03:47
आप कुछ प्रदान करें सकते हैं प्रश्न के साथ अधिक जानकारी? –