当被绘制的多边形选中时,我想更改标记图标。在 addMarker() 中,标记从 JSON 数据中解析并推送到 allMarkers 数组中。图标未选中时为红色,选中时变为白色。
function addMarker(lat,lng,i){
var myLatlng = new google.maps.LatLng(lat,lng);
var marker = new google.maps.Marker({
position: myLatlng,
icon: "http://labs.google.com/ridefinder/images/mm_20_red.png",
map: map
});
marker.shapeId = '0';
allMarkers.push(marker);
}
function selectMarkersInPoly() {
alert(allMarkers.length)
for (var i=0; i < createdShapes.length; i++) {
for (var j=0; j < allMarkers.length; j++){
var latlong = allMarkers[j].getPosition();
if(google.maps.geometry.poly.containsLocation(latlong, createdShapes[i]) == true) {
allMarkers[j].shapeId = createdShapes[i].id;
allMarkers[j].setOptions({
icon : "http://labs.google.com/ridefinder/images/mm_20_white.png"
});
}
}
}
}
selectMarkersInPoly() 有什么问题???谢谢您的帮助?