Thank you so much Arnd, that works perfectly!<br>Still need to tweak it a bit, but that shouldn't be too difficult. <br><br>Thanks again,<br><br>Alex.<br><br><div class="gmail_quote">On Tue, Jun 29, 2010 at 9:35 PM, Arnd Wippermann <span dir="ltr"><<a href="mailto:arnd.wippermann@web.de">arnd.wippermann@web.de</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5">Hi Alex,<br>
<br>
that's how I would do it. Use an Ajax request to get the GML-file and then<br>
parse it and add every feature to an new vector layer.<br>
<br>
If your GML-file residents on the same server (use relative path to the<br>
gml), then you don't need a proxy script.<br>
<br>
If have tested the below code locally with the example<br>
"spherical-mercator.html".<br>
<br>
var formats = {<br>
wkt: new OpenLayers.Format.WKT(),<br>
geojson: new OpenLayers.Format.GeoJSON(),<br>
georss: new OpenLayers.Format.GeoRSS(),<br>
gml: new OpenLayers.Format.GML(),<br>
kml: new OpenLayers.Format.KML()<br>
};<br>
<br>
function getGML()<br>
{<br>
theUrl = "/OLClient/some.gml";<br>
<br>
var myAjax = new OpenLayers.Ajax.Request(<br>
theUrl,<br>
{<br>
method: 'get',<br>
onComplete: showResponse,<br>
onFailure: showResponseFailure<br>
});<br>
}<br>
<br>
var arr = [];<br>
<br>
function showResponse(response)<br>
{<br>
var theParser = formats["gml"];<br>
theParser.internalProjection = null;<br>
theParser.externalProjection = null;<br>
theParser.extractStyles = false;<br>
theParser.extractAttributes = true;<br>
<br>
var features = theParser.read(response.responseText);<br>
<br>
</div></div><div class="im"> if(features)<br>
{<br>
if(features.constructor != Array)<br>
features = [features];<br>
<br>
</div><div class="im"> //iterate the features and put them on a vector layer<br>
</div><div class="im"> for(var i=0;i<features.length;i++)<br>
{<br>
</div><div class="im"> //get the feature type<br>
var ftType =<br>
features[i].geometry.CLASS_NAME.replace(/OpenLayers.Geometry./,"");<br>
//count the feature of a type<br>
arr[ftType] = arr[ftType] + 1;<br>
<br>
</div> var ftLyr = new OpenLayers.Layer.Vector(ftType + " " +<br>
arr[ftType]);<br>
map.addLayer(ftLyr);<br>
ftLyr.addFeatures(features[i]);<br>
}<br>
<div class="im"><br>
//to zoom to the features<br>
var bounds = features[0].geometry.getBounds().clone();<br>
for(var i=1;i<features.length;i++)<br>
bounds.extend(features[i].geometry.getBounds());<br>
map.zoomToExtent(bounds,false);<br>
}<br>
else<br>
alert('Bad input ' + type);<br>
}<br>
<br>
function showResponseFailure(response)<br>
{<br>
alert(response);<br>
}<br>
<br>
getGML();<br>
<br>
Arnd<br>
________________________________<br>
<br>
Von: Alex Brandsen [mailto:<a href="mailto:alex.brandsen@gmail.com">alex.brandsen@gmail.com</a>]<br>
Gesendet: Dienstag, 29. Juni 2010 12:23<br>
An: Arnd Wippermann<br>
</div><div><div></div><div class="h5">Cc: <a href="mailto:users@openlayers.org">users@openlayers.org</a><br>
Betreff: Re: [OpenLayers-Users] parsing a GML file into different layers<br>
<br>
<br>
Hi Arnd,<br>
<br>
thanks for your reply, this seems like it should work. I've been trying it<br>
out, but can't get it to work.. What should go in the brackets after 'GML',<br>
and where does 'response' come from? Sorry if these are really basic<br>
questions, but I don't have much experience in JS or OL...<br>
<br>
Thanks again,<br>
<br>
Alex.<br>
<br>
<br>
On Sun, Jun 27, 2010 at 2:44 PM, Arnd Wippermann <<a href="mailto:arnd.wippermann@web.de">arnd.wippermann@web.de</a>><br>
wrote:<br>
<br>
<br>
Hi,<br>
<br>
something like this should work:<br>
<br>
var features = new OpenLayers.Format.GML().read(response);<br>
<br>
if(features)<br>
{<br>
if(features.constructor != Array)<br>
features = [features];<br>
<br>
for(var i=0;i<features.length;i++)<br>
{<br>
var ftLyr = new OpenLayers.Layer.Vector("Feature " + i);<br>
addLayer(ftLyr);<br>
ftLyr.addFeatures(features[i]);<br>
}<br>
}<br>
<br>
Arnd<br>
<br>
________________________________<br>
<br>
Von: <a href="mailto:users-bounces@openlayers.org">users-bounces@openlayers.org</a><br>
[mailto:<a href="mailto:users-bounces@openlayers.org">users-bounces@openlayers.org</a>] Im Auftrag von Alex Brandsen<br>
Gesendet: Sonntag, 27. Juni 2010 14:43<br>
An: Eric Lemoine<br>
Cc: <a href="mailto:users@openlayers.org">users@openlayers.org</a><br>
Betreff: Re: [OpenLayers-Users] parsing a GML file into different<br>
layers<br>
<br>
<br>
Hi Eric,<br>
<br>
thanks for your reply. I probably need to use OpenLayers.<br>
Format.GML.read() , but how do I then split the array it returns into<br>
different layers?<br>
<br>
Thanks,<br>
<br>
Alex.<br>
<br>
<br>
On Sat, Jun 26, 2010 at 7:12 AM, Eric Lemoine<br>
<<a href="mailto:eric.lemoine@camptocamp.com">eric.lemoine@camptocamp.com</a>> wrote:<br>
<br>
<br>
On Friday, June 25, 2010, Alex Brandsen<br>
<<a href="mailto:alex.brandsen@gmail.com">alex.brandsen@gmail.com</a>> wrote:<br>
> Hi all,<br>
><br>
> I'm building a map of a medieval wallpainting, and the<br>
graffiti inscribed in this wall, which can be found on<br>
<a href="http://www.thomasav.com/DurhamGraffiti/" target="_blank">www.thomasav.com/DurhamGraffiti/</a> (still quite buggy though!).<br>
> I was wondering if there is a way for OpenLayers to<br>
dynamically turn features from a single GML file into seperate layers, by<br>
providing an array of feature id's. I've been looking through the<br>
documentation and been googling around, but I can't seem to find anything<br>
useful. Perhaps "OpenLayers. Filter. FeatureId" could do something like<br>
this, but the documentation on this is quite sparse..<br>
><br>
> Ofcourse, I could just write a php script that would<br>
pre-parse the gml into seperate, temporary gml files, but I think using<br>
OpenLayers itself would be preferable.<br>
><br>
> If anyone has any ideas, I would be very grateful!<br>
<br>
<br>
<br>
Hi<br>
<br>
The protocol or format that you use will give you an array<br>
of<br>
features. You are then free to dispatch the features to<br>
separate<br>
vector layers, for example based on their ids.<br>
<br>
I hope it helps,<br>
<br>
<br>
--<br>
Eric Lemoine<br>
<br>
Camptocamp France SAS<br>
Savoie Technolac, BP 352<br>
73377 Le Bourget du Lac, Cedex<br>
<br>
Tel : 00 33 4 79 44 44 96<br>
Mail : <a href="mailto:eric.lemoine@camptocamp.com">eric.lemoine@camptocamp.com</a><br>
<a href="http://www.camptocamp.com" target="_blank">http://www.camptocamp.com</a><br>
<br>
<br>
<br>
<br>
<br>
</div></div></blockquote></div><br>