0

I have build a web application in which I use OpenLayers to display data on a map. I use GeoServer to serve my data. Till a specific zoom level I display a raster WMS (road network) and after this zoom level I remove the WMS layer and make a WFS request, which returns features (using bbox strategy). Everything works fine. The speed is also quite satisfying. But I saw something in my firebug which I don't quite understand. This is what it happens:

  1. I have adjusted in zoomLevel = 11 to make the WFS request and remove the WMS layer.
  2. When I zoom in and reach this zoom level indeed I see (in firebug) two POST requests (WFS) to be sent. I see the response etc. Everything is fine.
  3. The strange thing happens on zoom out. On zoom out although everything seems to work fine (WFS layer disappears and WMS layer appears) I see on my firebug that two WFS POST requests are sent (the same as before) and I get the same response. The exact same requests I make on zoom in happen also on zoom out (only for this zoom level). Nothing is rendered on the map. Just the POST requests are made but not displayed.

Obviously is something small that I am missing here.

Here is part of my code:

   // CREATE LAYER WITH NETWORK FROM GEOSERVER  
    wms_layer_network = new OpenLayers.Layer.WMS( "Whole Network", "http://localhost:8080/geoserver/gwc/service/wms", //http://192.168.2.6:8080/geoserver/wms
        {
            layers: 'rural:foc_network',
            transparent: true,
            tiled: true
        },
        {
            format: "image/png",
            visibility: true,
            displayOutsideMaxExtent: false,
            projection: new OpenLayers.Projection("EPSG:900913")
        }); 


      map.addLayer([wms_layer_network]);

       map.events.register("zoomend", map, function(){ // event zoomend 
          zoom = map.getZoom();
          var layerNetwork = map.getLayersByName('Network Part'); // check if the layer network exists

        if((zoom==valueZoom) && (layerNetwork.length==0)){


              // OVERLAY WFS LAYER WITH NETWORK FROM GEOSERVER BBOX STRATEGY
                wfs_layer_network = new OpenLayers.Layer.Vector("Network Part", {

                    <!-- DEFINE STYLE FOR LINES -->
                    styleMap: featurestyleMap,  
                    visibility: true,
                    //displayInLayerSwitcher: true,                     
                    strategies: [new OpenLayers.Strategy.BBOX()],
                    protocol: new OpenLayers.Protocol.WFS({
                        version: "1.1.0",
                        url: "http://localhost:8080/geoserver/wfs", 
                        featurePrefix: "rural", //workspace from geoserver
                        featureType: "foc_network", //layer name from geoserver  
                        featureNS : "http://www.opengeospatial.net/rural", //namespace from geoserver
                    })
                })
                map.removeLayer(wms_layer_network);
                map.addLayer(wfs_layer_network);....
  • I suspect your code has no idea which way you are zooming and fires the request as you pass through that zoom level in & out – Ian Turton Mar 17 '15 at 14:58
  • Is there a way to make my code know this? – user1919 Mar 17 '15 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.