Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
OpenLayers I am not able to drag the custom features

Following the query here:

Openlayers can't modify drawn features

I have built some code, which allowes me to edit nodes of my drawn features:

 var modifyInteraction = new ol.interaction.Modify({
 features: selectInteraction.getFeatures(),
 deleteCondition: function(event) {
 return ol.events.condition.shiftKeyOnly(event) &&
    ol.events.condition.singleClick(event);
 }
});
map.addInteraction(modifyInteraction);

However I have lost the option for dragging my features, which is defined by this code:

 var translateInteraction = new ol.interaction.Translate({
features: selectInteraction.getFeatures(),
});
map.addInteraction(translateInteraction);

The new ol.interaction.Translate({ has been switched off, otherwise I am not able to edit my features, but I can only drag them.

Is there any chance to make my features draggable when I can edit them like defined in the code new ol.interaction.Modify({ above?

My full JSfiddle is here:

https://jsfiddle.net/g196cqoa/

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can add a condition option to the translate interaction to only interact when ctrl key is pressed.

var modifyInteraction = new ol.interaction.Modify({
  features: selectInteraction.getFeatures(),
  deleteCondition: function(event) {
    return ol.events.condition.shiftKeyOnly(event) &&
      ol.events.condition.singleClick(event);
  },
});
map.addInteraction(modifyInteraction);

const translate = new ol.interaction.Translate({
  features: selectInteraction.getFeatures(),
  condition: function (event) {
    return ol.events.condition.platformModifierKeyOnly(event) &&
      ol.events.condition.primaryAction(event);
  },
});
map.addInteraction(translate);

Alternatively, if you add the translate interaction before the modify interaction it should allow you to drag polygons as long as you stay away from the edges. This won't work with lines and points. as there is no area where the geometry cannot be modified.

The order in which the interactions are added to the maps interaction collection determines whether the modify interaction is allowed see and handle the events before the translate interaction handles them

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!