admin管理员组文章数量:1300133
I want to change a marker icon when selected by a drawed polygon. In addMarker() the markers are parsed from JSON data and push into allMarkers array. The icon is red when not selected and would bee white when selected.
function addMarker(lat,lng,i){
var myLatlng = new google.maps.LatLng(lat,lng);
var marker = new google.maps.Marker({
position: myLatlng,
icon: ".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 : ".png"
});
}
}
}
}
What is wrong with selectMarkersInPoly() ??? Thank you for your help?
I want to change a marker icon when selected by a drawed polygon. In addMarker() the markers are parsed from JSON data and push into allMarkers array. The icon is red when not selected and would bee white when selected.
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./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./ridefinder/images/mm_20_white.png"
});
}
}
}
}
What is wrong with selectMarkersInPoly() ??? Thank you for your help?
Share Improve this question edited Dec 17, 2012 at 15:43 asked Dec 17, 2012 at 14:49 user1865154user18651541 Answer
Reset to default 7This is not the correct syntax for a javascript anonymous object:
allMarkers[j].setOptions({
icon = "http://labs.google./ridefinder/images/mm_20_white.png"
});
(I would think you would get javascript errors in the javascript console) This should work:
allMarkers[j].setOptions({
icon: "http://labs.google./ridefinder/images/mm_20_white.png"
});
本文标签: javascriptGoogle Maps Api Marker setOptions() change iconStack Overflow
版权声明:本文标题:javascript - Google Maps Api Marker setOptions() change icon - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741657923a2390866.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论