Talk:Openlayers Track example

From OpenStreetMap Wiki
Jump to navigation Jump to search

format: OpenLayers.Format.GPX

You are aware that it's easier to just do:

var gpx = new OpenLayers.Layer.GML("GPX Track", "file.gpx", {
  format: OpenLayers.Format.GPX,
  projection: new OpenLayers.Projection("EPSG:4326"),
  style: {strokeColor: "green"}
};
map.addLayer(gpx);

Rather than writing your own GPX parser etc? --Thomas Wood 17:05, 25 November 2008 (UTC)


Thanks for the update, of course it's simpler. But this is not working for me. I don't see the track. Please post here a working example. :--Zapfen 07:45, 26 November 2008 (UTC)

Out of date?

Given the above comment (from 2008), and the fact the layer constructors are following an old format, I think this example is hopelessly out of date. Does it still work? -- Harry Wood 13:55, 9 September 2010 (BST)

strokeWidth

I got this example working by adding a "strokeWidth" to the list of style attributes (presumably defaults to zero?). I also added a strokeOpacity fraction so that one can see the underlying map ways under the track overlay (opacity seems to default to 1.0). User:Neil_Hoggarth 29th March 2009.

Example link

example link http://edgemaster.dev.openstreetmap.org/OpenLayersExamples/Track/ does not work (http-code: 404) -- jklippel 14:26, 30 May 2010 (UTC)

OpenLayers.Layer.GML is depreciated

As OpenLayers.Layer.GML is depreciated you have to add:

  <script type="text/javascript" src="http://dev.openlayers.org/releases/OpenLayers-2.12/lib/deprecated.js"></script>

to get the examples to work.

The examples should be rewritten to something like:

          var lgpx = new OpenLayers.Layer.Vector( 'Features', {
             strategies: [new OpenLayers.Strategy.Fixed()],
             projection:map.displayProjection,
             protocol: new OpenLayers.Protocol.HTTP({
                url: example.gpx,
                format: new OpenLayers.Format.GPX
             })
             }
          );

Opera Browser Trouble

The example works fine in InternetExplorer and Firefox but Opera won't show the track, only the marker. Any hints? --NoName0815

I got it - it's showing after changing the default settings...
XMLHttpRequest to files is disabled for security reasons. Set "Allow File XMLHttpRequest" with opera:config#UserPrefs|AllowFileXMLHttpRequest to disable this security check. --NoName0815 16:55, 14 September 2012 (BST)
Thank you! I had the same problem when testing my Openlayers locally and your solution worked. Nillerdk 13:29, 4 November 2012 (UTC)

See the "common issues" section for a general solution (using a HTTP server). --Gormo (talk) 13:16, 7 April 2015 (UTC)