The dragging the features on opelayers map is not very straightforward for newbies because it assumes to be familiar with the concept of interactions and there’s no good sample to start the dragging.

In fact the have a related sample translate-features but it enforces a feature to be clicked before it can be moved and it does not shows the way to be notified about the changing end.

Moreover – in the most tutorials and advices there are “modify” interaction mentioned while it is intended to modify the elements of the feature rather than move the feature as a whole. Particularly “modify” will show a circle in the some point of the feature instead of the changing the cursor hovering over the feature.

So. The first task is to start dragging. Or, in the terms of Openlayer – “to add translate interaction to the map against some fetures”.

Let’s observe the hovering over a map:

And, if the hovering happens to be over a feature add the interaction, remove the interaction otherwise.

Where the adding includes the steps:

  1. create ol InteractionTranslate instance
  2. add it to the map
  3. add “translateend” event listener to the interaction

and the removing is as easy as

And here we are.


Leave a Reply

Your email address will not be published. Required fields are marked *