[OpenLayers-Users] How to achieve DragFeature with Snapping?

Michael Weibel michael.weibel at gmail.com
Tue Aug 30 08:06:51 EDT 2011


Hi all,

I'm new to this list & new to openlayers. :)

I'm currently trying to implement something like a marker reordering. 
I have a route with e.g. 4 markers on it (drawn using OpenLayers.Feature.Vector) and I want to reorder the markers in order to change the way the route goes. 

So far I've been able to attach a DragFeature to the layer and I can drag&drop those markers. But I want now to use the OpenLayers.Control.Snapping-Feature (or something like that) to snap the marker I'm currently dragging to another marker. 

Does anyone know how I could achieve that?

Here some code snippets:
------------------------------------------------------------------------------------------------------------------------
	markerLayer = new OpenLayers.Layer.Vector("Markers");
	map.addLayer(markerLayer);

	_drag = new OpenLayers.Control.DragFeature(markerLayer, {
		onStart: self.onStart, 
		onComplete: self.onComplete,
	});
	_map.addControl(_drag);
	_drag.activate();
------------------------------------------------------------------------------------------------------------------------
Adding a marker like this:
	feature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.Point(point.lon, point.lat), {'icon': icon}, {
		externalGraphic: "number_" + num + ".png",
		graphicWidth: 32,
		graphicHeight: 37,
		graphicXOffset: -16,
		graphicYOffset: -35
	});


Thanks for answering. 

Cheers,
Michael


More information about the Users mailing list