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

335
Vistas
Openlayers - lines and points cannot be deleted by double click

I am working on the delete option by double click in OpenLayers. I use the following code:

 map.on('dblclick', function(evt) {
  var selectCollection = selectInteraction.getFeatures();
  if(selectCollection.getLength() > 0){
   var answer = window.confirm("Do you want to delete?")
   if (answer) {
   vectorLayer.getSource().removeFeature(selectCollection.item(0));
    }
  }
 }); 

based on these examples:

https://gis.stackexchange.com/questions/126581/openlayers-3-capturing-various-click-events

How to create a dialog with “yes” and “no” options

everything would be perfect, but I cannot delete the linestrings and points at some point.

As you can see below, all the shapes which have the "filled surface" can be deleted easily after the selection.

enter image description here

I am getting the

**Vector.js:906

Uncaught TypeError: Cannot read properties of undefined (reading 'forEach')**

instead.

I don't know how to fix it frankly. By reading this hint:

Cannot read property 'forEach' of undefined

I think, that I should use the push method, although I see no option for distinguishing my selectInteraction between the separate geometry.

My full JSFiddle is here:

https://jsfiddle.net/skwbdx0j/

Is there any option to fix it?

UPDATE:

Placing a certain variable inside the getSource didn't resolve this issue.

 map.on('dblclick', function(evt) {
 var selectCollection = selectInteraction.getFeatures();
 if(selectCollection.getLength() > 0){
 var answer = window.confirm("Do you want to delete?")
  if (answer) {
  
  vectorLayer.getSource(lineInteraction).  // the same line
   removeFeature(selectCollection.item(0));           }
      }       
   });
about 4 years ago · Juan Pablo Isaza
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