I was investigating the adding of markers on the map through Javascript, and found a topic on the forums that offered code to do it:
var markerUrl = "Images/marker_blue.gif";
var markerWidth = 21;
var markerHeight = 25;
var markerOffsetX = -10.5;
var markerOffsetY = -25;
var OnMapCreating = function (map) {
OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer.Vector, {
onFeatureInsert: function (feature) {
var markerLayer = map.getLayer('SomeMarkers');
var size = new OpenLayers.Size(markerWidth, markerHeight);
var offset = new OpenLayers.Pixel(markerOffsetX, markerOffsetY);
var icon = new OpenLayers.Icon(markerUrl, size, offset);
var marker = new OpenLayers.Marker(feature.geometry.bounds.getCenterLonLat(), icon.clone());
marker.id = new Date().toTimeString();
//markerLayer.addMarker(marker);
}
})
};
This is used in combo with "Map1.SetDrawMode('Point')". Now, this works...almost.
I was getting a syntax error, which I finally tracked down to the "AddMarkersByAjax" method, in helper_geoResource.axd. The first line of that method reads:
var markerOverlays = eval('(' + json + ')');
Assuming this was trying to parse the JSON object that holds the list of overlays, I corrected this to the follow:
var markerOverlays = eval('[' + json + ']');
This solved the syntax error, and clicking on the map now adds my image as a marker, as expected. Could this be fixed in the daily build? I have an overwritten version of that method in my code right now, but obviously I'd prefer to remove it.