[OpenLayers-Users] dynamic WMS add/remove problem

Andreas Hocevar ahocevar at opengeo.org
Tue Jun 16 09:36:54 EDT 2009


Hi,

no need to remove, destroy and re-add the layer. If your WMS URL stays
the same, all you need to do is

var layer=window.parent.map.getLayer("shapefile");
if(layer !== null) {
    layer.redraw(true);
}

This will force WMS images to be re-fetched, by adding a unique url
parameter to the requests.

Regards,
Andreas.

On Mon, Jun 15, 2009 at 5:25 PM, Balázs Bámer<bamerbalazs at gmail.com> wrote:
> Hi All,
>
> I try to create a page where the user can upload a shapefile (dbf shp
> shx in a zip file) and its contents are added to the existing display
> of WMSes. This works fine. However, my goal is to allow only one
> uploaded shapefile to be displayed, so when the user uploads a new
> one, the old should be removed and the new one is displayed instead.
> The old one reappears. This happens even if a wrong file is uploaded
> between the two good ones: first the old one is removed, error message
> appears (fine), but the new good shapefile just brings back the old
> one. After page reload if I start with the new one, it is displayed
> but the behaviour is similar. The phenomenon is the same under
> Openlayers 2.7 and 2.8 rc5.
>
> Here is the application:
> http://att-it.homelinux.net:22080/blokknez/
> file must be selected in the file box "Fajl".
>
> Here are two shapefiles to experiment with:
> http://att-it.homelinux.net:22080/blokknez/meres.zip
> http://att-it.homelinux.net:22080/blokknez/meres2.zip
>
> The code is here:
> http://att-it.homelinux.net:22080/blokknez/index.php.txt
>
> The code used to add WMS:
> var shapefile_wms = new OpenLayers.Layer.WMS("shapefile [name from PHP var]",
> "http://att-it.homelinux.net:22080/cgi-bin/ms-5.4.1/mapserv",
> {
>    layers: 'shapefile',
>    map: '/var/lib/mapserver-5.4.1/blokknez/shapefile/shapefile.map',
>    transparent: "true"
> },
> {
>    scales:[2000000,1500000,1000000,750000,500000,300000,200000,150000,100000,75000,50000,30000,20000,15000,10000,7500,5000,3000,2000,1500,1000],
>    isBaseLayer:false,
>    visibility:true
> });
> window.parent.map.addLayer(shapefile_wms);
> shapefile_wms.id="shapefile";
>
> The code used for WMS removal (try needed because OpenLayers 2.7 threw
> some exception):
> layer=window.parent.map.getLayer("shapefile");
> if(layer!==null) {
>        window.parent.map.removeLayer(layer);
>        try {
>                layer.destroy();
>        }catch(dfdf) {}
> }
>
> The exception without try in Firebug is
> OpenLayers is not defined
> getURL()()OpenLayers.js (sor 1382)
> blokknez()()blokknez (sor 9)
> [Break on this error]
> if(this.params.FORMAT=="image/jpeg"){thi...ame,this.url,this.params,this.options);}
>
> What can be the problem?
>
> Thank you in advance.
> Best regards: Balázs
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>



-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.



More information about the Users mailing list