[OpenLayers-Users] How to completely erase a map?
Eric Lemoine
eric.lemoine at camptocamp.com
Sat May 5 03:12:48 EDT 2012
On Saturday, May 5, 2012, alexe100 wrote:
> Hi
>
> I have a map which embedds :
>
> var layer = new OpenLayers.Layer.OSM(...
> var vectorLayer = new OpenLayers.Layer.Vector(...
> var renderer =
> OpenLayers.Util.getParameters(window.location.href).renderer;
> and
> var selectControl = new OpenLayers.Control.SelectFeature(...
>
> It shows very well including vectors and tooltips.
>
> On the html page i have a check box called Automatic Refresh. If i check
> this control a timer is set with a period of 5 secods.
> For each 5 seconds the page requests new (current) GPS positions from the
> servlet for the vehicles.
> When those positions arrive I clear the structure vector and store the new
> positions and then I need to update the positions on the map. To simplify
> the operation I do this:
>
> for (var i = map.layers.length - 1; i >= 0; i--)
> {
> map.removeLayer(map.layers[i]);
> }
>
> and then I call Init() again to create the (new) map
>
>
> but the map does not show very well. It seems that part of the old map
> remains on the bottom of the screen/div and the new map is drawn above it.
>
> Is this the right way to do the map update?
Use map.destroy() to destroy a map entirely.
>
> Can I simple update only the layer on the vehicles positions icons? if so,
> what about the already stablished SelectFeatures for that layer? Do I have
> to delete them too? how?
You can do vectorLayer.destroyFeatures() to empty the layer and then add
the new poditions.
Also, you may want to look at the Refresh strategy.
Cheers,
--
Eric Lemoine
Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex
Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com
http://www.camptocamp.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120505/0a6deb25/attachment.html
More information about the Users
mailing list