Mapstraction: changing the url of an icon image after adding it?
I am trying to use marker.setIcon()
to change the image of the markers. However, it seems that while this changes the attribute marker.iconUrl
, the icon itself uses the marker.proprietary_marker.$.icon.image
markers to display the image, so the markers icon remains unchanged. Is there a way to change dynamically marker.proprietary_marker.$.icon.image
?
- Add marker.
- Check the url of the icon image and its icon - they are the same.
- Change the icon.
- Check the URL again. The Url icon has changed now, but the marker still shows the old image, which is in its own marker object.
<head>
<title>Map Test</title>
<script src="http://maps.google.com/maps?file=api&v=2&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>
a source to share
In my opinion, from what I've read, after creating 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've read, I don't believe it can be changed via the icon options after the marker is created.
I also believe I read that if you change the icon's image, it will maintain the same sizing properties that you originally set in the icon preferences for the marker options. IE, if the first image was set to 15x15 and the second one was 5x5, the 5x5 will be resized to 15x15.
a source to share