谷歌地图Javascript上的更改标记
我在angular 2中添加了JavaScript的GoogleMapsAPI。 根据从API获取的位置在地图上添加自定义标记。 我已经在UI上显示了职位列表。单击位置后,我想替换该位置对应的标记图标并重置所有其他图标。 以下代码未按预期工作 我添加了此功能以在地图上放置标记:谷歌地图Javascript上的更改标记,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我在angular 2中添加了JavaScript的GoogleMapsAPI。 根据从API获取的位置在地图上添加自定义标记。 我已经在UI上显示了职位列表。单击位置后,我想替换该位置对应的标记图标并重置所有其他图标。 以下代码未按预期工作 我添加了此功能以在地图上放置标记: placeMarkers(markers: any, infoWindowContent: any) { // Display multiple markers on a map let infoWind
placeMarkers(markers: any, infoWindowContent: any) {
// Display multiple markers on a map
let infoWindow = new google.maps.InfoWindow();
let bounds = new google.maps.LatLngBounds();
let marker;
// Loop through our array of markers & place each one on the map
for(let i = 0; i < markers.length; i++ ) {
let position = new google.maps.LatLng(<number>markers[i].lat, <number>markers[i].lang);
bounds.extend(position);
marker = new google.maps.Marker(<google.maps.MarkerOptions>{
position,
map: this.map,
title: markers[i].name,
icon: this.iconUrl,
});
// Allow each marker to have an info window
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infoWindow.setContent(infoWindowContent[i]);
infoWindow.open(this.map, marker);
}
})(marker, i));
// Automatically center the map fitting all markers on the screen
this.map.fitBounds(bounds);
}
}
placeMarkers(markers:any,infoWindowContent:any){
//在地图上显示多个标记
让infoWindow=new google.maps.infoWindow();
让bounds=new google.maps.LatLngBounds();
让标记;
//在我们的标记阵列中循环并将每个标记放置在地图上
for(设i=0;i
此代码用于替换所选位置的标记:
selectSite(site: any, index: any) {
this.placeMarkers(this.finalMarkers, this.finalInfoWindowContent);
let selection = this.finalMarkers.find(function(item) {
return item.name == site.Name
});
let infowindow = new google.maps.InfoWindow();
let position = new google.maps.LatLng(<number>selection.lat, <number>selection.lang);
let redMarker = new google.maps.Marker(<google.maps.MarkerOptions>{
position: position,
map: this.map,
title: selection.name,
icon: {url: require('../../../assets/img/red-marker.png'), scaledSize: {height: 30, width: 20}}
});
redMarker.addListener('click', function() {
infowindow.setContent(selection.name);
infowindow.open(this.map, redMarker);
});
}
选择站点(站点:任意,索引:任意){
this.placeMarkers(this.finalMarkers,this.finalInfoWindowContent);
让selection=this.finalMarkers.find(函数(项){
return item.name==site.name
});
让infowindow=new google.maps.infowindow();
让position=new google.maps.LatLng(selection.lat,selection.lang);
让redMarker=new google.maps.Marker({
职位:职位,,
map:this.map,
标题:selection.name,
图标:{url:require('../../../assets/img/red marker.png'),缩放大小:{height:30,width:20}}
});
redMarker.addListener('单击',函数()){
infowindow.setContent(selection.name);
infowindow.open(this.map,redMarker);
});
}
上面的代码最初运行良好,但在多次位置更改后被卡住。
非常感谢您的帮助 我就是这样做的
**You can Set Following marker**
var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/';
var icons = {
parking: {
icon: iconBase + 'parking_lot_maps.png'
},
library: {
icon: iconBase + 'library_maps.png'
},
info: {
icon: iconBase + 'info-i_maps.png'
}
};
我只是在谷歌地图之外做的,效果很好
我就是这样做的
我只是在谷歌地图之外做的,效果很好
选择一个站点后,我想重置所有其他站点,仅更改所选站点。选择一个站点后,我想重置所有其他站点,仅更改所选站点。