[OpenLayers-Users] Vector layer not displaying after load
Peter Becker
pbecker at itee.uq.edu.au
Sun Sep 6 19:13:36 EDT 2009
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/20090907/d1e37101/attachment.html
More information about the Users
mailing list