From 651b60f8f7b9ba324939f3d113760040a2c6c5f1 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Mon, 14 Jan 2008 14:42:29 +0000 Subject: [PATCH] New layer type PointTrack: connects point features to lines. r=crschmidt,elemoine. (closes #1167) git-svn-id: http://svn.openlayers.org/trunk/openlayers@5733 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- examples/point-track-markers.html | 66 ++++++++++++++++++++ examples/xml/track1.xml | 98 +++++++++++++++++++++++++++++ lib/OpenLayers.js | 1 + lib/OpenLayers/Layer/PointTrack.js | 99 ++++++++++++++++++++++++++++++ tests/Layer/test_PointTrack.html | 79 ++++++++++++++++++++++++ tests/list-tests.html | 1 + 6 files changed, 344 insertions(+) create mode 100644 examples/point-track-markers.html create mode 100644 examples/xml/track1.xml create mode 100644 lib/OpenLayers/Layer/PointTrack.js create mode 100644 tests/Layer/test_PointTrack.html diff --git a/examples/point-track-markers.html b/examples/point-track-markers.html new file mode 100644 index 0000000000..5de8818843 --- /dev/null +++ b/examples/point-track-markers.html @@ -0,0 +1,66 @@ + + + + + + + +

GeoRSS PointTrack in OpenLayers

+

This demo uses OpenLayers.Layer.GeoRSS and OpenLayers.Layer.PointTrack. The track is created by connecting the points of the GeoRSS feed.

+
+ GeoRSS URL: +
+

The above input box allows the input of a URL to a GeoRSS feed. This feed can be local to the HTML page -- for example, entering 'xml/track1.xml' will work by default.

+

The example shows a track, displayed as a line connecting the points of the feed. It also shows markers at positions that have a title tag in the rss item. If clicked, a popup will show title and description.

+
+ + diff --git a/examples/xml/track1.xml b/examples/xml/track1.xml new file mode 100644 index 0000000000..1e2e2c9b07 --- /dev/null +++ b/examples/xml/track1.xml @@ -0,0 +1,98 @@ + + + +Title for First trial track +Description for first track +Nelson +1995-12-12T05:00:00Z22.1862861120.30211944Phase ChangeStart Phase A +1995-12-12T05:05:00Z22.1862194420.28514722 +1995-12-12T05:10:00Z22.1860972220.266425 +1995-12-12T05:15:00Z22.1827972220.24935 +1995-12-12T05:16:00Z22.1815388920.24605556Course Change220 degs 4kts +1995-12-12T05:20:00Z22.176420.23299444 +1995-12-12T05:25:00Z22.1699611120.21654167 +1995-12-12T05:30:00Z22.1635194420.20017222 +1995-12-12T05:35:00Z22.1571055620.18375278 +1995-12-12T05:40:00Z22.1506277820.16738889 +1995-12-12T05:42:00Z22.1480333320.16077222CommentXO has bridge +1995-12-12T05:45:00Z22.1441638920.15091944 +1995-12-12T05:50:00Z22.1375777820.13483333 +1995-12-12T05:55:00Z22.1254166720.134125 +1995-12-12T06:00:00Z22.1125055620.13402778 +1995-12-12T06:05:00Z22.0996027820.13395 +1995-12-12T06:10:00Z22.0881222220.14054722Comment +1995-12-12T06:13:00Z22.0814138920.14618333Course Change220 degs 4kts +1995-12-12T06:15:00Z22.0769527820.14992778 +1995-12-12T06:20:00Z22.0658416720.15931111 +1995-12-12T06:25:00Z22.0546027820.16871944 +1995-12-12T06:30:00Z22.0431583320.16791667 +1995-12-12T06:35:00Z22.0311861120.16143056 +1995-12-12T06:40:00Z22.0191222220.15486389 +1995-12-12T06:45:00Z22.0070833320.14833056 +1995-12-12T06:50:00Z21.9950444420.14181111 +1995-12-12T06:55:00Z21.9842388920.14733611 +1995-12-12T07:00:00Z21.9736722220.15803333 +1995-12-12T07:05:00Z21.9630611120.16874444 +1995-12-12T07:10:00Z21.9540722220.17233611 +1995-12-12T07:15:00Z21.9588555620.15766944 +1995-12-12T07:20:00Z21.9663083320.16956944 +1995-12-12T07:25:00Z21.9745055620.18388056 +1995-12-12T07:30:00Z21.9827638920.19838333 +1995-12-12T07:32:00Z21.9860527820.20413056CommentSuspect opponent to North, slowing down +1995-12-12T07:33:00Z21.9869166720.20727778CommentVIP visitors due. Helo retrieved. +1995-12-12T07:34:00Z21.9856694420.20985556CommentWind picked up. Switching off sensor Delta +1995-12-12T07:35:00Z21.984220.21243611CommentHeavenly dusk +1995-12-12T07:40:00Z21.9760944420.226425 +1995-12-12T07:45:00Z21.9678611120.240725 +1995-12-12T07:50:00Z21.959520.25507778 +1995-12-12T07:55:00Z21.9511805620.26941389 +1995-12-12T08:00:00Z21.9486277820.28483056 +1995-12-12T08:05:00Z21.9529520.30239444 +1995-12-12T08:10:00Z21.95732520.32020278 +1995-12-12T08:15:00Z21.9617222220.33795278 +1995-12-12T08:20:00Z21.9661611120.35568611 +1995-12-12T08:25:00Z21.9635555620.371925 +1995-12-12T08:30:00Z21.9587777820.38858333 +1995-12-12T08:35:00Z21.9598888920.40708333 +1995-12-12T08:40:00Z21.9636194420.41884722 +1995-12-12T08:45:00Z21.9694555620.40425278Course Change220 degs 4kts +1995-12-12T08:50:00Z21.975920.38807778 +1995-12-12T08:55:00Z21.9823722220.37183889 +1995-12-12T09:00:00Z21.9888027820.35546667 +1995-12-12T09:05:00Z21.9996861120.34794722 +1995-12-12T09:10:00Z22.0117916720.34156389 +1995-12-12T09:15:00Z22.0216861120.34614444 +1995-12-12T09:20:00Z22.0281111120.36220833 +1995-12-12T09:25:00Z22.0345611120.37856389Phase ChangeEnd Phase A +1995-12-12T09:30:00Z22.0414520.36952222 +1995-12-12T09:35:00Z22.0478222220.35348611 +1995-12-12T09:40:00Z22.0542638920.33713056 +1995-12-12T09:45:00Z22.0606944420.32085 +1995-12-12T09:46:00Z22.0619861120.31761111Phase ChangeStart Phase B +1995-12-12T09:50:00Z22.0647194420.30389444 +1995-12-12T09:55:00Z22.0758666720.29758333 +1995-12-12T10:00:00Z22.0879388920.29113889 +1995-12-12T10:05:00Z22.1000333320.2848 +1995-12-12T10:10:00Z22.1121972220.27842222 +1995-12-12T10:15:00Z22.1153055620.26194167 +1995-12-12T10:20:00Z22.1175694420.24336667 +1995-12-12T10:25:00Z22.1198611120.22466944 +1995-12-12T10:30:00Z22.1223833320.20620833 +1995-12-12T10:35:00Z22.1289027820.216475 +1995-12-12T10:40:00Z22.1235194420.22643333 +1995-12-12T10:45:00Z22.1209972220.23426667 +1995-12-12T10:50:00Z22.1219416720.23018333 +1995-12-12T10:55:00Z22.1187277820.23548056 +1995-12-12T11:00:00Z22.1199416720.23541111 +1995-12-12T11:05:00Z22.1199277820.23948056 +1995-12-12T11:10:00Z22.1180222220.24473889 +1995-12-12T11:15:00Z22.1176444420.24835278 +1995-12-12T11:20:00Z22.1221555620.24788889 +1995-12-12T11:25:00Z22.1172527820.25047778 +1995-12-12T11:30:00Z22.1225972220.24290278 +1995-12-12T11:35:00Z22.1292194420.24653889 +1995-12-12T11:40:00Z22.1397083320.25221389 +1995-12-12T11:41:00Z22.1417388920.25330556Phase ChangeEnd Phase B + + + diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index 6c8ca91fc9..738973c18b 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -164,6 +164,7 @@ "OpenLayers/Renderer/SVG.js", "OpenLayers/Renderer/VML.js", "OpenLayers/Layer/Vector.js", + "OpenLayers/Layer/PointTrack.js", "OpenLayers/Layer/GML.js", "OpenLayers/Style.js", "OpenLayers/Rule.js", diff --git a/lib/OpenLayers/Layer/PointTrack.js b/lib/OpenLayers/Layer/PointTrack.js new file mode 100644 index 0000000000..44bac051d4 --- /dev/null +++ b/lib/OpenLayers/Layer/PointTrack.js @@ -0,0 +1,99 @@ +/* Copyright (c) 2006-2007 MetaCarta, Inc., published under the Clear BSD + * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the + * full text of the license. */ + +/** + * @requires OpenLayers/Layer/Vector.js + * + * Class: OpenLayers.Layer.PointTrack + * Vector layer to display ordered point features as a line, creating one + * LineString feature for each pair of two points. + * + * Inherits from: + * - + */ +OpenLayers.Layer.PointTrack = OpenLayers.Class(OpenLayers.Layer.Vector, { + + /** + * APIProperty: + * dataFrom - {} optional. If the + * lines should get the data/attributes from one of the two + * points, creating it, which one should it be? + */ + dataFrom: null, + + /** + * Constructor: OpenLayers.PointTrack + * Constructor for a new OpenLayers.PointTrack instance. + * + * Parameters: + * name - {String} name of the layer + * options - {Object} Optional object with properties to tag onto the + * instance. + */ + initialize: function(name, options) { + OpenLayers.Layer.Vector.prototype.initialize.apply(this, arguments); + }, + + /** + * APIMethod: addNodes + * Adds point features that will be used to create lines from, using point + * pairs. The first point of a pair will be the source node, the second + * will be the target node. + * + * Parameters: + * pointFeatures - {Array()} + * + */ + addNodes: function(pointFeatures) { + if (pointFeatures.length < 2) { + OpenLayers.Console.error( + "At least two point features have to be added to create" + + "a line from"); + return; + } + + var lines = new Array(pointFeatures.length-1); + + var pointFeature, startPoint, endPoint; + for(var i = 0; i < pointFeatures.length; i++) { + pointFeature = pointFeatures[i]; + endPoint = pointFeature.geometry; + + if (!endPoint) { + var lonlat = pointFeature.lonlat; + endPoint = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat); + } else if(endPoint.CLASS_NAME != "OpenLayers.Geometry.Point") { + OpenLayers.Console.error( + "Only features with point geometries are supported."); + return; + } + + if(i > 0) { + var attributes = (this.dataFrom != null) ? + (pointFeatures[i+this.dataFrom].data || + pointFeatures[i+this.dataFrom].attributes) : + null; + var line = new OpenLayers.Geometry.LineString([startPoint, + endPoint]); + + lines[i-1] = new OpenLayers.Feature.Vector(line, attributes); + } + + startPoint = endPoint; + } + + this.addFeatures(lines); + }, + + CLASS_NAME: "OpenLayers.Layer.PointTrack" +}); + +/** + * Constant: OpenLayers.Layer.PointTrack.dataFrom + * {Object} with the following keys + * - SOURCE_NODE: take data/attributes from the source node of the line + * - TARGET_NODE: take data/attributes from the target node of the line + */ +OpenLayers.Layer.PointTrack.dataFrom = {'SOURCE_NODE': -1, 'TARGET_NODE': 0}; + diff --git a/tests/Layer/test_PointTrack.html b/tests/Layer/test_PointTrack.html new file mode 100644 index 0000000000..11ace62b88 --- /dev/null +++ b/tests/Layer/test_PointTrack.html @@ -0,0 +1,79 @@ + + + + + + +
+ + diff --git a/tests/list-tests.html b/tests/list-tests.html index 433f51379c..a522a29743 100644 --- a/tests/list-tests.html +++ b/tests/list-tests.html @@ -57,6 +57,7 @@
  • Layer/test_MapServer.html
  • Layer/test_Markers.html
  • Layer/test_MultiMap.html
  • +
  • Layer/test_PointTrack.html
  • Layer/test_SphericalMercator.html
  • Layer/test_Text.html
  • Layer/test_TileCache.html