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 user1865154user1865154
Add a ment  | 

1 Answer 1

Reset to default 7

This 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