[OpenLayers-Users] Vector layer not displaying after load

Peter Becker pbecker at itee.uq.edu.au
Mon Sep 7 21:51:09 EDT 2009


I still haven't figured out what the problem really is, but it seems to work if 
I don't zoom just before switching layers (i.e. remove all the 
zoomToExtent(..) calls). Is there any way to wait for a zoom to finish?

Thanks,
   Peter


On Mon, 7 Sep 2009 09:13:36 am Peter Becker wrote:
> Hello all,
>
> I'm trying to use Vector layers based on WFS and I am encountering issues
> with the layers not displaying straight away. To display them properly I
> need to remove them and add them again or call refresh().
>
> Here is what I do:
>
>         var propertyFilter = new OpenLayers.Filter.Comparison({
>             type: OpenLayers.Filter.Comparison.EQUAL_TO,
>             property: 'year',
>             value: 2009
>         });
>         subregions = new OpenLayers.Layer.Vector("Subregions", {
>             strategies: [new OpenLayers.Strategy.BBOX()],
>             filter: propertyFilter,
>             projection: new OpenLayers.Projection("EPSG:4326"),
>             styleMap: subregionStyle,
>             protocol: new OpenLayers.Protocol.WFS({
>                 url:  "<@geoServerUrlTemplate/>/wfs",
>                 featureType: "subregions_in_time",
>                 featureNS: "http://health-e-waterways.org"
>             })
>         });
>         // the next bit forces IE8 to show the overlay
>         subregions.events.register('loadend',subregions,function(e) {
>             map.removeLayer(subregions);
>             map.addLayer(subregions);
>         });
>         map.addLayer(subregions);
>
> Note the event hook, which fixes this layer for IE8 (it worked in Firefox
> out of the box). The same trick does not work if I swap in another layer
> later. I can't get this bit of code to work properly at all:
>
>     function focusOnSubregion(name) {
>         current_subregion=name;
>         if (current_subregion == 'Northern') {
>             map.zoomToExtent(northern_bounds);
>         } else if (current_subregion == 'Southern') {
>             map.zoomToExtent(southern_bounds);
>         } else if (current_subregion == 'Western') {
>             map.zoomToExtent(western_bounds);
>         } else if (current_subregion == 'Moreton Bay') {
>             map.zoomToExtent(moreton_bounds);
>         } else {
>             map.zoomToExtent(bounds);
>         }
>         var yearFilter = new OpenLayers.Filter.Comparison({
>             type: OpenLayers.Filter.Comparison.EQUAL_TO,
>             property: 'year',
>             value: 2009
>         });
>         var subRegionFilter = new OpenLayers.Filter.Comparison({
>             type: OpenLayers.Filter.Comparison.EQUAL_TO,
>             property: 'subregion',
>             value: name
>         });
>         var propertyFilter = new OpenLayers.Filter.Logical({
>             type: OpenLayers.Filter.Logical.AND,
>             filters: [yearFilter, subRegionFilter]
>         });
>         current_areas = new OpenLayers.Layer.Vector("Catchments", {
>             strategies: [new OpenLayers.Strategy.BBOX()],
>             filter: propertyFilter,
>             projection: new OpenLayers.Projection("EPSG:4326"),
>             styleMap: catchmentStyle,
>             protocol: new OpenLayers.Protocol.WFS({
>                 url:  "<@geoServerUrlTemplate/>/wfs",
>                 featureType: "areas_in_time",
>                 featureNS: "http://health-e-waterways.org"
>             })
>         });
>         map.removeLayer(subregions);
>         map.addLayer(current_areas);
>     }
>
> I tried using the "loadend" event again with various things in it, but it
> doesn't work. Turning the layer off/on manually does as does a call to
> refresh() later.
>
> Am I doing something wrong? Is there something I should wait for before
> adding the layer?
>
> Thanks,
>    Peter

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090908/bca58491/attachment.html


More information about the Users mailing list