<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"><html><head><meta name="qrichtext" content="1" /><style type="text/css">p, li { white-space: pre-wrap; }</style></head><body style=" font-family:'DejaVu Sans'; font-size:9pt; font-weight:400; font-style:normal;">Hello all,<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>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().<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>Here is what I do:<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p> var propertyFilter = new OpenLayers.Filter.Comparison({<br>
type: OpenLayers.Filter.Comparison.EQUAL_TO,<br>
property: 'year',<br>
value: 2009<br>
});<br>
subregions = new OpenLayers.Layer.Vector("Subregions", {<br>
strategies: [new OpenLayers.Strategy.BBOX()],<br>
filter: propertyFilter,<br>
projection: new OpenLayers.Projection("EPSG:4326"),<br>
styleMap: subregionStyle,<br>
protocol: new OpenLayers.Protocol.WFS({<br>
url: "<@geoServerUrlTemplate/>/wfs",<br>
featureType: "subregions_in_time",<br>
featureNS: "http://health-e-waterways.org"<br>
})<br>
});<br>
// the next bit forces IE8 to show the overlay<br>
subregions.events.register('loadend',subregions,function(e) {<br>
map.removeLayer(subregions);<br>
map.addLayer(subregions);<br>
});<br>
map.addLayer(subregions);<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>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:<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p> function focusOnSubregion(name) {<br>
current_subregion=name;<br>
if (current_subregion == 'Northern') {<br>
map.zoomToExtent(northern_bounds);<br>
} else if (current_subregion == 'Southern') {<br>
map.zoomToExtent(southern_bounds);<br>
} else if (current_subregion == 'Western') {<br>
map.zoomToExtent(western_bounds);<br>
} else if (current_subregion == 'Moreton Bay') {<br>
map.zoomToExtent(moreton_bounds);<br>
} else {<br>
map.zoomToExtent(bounds);<br>
}<br>
var yearFilter = new OpenLayers.Filter.Comparison({<br>
type: OpenLayers.Filter.Comparison.EQUAL_TO,<br>
property: 'year',<br>
value: 2009<br>
});<br>
var subRegionFilter = new OpenLayers.Filter.Comparison({<br>
type: OpenLayers.Filter.Comparison.EQUAL_TO,<br>
property: 'subregion',<br>
value: name<br>
});<br>
var propertyFilter = new OpenLayers.Filter.Logical({<br>
type: OpenLayers.Filter.Logical.AND,<br>
filters: [yearFilter, subRegionFilter]<br>
});<br>
current_areas = new OpenLayers.Layer.Vector("Catchments", {<br>
strategies: [new OpenLayers.Strategy.BBOX()],<br>
filter: propertyFilter,<br>
projection: new OpenLayers.Projection("EPSG:4326"),<br>
styleMap: catchmentStyle,<br>
protocol: new OpenLayers.Protocol.WFS({<br>
url: "<@geoServerUrlTemplate/>/wfs",<br>
featureType: "areas_in_time",<br>
featureNS: "http://health-e-waterways.org"<br>
})<br>
});<br>
map.removeLayer(subregions);<br>
map.addLayer(current_areas);<br>
} <br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>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.<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>Am I doing something wrong? Is there something I should wait for before adding the layer?<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"><br></p>Thanks,<br>
Peter</p></body></html>