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

Robert Sanson Robert.Sanson at asurequality.com
Wed Apr 17 16:04:55 PDT 2013


OK - here is what works:

Once I have read in the local GPX file into memory, I have a function that creates the Vector layer:

var gpx_format = new OpenLayers.Format.GPX({externalProjection: new OpenLayers.Projection('EPSG:4326'),
     internalProjection: new OpenLayers.Projection('EPSG:2193')});
var reader = new FileReader();
reader.onload = function(event) {
	var contents = event.target.result;
	//alert(contents);
	var olgpx = gpx_format.read(contents);
	var gpxl = new OpenLayers.Layer.Vector("GPX Points",
		{isBaseLayer: false,
		styleMap: gpxStyles,
		rendererOptions: {zIndexing: true},
		extractAttributes: true });
	gpxl.addFeatures(olgpx);
	alert("added " + gpxl.features.length + " features to layer");
	map.addLayer(gpxl);
	alert("added gpx layer to map");
	map.zoomToExtent(gpxl.getDataExtent());
};

Kind regards,

Robert Sanson



This email and any attachments are confidential and intended solely for the addressee(s). If you are not the intended recipient, please notify us immediately and then delete this email from your system.

This message has been scanned for Malware and Viruses by Websense Hosted Security.
www.websense.com


More information about the Users mailing list