I have a version of mxn.microsoft.core.js that will utilize the icon, shadow
icon, and hover icon when creating Microsoft custom icons. My only hesitation on
checking it in is that I needed an identifier for the custom marker to implement
the hover effect. The example code on the Mapstraction site used a property
named "marker" as shown below:
function advancedMarker() {
mapstraction.addMarkerWithData(new mxn.Marker( new
mxn.LatLonPoint(47.4004,153.1435)),{
infoBubble : "Advanced Marker",
label : "tooltip",
date : "new Date()",
marker : 4,
iconShadow:
"http://mapufacture.com/images/providers/blank.png",
iconShadowSize : [0,0],
icon :
"http://assets1.mapufacture.com/images/markers/usgs_marker.png",
iconSize : [20,20],
draggable : false,
hover : true
}
I did not see "marker" in mxn.core.js, but I used it anyway. Is this
the desired way to pass in an identifier for a marker? If so, here is my code
for mxn.microsoft.core.js. It works fine, producing a custom icon with offsets,
shadow with offsets, and has the hover effect, but I wanted to hear some
feedback whether this approach was acceptable:
addMarker: function(marker, old) {
var map = this.maps[this.api];
var pin = marker.toProprietary(this.api);
map.AddShape(pin);
marker.pinID = pin.GetID();
if(marker.hoverIconUrl){
map.AttachEvent("onmouseover", function(e) {
var map = this.maps[this.api];
if(e.elementID){
var shape = map.GetShapeByID(e.elementID);
var marker = shape.mapstraction_marker;
var element = document.getElementById(marker.marker);
if (element) {
element.src = marker.hoverIconUrl
}
}
}.bind(this));
map.AttachEvent("onmouseout", function(e) {
var shape = map.GetShapeByID(e.elementID);
var marker = shape.mapstraction_marker;
var element = document.getElementById(marker.marker);
if (element) {
element.src = marker.iconUrl
}
}.bind(this));
}
//give onclick event
//give on double click event
//give on close window
//return the marker
return pin;
},
...
Marker: {
toProprietary: function() {
var mmarker = new VEShape(VEShapeType.Pushpin,
this.location.toProprietary(''microsoft''));
mmarker.SetTitle(this.infoBubble);
var customIcon = new VECustomIconSpecification();
var markerOffsetx = 0;
var markerOffsety = 0;
var shadowOffsetx = 0;
var shadowOffsety = 0;
if (this.iconAnchor) {
markerOffsetx = -this.iconAnchor[0];
markerOffsety = -this.iconAnchor[1];
} else if (this.iconSize){
markerOffsetx = -this.iconSize[0]/2;
markerOffsety = -this.iconSize[1]/2;
}
if (this.iconShadowUrl) {
if (this.iconAnchor) {
shadowOffsetx = -this.iconAnchor[0];
shadowOffsety = -this.iconAnchor[1];
} else if (this.iconShadowSize){
shadowOffsetx = -this.iconShadowSize[0]/2;
shadowOffsety = -this.iconShadowSize[1]/2;
}
}
var customHTML = [];
customHTML.push("<div
style=''position:relative''>");
if (this.iconShadowUrl) {
customHTML.push(" <div
style=''position:absolute;left:" + shadowOffsetx +
"px;top:" + shadowOffsety + "px;''>");
customHTML.push("<img src=''");
customHTML.push(this.iconShadowUrl);
customHTML.push("'' border=''0''
/>");
customHTML.push("</div>");
}
customHTML.push(" <div
style=''position:absolute;left:" + markerOffsetx +
"px;top:" + markerOffsety + "px;''>");
customHTML.push("<img src=''");
customHTML.push(this.iconUrl);
customHTML.push("'' id=''");
customHTML.push(this.marker);
customHTML.push("'' ");
customHTML.push(" border=''0'' />");
customHTML.push("</div>");
customHTML.push("</div>");
customIcon.CustomHTML = customHTML.join("");
mmarker.SetCustomIcon(customIcon);
return mmarker;
},
________________________________
This e-mail and any attachments may contain confidential material for the sole
use of the intended recipient. If you are not the intended recipient, please be
aware that any disclosure, copying, distribution or use of this e-mail or any
attachment is prohibited. If you have received this e-mail in error, please
contact the sender and delete all copies.
Thank you for your cooperation.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.mapstraction.com/pipermail/mapstraction-mapstraction.com/attachments/20100831/c9f3c7c4/attachment-0001.htm>