+ function startMarker() {
+ $("add_marker").innerHTML='Click on the map to add a marker';
+ if (!markerLayer) {
+ markerLayer = new OpenLayers.Layer.Vector("",{displayInLayerSwitcher: false});
+ markerControl = new OpenLayers.Control.DrawFeature(markerLayer, OpenLayers.Handler.Point);
+ map.addLayer(markerLayer);
+ map.addControl(markerControl);
+ markerLayer.events.on({"featureadded": endMarker});
+ }
+ markerLayer.destroyFeatures();
+ markerControl.activate();
+ return false;
+ }
+
+ $("add_marker").onclick = startMarker;
+
+ function endMarker(event) {
+
+ markerControl.deactivate();
+ $("add_marker").innerHTML='Change marker position';
+ $("marker_inputs").style.display="block";
+
+ var epsg4326 = new OpenLayers.Projection("EPSG:4326");
+ var epsg900913 = new OpenLayers.Projection("EPSG:900913");
+ var geom = event.feature.geometry.clone().transform( epsg900913, epsg4326 );
+ $("marker_lon").value = geom.x.toFixed(5);
+ $("marker_lat").value = geom.y.toFixed(5);
+ htmlUrlChanged();
+ }
+
+ function clearMarker() {
+ $("marker_lon").value = "";
+ $("marker_lat").value = "";
+ $("marker_inputs").style.display = "none";
+ $("add_marker").innerHTML='Add a marker to the map';
+ if (markerLayer) {
+ markerControl.destroy();
+ markerLayer.destroy();
+ markerLayer = null;
+ markerControl = null;
+ }
+ }
+