[OpenLayers-Users] How to implement draggable Markers?

Joao Duarte joao.c.duarte at co.sapo.pt
Thu Jan 8 05:03:05 EST 2009


Hi,

Another option would be to have your markers rendered in a Vector layer
(each marker would be a Feature).
Example:

************Create the layer and add it to the map***************
markersLayer = new OpenLayers.Layer.Vector("Markers", 
	{
		projection: new OpenLayers.Projection("EPSG:4326"),
		styleMap: new OpenLayers.StyleMap({
			externalGraphic:
"http://openlayers.org/dev/img/marker-gold.png",
			backgroundGraphic:
"http://openlayers.org/dev/examples/marker_shadow.png",
			graphicYOffset: -20,
			backgroundXOffset: 0,
			backgroundYOffset: -17,
			pointRadius: 10
		})
	}
);
map.addLayer(markersLayer);

************Add some features(markers)*******************
var feature1 = new OpenLayers.Feature.Vector(new
OpenLayers.Geometry.Point(-9.39));
var feature2 = new OpenLayers.Feature.Vector(new
OpenLayers.Geometry.Point(-8,42));
markersLayer.addFeatures([feature1, feature2]);

With this option you could then just add the DragFeature control to the map,
and your markers (features) will become draggable.

Best regards,

João Duarte

-----Original Message-----
From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] On
Behalf Of Alan Boudreault
Sent: quarta-feira, 7 de Janeiro de 2009 16:55
To: KartoPete
Cc: users at openlayers.org
Subject: Re: [OpenLayers-Users] How to implement draggable Markers?

KartoPete wrote:
>
> Alan Boudreault wrote:
>   
>> KartoPete wrote:
>>     
>>> Hi guys, 
>>> I#m working with OpenLayers2.6 and try make my markers draggable. I
tried
>>> a
>>> few edited classes I found here but it wouldn't work out, even the
posted
>>> example(long time ago) wouldn't work on my machine. Does anyone know if
>>> draggable markers is already working with the new or future versions? Or
>>> has
>>> someone a idea on how to implement this? 
>>> thx Pete
>>>   
>>>       
>> Something that you can do is to create a new class "DraggableMarker"
>> that inherit of OpenLayers.Marker. This class will mainly handle 2
>> events: mouseup and mousedown:
>>
>>  this.events.register('mousedown', this, this._markerDown);
>>  this.events.registerPriority('mouseup', this, this._markerUp);
>>
>> Thanks, I'll try
>> But why registerPriority()?
>>
>> After that, the mousedown function will activate the event "mousemove"
>> and the mouseup will disable it. And the mousemove handle will calculate
>> the new position and move the marker on the fly.
>>
>> Hope this help.
>> Alan
>>
>>
>> -- 
>> Alan Boudreault
>> Mapgears
>> http://www.mapgears.com
>>
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
>>
>>     
>
>   
You can try without the "priority" ..... i don't remember why we used
this. Maybe a problem with an old version.

-- 
Alan Boudreault
Mapgears
http://www.mapgears.com

_______________________________________________
Users mailing list
Users at openlayers.org
http://openlayers.org/mailman/listinfo/users




More information about the Users mailing list