[OpenLayers-Users] Loading a local GPX file into an OpenLayers Vector layer

Mark Prins mc.prins at gmail.com
Thu Apr 18 04:32:53 PDT 2013


> What OpenLayers protocol settings can I use to pass the file contents to the OpenLayers GPX reader?
>
> This code works if I have one of the GPX files in my htdocs directory:
>
> var wgs84 = new OpenLayers.Projection("EPSG:4326");
>         map.addLayer(new OpenLayers.Layer.Vector("GPX Vectors", {
>            styleMap: gpxStyles,
>             eventListeners: {
>                 "featuresadded": function(event) {
>                     // 'this' is layer
>                     this.map.zoomToExtent(this.getDataExtent());
>                 }
>             },
>             projection: wgs84,
>             strategies: [new OpenLayers.Strategy.Fixed()],
>             protocol: new OpenLayers.Protocol.HTTP({
>                 url: "deer 5-10-12.gpx",
>                 format: new OpenLayers.Format.GPX()
>             })
>         }));
>
> But I want to point the url to the file in memory of the client browser, or use some other approach.

I think you'd need to write a new OpenLayers.Protocol implementation
that uses the FileReader.readAsText(File) method

OpenLayers.Protocol.Script might have some pointers on how to implement that.

Mark


--
Disclaimer;
This message is just a reflection of what I thought at the time of
sending. The message may contain information that is not intended for
you or that you don't understand.


More information about the Users mailing list