views:

150

answers:

1

I am trying to use marker.setIcon() to change a markers image. However it appears that although this changes the marker.iconUrl attribute the icon itself is using marker.proprietary_marker.$.icon.image to display the markers image - so the markers icon remains unchanged. Is there a way to dynamically change the marker.proprietary_marker.$.icon.image?

  1. Add a marker.
  2. Check the icon's image url and the proprietary icon's image - they're the same.
  3. Change the icon.
  4. Again check the Urls. Now the Icon Url has changed but the marker still shows the old image which is in the proprietary marker object.

 <head>
<title>Map Test</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=Your-Google-API-Key" type="text/javascript"></script>
<script src="mapstraction.js"></script>

<script type="text/javascript">
var map;
var marker;

function getMap(){
        map = new mxn.Mapstraction('myMap','google');
    map.setCenterAndZoom(new mxn.LatLonPoint(45.559242,-122.636467), 15);
}


function addMarker(){
        marker = new mxn.Marker(new mxn.LatLonPoint(45.559242, -122.636467));
    marker.addData({infoBubble : "Text", label : "Label",  marker : 4, icon: "http://mapscripting.com/examples/mashups/richter-high.png"});
    map.addMarker(marker);
}

function changeIcon(){
    marker.setIcon("http://assets1.mapufacture.com/images/markers/usgs_marker.png");
}


function showIconURL(){
        alert(marker.iconUrl);
} 


function showProprietaryIconURL(){
    alert(marker.proprietary_marker.$.icon.image);
}

</script>
</head>
<body onload="getMap()">
<div id="myMap" style="width:627px; height:412px;"></div>
<div>
    <input type="button" value="add marker" OnClick="addMarker();">
    <input type="button" value="change icon" OnClick="changeIcon();">
    <input type="button" value="show icon URL" OnClick="showIconURL();">
    <input type="button" value="show proprierty icon URL " OnClick="showProprietaryIconURL();">
</div>
</body>
</html>
+1  A: 

It was to my understanding from what I have read that once you create a marker you can no longer change the "icon" of the marker. You can change the image property of the marker itself but from what I have read I don't believe that it is possible to change it through the icon options once the marker has been generated.

I also believe I read that if you do change the image of the icon it will maintain the same size properties that you originally set in your icon settings for the marker options. IE if the first image was set to a 15x15 and the second is a 5x5 the 5x5 will be resized to the 15x15.

Nathan Raley