[OpenLayers-Users] How to implement draggable Markers?

Tim Schaub tschaub at opengeo.org
Fri Jan 9 13:51:02 EST 2009


Or, consider resurrecting Chris' DragMarker control:

http://trac.openlayers.org/browser/sandbox/tschaub/feature/lib/OpenLayers/Control/DragMarker.js

Can't remember why that didn't work.  Chris probably already replied and 
I missed it.

Tim

PS - I think we should start discussing an easier way to make things 
draggable.  There are certainly plenty of good solutions in other 
frameworks.  Dragging is a pretty primary operation in map related apps. 
  Would be good to have an elegant solution that was reusable for 
various elements.

Alan Boudreault wrote:
> I think that's why the "mouseup" event was register with Priority......
> it's this event that stop the mousemove one.  Just add a boolean member
> "DragEnabled" and the mousemove event will do it's work only if the this
> variable is set.
> 
> Alan
> 
> KartoPete wrote:
>> good idea, 
>> I tried first version and can't stop the mousemove event. Any ideas? If it
>> would be my own code I would do it different, but I#m stuck in many code
>> from another author, who worked on the project before. My actuell
>> DraggableMarkerClass looks like this:
>> OpenLayers.Marker.DraggableMarker = OpenLayers.Class(OpenLayers.Marker, {
>> 	
>> 	layer: null,
>> 	currentEvent: null,
>> 	
>> 	registerEvents: function(){
>> 		this.events.registerPriority('mousedown', this, this.onMarkerDown);
>> 		this.map.events.register('mouseup', this, this.onMarkerUp);
>> 	},
>> 	
>> 	onMarkerDown: function(){
>> 		this.map.events.register('mousemove', this, this.onMove);
>> 	},
>> 	onMarkerUp: function(){
>> 		
>> 		Event.stop(this.currentEvent);
>> 		
>> 	},
>> 	onMove: function(e){
>> 		 	var lonlat = this.map.getLonLatFromViewPortPx(e.xy);
>> 		 	var marker = new OpenLayers.Marker.DraggableMarker(new
>> OpenLayers.LonLat(lonlat.lon,lonlat.lat), markerIcon2.clone());
>> 		 	this.layer.clearMarkers();
>> 		 	this.layer.addMarker(marker);
>> 		 	this.currentEvent = e;
>> 	},
>> 	
>> 	
>>     CLASS_NAME: "OpenLayers.Marker.DraggableMarker"
>> });
>>
>> As I already said, I can't stop the mousemove-Event!
>> Any ideas?
>> thx,
>> Pete
>>   
> 
> 


-- 
Tim Schaub
OpenGeo - http://opengeo.org
Expert service straight from the developers.



More information about the Users mailing list