From 8f584f2b8468122a42a7fd05326cd9cb642a15e1 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Tue, 22 Mar 2011 13:46:33 +0000 Subject: [PATCH] Making Layer.PointTrack play nicely with gx:Track from Format.KML. Thanks bartvde for the updated patch. r=fredj,bartvde (closes #2792) git-svn-id: http://svn.openlayers.org/trunk/openlayers@11722 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- examples/kml-pointtrack.html | 38 +++++++++++++++++++++++++++ examples/kml-pointtrack.js | 51 ++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 examples/kml-pointtrack.html create mode 100644 examples/kml-pointtrack.js diff --git a/examples/kml-pointtrack.html b/examples/kml-pointtrack.html new file mode 100644 index 0000000000..04c2a4c8b8 --- /dev/null +++ b/examples/kml-pointtrack.html @@ -0,0 +1,38 @@ + + + + + + OpenLayers KML Track in a PointTrack Layer Example + + + + + + + + +

Parsing gx:Track in KML

+

+ Demonstrates populating a PointTrack layer with gx:Track elements from KML. +

+
+
+

+ If a KML document contains <gx:Track> + elements and the extractTracks property is set true on the + parser, features will be created that represent track points. + These track points can easily be visualized as track lines with + a PointTrack layer, preserving the KML's original + styles. +

+

+ View the kml-pointtrack.js + source to see how this is done. +

+ + diff --git a/examples/kml-pointtrack.js b/examples/kml-pointtrack.js new file mode 100644 index 0000000000..47836f25fd --- /dev/null +++ b/examples/kml-pointtrack.js @@ -0,0 +1,51 @@ +var map; + +function init() { + + var mercator = new OpenLayers.Projection("EPSG:900913"); + var geographic = new OpenLayers.Projection("EPSG:4326"); + + map = new OpenLayers.Map({ + div: "map", + projection: mercator, + layers: [ + new OpenLayers.Layer.OSM(), + new OpenLayers.Layer.PointTrack("Aircraft Tracks", { + projection: geographic, + strategies: [new OpenLayers.Strategy.Fixed()], + protocol: new OpenLayers.Protocol.HTTP({ + url: "kml-track.kml", + format: new OpenLayers.Format.KML({ + extractTracks: true, + extractStyles: true + }) + }), + dataFrom: OpenLayers.Layer.PointTrack.TARGET_NODE, + styleFrom: OpenLayers.Layer.PointTrack.TARGET_NODE, + eventListeners: { + "beforefeaturesadded": function(e) { + // group the tracks by fid and create one track for + // every fid + var fid, points = [], feature; + for (var i=0, len=e.features.length; i