Skip to main content
deleted 30 characters in body
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

I add a ol.layer.Vector OR ol.layer.Group with a mouse click in the map. By a new mouse click should the layer removed/deleted AND a new layer should be add. etc.

I have search and search and don't found a simple methode. There is all complicated or don't work, or with Ajax or JQuery (i don't use it).

Then i use this and that is the best solution:

if (map.getLayers().array_.length > 1) {
map.getLayers().array_.pop();
}

Hey! Silent! That works absolutelly perfect and is absolutelly simple!. OpenLayers does not seem to have such a simple solution. Simple! Now you!

I add a ol.layer.Vector OR ol.layer.Group with a mouse click in the map. By a new mouse click should the layer removed/deleted AND a new layer should be add. etc.

I have search and search and don't found a simple methode. There is all complicated or don't work, or with Ajax or JQuery (i don't use it).

Then i use this and that is the best solution:

if (map.getLayers().array_.length > 1) {
map.getLayers().array_.pop();
}

Hey! Silent! That works absolutelly perfect and is absolutelly simple! OpenLayers does not seem to have such a simple solution. Simple! Now you!

I add a ol.layer.Vector OR ol.layer.Group with a mouse click in the map. By a new mouse click should the layer removed/deleted AND a new layer should be add. etc.

I have search and search and don't found a simple methode. There is all complicated or don't work, or with Ajax or JQuery (i don't use it).

Then i use this and that is the best solution:

if (map.getLayers().array_.length > 1) {
map.getLayers().array_.pop();
}

That works absolutelly perfect and is absolutelly simple. OpenLayers does not seem to have such a simple solution.

Source Link
Suka
  • 81
  • 1
  • 11

Remove/Delete a layer or layergroup with mouse click

I add a ol.layer.Vector OR ol.layer.Group with a mouse click in the map. By a new mouse click should the layer removed/deleted AND a new layer should be add. etc.

I have search and search and don't found a simple methode. There is all complicated or don't work, or with Ajax or JQuery (i don't use it).

Then i use this and that is the best solution:

if (map.getLayers().array_.length > 1) {
map.getLayers().array_.pop();
}

Hey! Silent! That works absolutelly perfect and is absolutelly simple! OpenLayers does not seem to have such a simple solution. Simple! Now you!