Mario Danelli: Thanks for your attention and the codes.
It seem that the `OpenLayers.Marker` have no native support methods like `setPosition()` or something else to update its position. Since in my opinion, destroy-create-destroy.. will be a performance consuming problem, that is why I keep one object of `Marker` to reuse it. I think it is a pity. APIs like this kinds should be considered. And I hope the development team of OL will notice this post. :) And thank you anyway. :) 2013/5/31 Mario Danelli <[email protected]> > Dear Maven, > > > As you can see, once I click on the map, I want the marker's position > updated and re-located. > > As you can see, from the following link too > > > http://stackoverflow.com/questions/9278174/how-to-move-a-marker-in-an-openlayers-layer-markers-layer > > It seems that the "moveTo" -- is not "official" APIMethod -- or in any case > there are some problems with it. > > So I tried removing and adding a new marker at any click on map. > Below the JS code, that runs as expected, I tried in your example. > As you can see I changed the code of "updateMaker" function. > > ---------> BEGIN > > $(window).load(function() { > var map = new OpenLayers.Map("map"); > map.addControl(new OpenLayers.Control.MousePosition()); > var osm = new OpenLayers.Layer.OSM(); > map.addLayer(osm); > // Set view to zoom maximum map extent > map.zoomToMaxExtent(); > > var markers = new OpenLayers.Layer.Markers("Markers"); > map.addLayer(markers); > > myMarker = new OpenLayers.Marker(new OpenLayers.LonLat(0,0)); > markers.addMarker(myMarker); > > map.events.register("click", map, function(evt) { > var pos = map.getLonLatFromPixel(evt.xy); > updateMaker(myMarker, pos); > }); > > function updateMaker(myMarkerIn, pos) { > > //myMarker.moveTo(myMarker.map.getPixelFromLonLat(pos)); > markers.removeMarker(myMarkerIn); > myMarkerIn.destroy(); > myMarker = new OpenLayers.Marker(pos); > markers.addMarker(myMarker); > } > }); > > <--------- END > > I hope it can be useful. > > Regards > > Mario Danelli > > _______________________________________________ > Users mailing list > [email protected] > http://lists.osgeo.org/mailman/listinfo/openlayers-users >
_______________________________________________ Users mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/openlayers-users
