Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda