Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda