More

Popup overlays on draw (measure) with OpenLayers 3?

Popup overlays on draw (measure) with OpenLayers 3?


Using the OpenLayers Measure exemple (http://openlayers.org/en/v3.10.1/examples/measure.html), I'm trying to have only a single measure active at a time.

http://jsfiddle.net/Sinnel/yfdejpre/1/

However, the static measure results appear in a overlay and I have not been able to limit/delete old measures from staying on the map. I have tried different approaches for quite some time, the one giving the "best" results being :

if (map.getOverlays().getArray().length >= 2) { map.getOverlays().clear()};

However, the result is quite inconsistent… How should I approach this?


  1. source_mesure.clear(); should be fired on drawstart and not on drawend.
  2. I have used $( ".tooltip" ).remove(); in order to clear the tooltips. Maybe you should find something more elgant for that.
  3. You had a firebug error (draw is undifined). That was because you asign the listener before initialising the interaction. So I put the listener asignments imediate after initialising the interaction.

check this fiddle. click Its your fiddle with slight mods to do your job.


Watch the video: GIS with #Openlayers part3. Add Point #GeoJSON with #PopupTemplate