我需要当地图接近/离开时,不要擦除标记。
我的脚本是这样的:
JS
$(document).ready(function() {
//init
var map;
var posMarcador; // Posicion del marcador
var options = {
restrictedExtent: extent,
controls: [
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.Attribution()
]
};
var position = new OpenLayers.LonLat(lon, lat).transform( fromProjection, toProjection);
map = new OpenLayers.Map( 'map', options);
layerBase = new OpenLayers.Layer.OSM();
map.addLayer(layerBase);
map.setCenter(extent.getCenterLonLat(), zoom);
map.isValidZoomLevel = function(zoomLevel) {
return ( (zoomLevel != null) &&
(zoomLevel >= 11) && // set min level here, could read from property
(zoomLevel < 17) );
}
var iconImage = //url image
/**
* Marcador
* @type {OpenLayers.Layer.Markers}
*/
var layerMarkers = new OpenLayers.Layer.Markers( "Markers" );
map.addLayer(layerMarkers);
map.events.register("click", map, function(e) {
layerMarkers.clearMarkers();
var position = map.getLonLatFromViewPortPx(e.xy);
posMarcador = new OpenLayers.LonLat(position.lon, position.lat);
var size = new OpenLayers.Size(50,50);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon = new OpenLayers.Icon(iconImage(tipoIcono), size, offset);
layerMarkers.addMarker(new OpenLayers.Marker(posMarcador, icon));
posMarcador = posMarcador.transform(toProjection , fromProjection );
$('input[name="geopunto.latitud"]').val(posMarcador.lat);
$('input[name="geopunto.longitud"]').val(posMarcador.lon);
});
});
我的观点是:
<div id="map"></div>
当我放置一个静态点(取消注册点击事件)时,它可以正常工作。我希望你能帮忙。