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
This commit is contained in:
66
examples/point-track-markers.html
Normal file
66
examples/point-track-markers.html
Normal file
@@ -0,0 +1,66 @@
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<style type="text/css">
|
||||
#map {
|
||||
width: 800px;
|
||||
height: 400px;
|
||||
border: 1px solid black;
|
||||
}
|
||||
</style>
|
||||
<script src="../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
var map, layer, rss, lineFeatures, popup;
|
||||
|
||||
OpenLayers.ProxyHost = "/proxy/?url=";
|
||||
function init(){
|
||||
map = new OpenLayers.Map('map', {maxResolution:'auto'});
|
||||
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
||||
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
|
||||
map.addLayer(layer);
|
||||
map.setCenter(new OpenLayers.LonLat(20.22, 22.05), 9);
|
||||
map.addControl(new OpenLayers.Control.LayerSwitcher());
|
||||
}
|
||||
|
||||
function addUrl() {
|
||||
var urlObj = OpenLayers.Util.getElement('url');
|
||||
var value = urlObj.value;
|
||||
var parts = value.split("/");
|
||||
rss = new OpenLayers.Layer.GeoRSS(parts[parts.length-1], value);
|
||||
rss.events.register("loadend", window, populateMap);
|
||||
}
|
||||
|
||||
function populateMap() {
|
||||
// create the point track layer
|
||||
var lineLayer = new OpenLayers.Layer.PointTrack(rss.name + " Track",
|
||||
{dataFrom: OpenLayers.Layer.PointTrack.dataFrom.SOURCE_NODE});
|
||||
// add the features from the rss layer to the track layer. This
|
||||
// also works with OpenLayers.Feature.Vector features.
|
||||
lineLayer.addNodes(rss.features);
|
||||
map.addLayer(lineLayer);
|
||||
|
||||
rss.setName(rss.name + " Comments");
|
||||
|
||||
var feature, marker;
|
||||
// only show markers for features that are not "Untitled"
|
||||
for (var i = 0; i< rss.features.length-1; i++) {
|
||||
if (rss.features[i].data.popupContentHTML.indexOf(
|
||||
"Untitled") != -1) {
|
||||
// nullify lonlat to hide marker
|
||||
rss.markers[i].lonlat = null;
|
||||
}
|
||||
}
|
||||
map.addLayer(rss);
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init()">
|
||||
<h1>GeoRSS PointTrack in OpenLayers</h1>
|
||||
<p style="font-size:.9em;">This demo uses OpenLayers.Layer.GeoRSS and OpenLayers.Layer.PointTrack. The track is created by connecting the points of the GeoRSS feed.</a></p>
|
||||
<form onsubmit="return false;">
|
||||
GeoRSS URL: <input type="text" id="url" size="50" /><input type="submit" onclick="addUrl(); return false;" value="Load Feed" onsubmit="addUrl(); return false;" />
|
||||
</form>
|
||||
<p>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.</p>
|
||||
<p>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.</p>
|
||||
<div id="map"></div>
|
||||
</body>
|
||||
</html>
|
||||
98
examples/xml/track1.xml
Normal file
98
examples/xml/track1.xml
Normal file
@@ -0,0 +1,98 @@
|
||||
<rss version="2.0" xmlns:geo="http://www.georss.org/georss">
|
||||
<channel>
|
||||
|
||||
<title>Title for First trial track</title>
|
||||
<description>Description for first track</description>
|
||||
<category>Nelson</category>
|
||||
<item><pubDate>1995-12-12T05:00:00Z</pubDate><geo:lat>22.18628611</geo:lat><geo:long>20.30211944</geo:long><title>Phase Change</title><description>Start Phase A</description></item>
|
||||
<item><pubDate>1995-12-12T05:05:00Z</pubDate><geo:lat>22.18621944</geo:lat><geo:long>20.28514722</geo:long></item>
|
||||
<item><pubDate>1995-12-12T05:10:00Z</pubDate><geo:lat>22.18609722</geo:lat><geo:long>20.266425</geo:long></item>
|
||||
<item><pubDate>1995-12-12T05:15:00Z</pubDate><geo:lat>22.18279722</geo:lat><geo:long>20.24935</geo:long></item>
|
||||
<item><pubDate>1995-12-12T05:16:00Z</pubDate><geo:lat>22.18153889</geo:lat><geo:long>20.24605556</geo:long><title>Course Change</title><description>220 degs 4kts</description></item>
|
||||
<item><pubDate>1995-12-12T05:20:00Z</pubDate><geo:lat>22.1764</geo:lat><geo:long>20.23299444</geo:long></item>
|
||||
<item><pubDate>1995-12-12T05:25:00Z</pubDate><geo:lat>22.16996111</geo:lat><geo:long>20.21654167</geo:long></item>
|
||||
<item><pubDate>1995-12-12T05:30:00Z</pubDate><geo:lat>22.16351944</geo:lat><geo:long>20.20017222</geo:long></item>
|
||||
<item><pubDate>1995-12-12T05:35:00Z</pubDate><geo:lat>22.15710556</geo:lat><geo:long>20.18375278</geo:long></item>
|
||||
<item><pubDate>1995-12-12T05:40:00Z</pubDate><geo:lat>22.15062778</geo:lat><geo:long>20.16738889</geo:long></item>
|
||||
<item><pubDate>1995-12-12T05:42:00Z</pubDate><geo:lat>22.14803333</geo:lat><geo:long>20.16077222</geo:long><title>Comment</title><description>XO has bridge</description></item>
|
||||
<item><pubDate>1995-12-12T05:45:00Z</pubDate><geo:lat>22.14416389</geo:lat><geo:long>20.15091944</geo:long></item>
|
||||
<item><pubDate>1995-12-12T05:50:00Z</pubDate><geo:lat>22.13757778</geo:lat><geo:long>20.13483333</geo:long></item>
|
||||
<item><pubDate>1995-12-12T05:55:00Z</pubDate><geo:lat>22.12541667</geo:lat><geo:long>20.134125</geo:long></item>
|
||||
<item><pubDate>1995-12-12T06:00:00Z</pubDate><geo:lat>22.11250556</geo:lat><geo:long>20.13402778</geo:long></item>
|
||||
<item><pubDate>1995-12-12T06:05:00Z</pubDate><geo:lat>22.09960278</geo:lat><geo:long>20.13395</geo:long></item>
|
||||
<item><pubDate>1995-12-12T06:10:00Z</pubDate><geo:lat>22.08812222</geo:lat><geo:long>20.14054722</geo:long><title>Comment</title><description></description></item>
|
||||
<item><pubDate>1995-12-12T06:13:00Z</pubDate><geo:lat>22.08141389</geo:lat><geo:long>20.14618333</geo:long><title>Course Change</title><description>220 degs 4kts</description></item>
|
||||
<item><pubDate>1995-12-12T06:15:00Z</pubDate><geo:lat>22.07695278</geo:lat><geo:long>20.14992778</geo:long></item>
|
||||
<item><pubDate>1995-12-12T06:20:00Z</pubDate><geo:lat>22.06584167</geo:lat><geo:long>20.15931111</geo:long></item>
|
||||
<item><pubDate>1995-12-12T06:25:00Z</pubDate><geo:lat>22.05460278</geo:lat><geo:long>20.16871944</geo:long></item>
|
||||
<item><pubDate>1995-12-12T06:30:00Z</pubDate><geo:lat>22.04315833</geo:lat><geo:long>20.16791667</geo:long></item>
|
||||
<item><pubDate>1995-12-12T06:35:00Z</pubDate><geo:lat>22.03118611</geo:lat><geo:long>20.16143056</geo:long></item>
|
||||
<item><pubDate>1995-12-12T06:40:00Z</pubDate><geo:lat>22.01912222</geo:lat><geo:long>20.15486389</geo:long></item>
|
||||
<item><pubDate>1995-12-12T06:45:00Z</pubDate><geo:lat>22.00708333</geo:lat><geo:long>20.14833056</geo:long></item>
|
||||
<item><pubDate>1995-12-12T06:50:00Z</pubDate><geo:lat>21.99504444</geo:lat><geo:long>20.14181111</geo:long></item>
|
||||
<item><pubDate>1995-12-12T06:55:00Z</pubDate><geo:lat>21.98423889</geo:lat><geo:long>20.14733611</geo:long></item>
|
||||
<item><pubDate>1995-12-12T07:00:00Z</pubDate><geo:lat>21.97367222</geo:lat><geo:long>20.15803333</geo:long></item>
|
||||
<item><pubDate>1995-12-12T07:05:00Z</pubDate><geo:lat>21.96306111</geo:lat><geo:long>20.16874444</geo:long></item>
|
||||
<item><pubDate>1995-12-12T07:10:00Z</pubDate><geo:lat>21.95407222</geo:lat><geo:long>20.17233611</geo:long></item>
|
||||
<item><pubDate>1995-12-12T07:15:00Z</pubDate><geo:lat>21.95885556</geo:lat><geo:long>20.15766944</geo:long></item>
|
||||
<item><pubDate>1995-12-12T07:20:00Z</pubDate><geo:lat>21.96630833</geo:lat><geo:long>20.16956944</geo:long></item>
|
||||
<item><pubDate>1995-12-12T07:25:00Z</pubDate><geo:lat>21.97450556</geo:lat><geo:long>20.18388056</geo:long></item>
|
||||
<item><pubDate>1995-12-12T07:30:00Z</pubDate><geo:lat>21.98276389</geo:lat><geo:long>20.19838333</geo:long></item>
|
||||
<item><pubDate>1995-12-12T07:32:00Z</pubDate><geo:lat>21.98605278</geo:lat><geo:long>20.20413056</geo:long><title>Comment</title><description>Suspect opponent to North, slowing down</description></item>
|
||||
<item><pubDate>1995-12-12T07:33:00Z</pubDate><geo:lat>21.98691667</geo:lat><geo:long>20.20727778</geo:long><title>Comment</title><description>VIP visitors due. Helo retrieved.</description></item>
|
||||
<item><pubDate>1995-12-12T07:34:00Z</pubDate><geo:lat>21.98566944</geo:lat><geo:long>20.20985556</geo:long><title>Comment</title><description>Wind picked up. Switching off sensor Delta</description></item>
|
||||
<item><pubDate>1995-12-12T07:35:00Z</pubDate><geo:lat>21.9842</geo:lat><geo:long>20.21243611</geo:long><title>Comment</title><description>Heavenly dusk</description></item>
|
||||
<item><pubDate>1995-12-12T07:40:00Z</pubDate><geo:lat>21.97609444</geo:lat><geo:long>20.226425</geo:long></item>
|
||||
<item><pubDate>1995-12-12T07:45:00Z</pubDate><geo:lat>21.96786111</geo:lat><geo:long>20.240725</geo:long></item>
|
||||
<item><pubDate>1995-12-12T07:50:00Z</pubDate><geo:lat>21.9595</geo:lat><geo:long>20.25507778</geo:long></item>
|
||||
<item><pubDate>1995-12-12T07:55:00Z</pubDate><geo:lat>21.95118056</geo:lat><geo:long>20.26941389</geo:long></item>
|
||||
<item><pubDate>1995-12-12T08:00:00Z</pubDate><geo:lat>21.94862778</geo:lat><geo:long>20.28483056</geo:long></item>
|
||||
<item><pubDate>1995-12-12T08:05:00Z</pubDate><geo:lat>21.95295</geo:lat><geo:long>20.30239444</geo:long></item>
|
||||
<item><pubDate>1995-12-12T08:10:00Z</pubDate><geo:lat>21.957325</geo:lat><geo:long>20.32020278</geo:long></item>
|
||||
<item><pubDate>1995-12-12T08:15:00Z</pubDate><geo:lat>21.96172222</geo:lat><geo:long>20.33795278</geo:long></item>
|
||||
<item><pubDate>1995-12-12T08:20:00Z</pubDate><geo:lat>21.96616111</geo:lat><geo:long>20.35568611</geo:long></item>
|
||||
<item><pubDate>1995-12-12T08:25:00Z</pubDate><geo:lat>21.96355556</geo:lat><geo:long>20.371925</geo:long></item>
|
||||
<item><pubDate>1995-12-12T08:30:00Z</pubDate><geo:lat>21.95877778</geo:lat><geo:long>20.38858333</geo:long></item>
|
||||
<item><pubDate>1995-12-12T08:35:00Z</pubDate><geo:lat>21.95988889</geo:lat><geo:long>20.40708333</geo:long></item>
|
||||
<item><pubDate>1995-12-12T08:40:00Z</pubDate><geo:lat>21.96361944</geo:lat><geo:long>20.41884722</geo:long></item>
|
||||
<item><pubDate>1995-12-12T08:45:00Z</pubDate><geo:lat>21.96945556</geo:lat><geo:long>20.40425278</geo:long><title>Course Change</title><description>220 degs 4kts</description></item>
|
||||
<item><pubDate>1995-12-12T08:50:00Z</pubDate><geo:lat>21.9759</geo:lat><geo:long>20.38807778</geo:long></item>
|
||||
<item><pubDate>1995-12-12T08:55:00Z</pubDate><geo:lat>21.98237222</geo:lat><geo:long>20.37183889</geo:long></item>
|
||||
<item><pubDate>1995-12-12T09:00:00Z</pubDate><geo:lat>21.98880278</geo:lat><geo:long>20.35546667</geo:long></item>
|
||||
<item><pubDate>1995-12-12T09:05:00Z</pubDate><geo:lat>21.99968611</geo:lat><geo:long>20.34794722</geo:long></item>
|
||||
<item><pubDate>1995-12-12T09:10:00Z</pubDate><geo:lat>22.01179167</geo:lat><geo:long>20.34156389</geo:long></item>
|
||||
<item><pubDate>1995-12-12T09:15:00Z</pubDate><geo:lat>22.02168611</geo:lat><geo:long>20.34614444</geo:long></item>
|
||||
<item><pubDate>1995-12-12T09:20:00Z</pubDate><geo:lat>22.02811111</geo:lat><geo:long>20.36220833</geo:long></item>
|
||||
<item><pubDate>1995-12-12T09:25:00Z</pubDate><geo:lat>22.03456111</geo:lat><geo:long>20.37856389</geo:long><title>Phase Change</title><description>End Phase A</description></item>
|
||||
<item><pubDate>1995-12-12T09:30:00Z</pubDate><geo:lat>22.04145</geo:lat><geo:long>20.36952222</geo:long></item>
|
||||
<item><pubDate>1995-12-12T09:35:00Z</pubDate><geo:lat>22.04782222</geo:lat><geo:long>20.35348611</geo:long></item>
|
||||
<item><pubDate>1995-12-12T09:40:00Z</pubDate><geo:lat>22.05426389</geo:lat><geo:long>20.33713056</geo:long></item>
|
||||
<item><pubDate>1995-12-12T09:45:00Z</pubDate><geo:lat>22.06069444</geo:lat><geo:long>20.32085</geo:long></item>
|
||||
<item><pubDate>1995-12-12T09:46:00Z</pubDate><geo:lat>22.06198611</geo:lat><geo:long>20.31761111</geo:long><title>Phase Change</title><description>Start Phase B</description></item>
|
||||
<item><pubDate>1995-12-12T09:50:00Z</pubDate><geo:lat>22.06471944</geo:lat><geo:long>20.30389444</geo:long></item>
|
||||
<item><pubDate>1995-12-12T09:55:00Z</pubDate><geo:lat>22.07586667</geo:lat><geo:long>20.29758333</geo:long></item>
|
||||
<item><pubDate>1995-12-12T10:00:00Z</pubDate><geo:lat>22.08793889</geo:lat><geo:long>20.29113889</geo:long></item>
|
||||
<item><pubDate>1995-12-12T10:05:00Z</pubDate><geo:lat>22.10003333</geo:lat><geo:long>20.2848</geo:long></item>
|
||||
<item><pubDate>1995-12-12T10:10:00Z</pubDate><geo:lat>22.11219722</geo:lat><geo:long>20.27842222</geo:long></item>
|
||||
<item><pubDate>1995-12-12T10:15:00Z</pubDate><geo:lat>22.11530556</geo:lat><geo:long>20.26194167</geo:long></item>
|
||||
<item><pubDate>1995-12-12T10:20:00Z</pubDate><geo:lat>22.11756944</geo:lat><geo:long>20.24336667</geo:long></item>
|
||||
<item><pubDate>1995-12-12T10:25:00Z</pubDate><geo:lat>22.11986111</geo:lat><geo:long>20.22466944</geo:long></item>
|
||||
<item><pubDate>1995-12-12T10:30:00Z</pubDate><geo:lat>22.12238333</geo:lat><geo:long>20.20620833</geo:long></item>
|
||||
<item><pubDate>1995-12-12T10:35:00Z</pubDate><geo:lat>22.12890278</geo:lat><geo:long>20.216475</geo:long></item>
|
||||
<item><pubDate>1995-12-12T10:40:00Z</pubDate><geo:lat>22.12351944</geo:lat><geo:long>20.22643333</geo:long></item>
|
||||
<item><pubDate>1995-12-12T10:45:00Z</pubDate><geo:lat>22.12099722</geo:lat><geo:long>20.23426667</geo:long></item>
|
||||
<item><pubDate>1995-12-12T10:50:00Z</pubDate><geo:lat>22.12194167</geo:lat><geo:long>20.23018333</geo:long></item>
|
||||
<item><pubDate>1995-12-12T10:55:00Z</pubDate><geo:lat>22.11872778</geo:lat><geo:long>20.23548056</geo:long></item>
|
||||
<item><pubDate>1995-12-12T11:00:00Z</pubDate><geo:lat>22.11994167</geo:lat><geo:long>20.23541111</geo:long></item>
|
||||
<item><pubDate>1995-12-12T11:05:00Z</pubDate><geo:lat>22.11992778</geo:lat><geo:long>20.23948056</geo:long></item>
|
||||
<item><pubDate>1995-12-12T11:10:00Z</pubDate><geo:lat>22.11802222</geo:lat><geo:long>20.24473889</geo:long></item>
|
||||
<item><pubDate>1995-12-12T11:15:00Z</pubDate><geo:lat>22.11764444</geo:lat><geo:long>20.24835278</geo:long></item>
|
||||
<item><pubDate>1995-12-12T11:20:00Z</pubDate><geo:lat>22.12215556</geo:lat><geo:long>20.24788889</geo:long></item>
|
||||
<item><pubDate>1995-12-12T11:25:00Z</pubDate><geo:lat>22.11725278</geo:lat><geo:long>20.25047778</geo:long></item>
|
||||
<item><pubDate>1995-12-12T11:30:00Z</pubDate><geo:lat>22.12259722</geo:lat><geo:long>20.24290278</geo:long></item>
|
||||
<item><pubDate>1995-12-12T11:35:00Z</pubDate><geo:lat>22.12921944</geo:lat><geo:long>20.24653889</geo:long></item>
|
||||
<item><pubDate>1995-12-12T11:40:00Z</pubDate><geo:lat>22.13970833</geo:lat><geo:long>20.25221389</geo:long></item>
|
||||
<item><pubDate>1995-12-12T11:41:00Z</pubDate><geo:lat>22.14173889</geo:lat><geo:long>20.25330556</geo:long><title>Phase Change</title><description>End Phase B</description></item>
|
||||
</channel>
|
||||
</rss>
|
||||
|
||||
@@ -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",
|
||||
|
||||
99
lib/OpenLayers/Layer/PointTrack.js
Normal file
99
lib/OpenLayers/Layer/PointTrack.js
Normal file
@@ -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.Vector>
|
||||
*/
|
||||
OpenLayers.Layer.PointTrack = OpenLayers.Class(OpenLayers.Layer.Vector, {
|
||||
|
||||
/**
|
||||
* APIProperty:
|
||||
* dataFrom - {<OpenLayers.Layer.PointTrack.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(<OpenLayers.Feature>)}
|
||||
*
|
||||
*/
|
||||
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};
|
||||
|
||||
79
tests/Layer/test_PointTrack.html
Normal file
79
tests/Layer/test_PointTrack.html
Normal file
@@ -0,0 +1,79 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var name = "PointTrack Layer";
|
||||
|
||||
function test_01_Layer_PointTrack_constructor(t) {
|
||||
t.plan(2);
|
||||
|
||||
var layer = new OpenLayers.Layer.PointTrack(name);
|
||||
t.ok(layer instanceof OpenLayers.Layer.PointTrack, "new OpenLayers.Layer.PointTrack returns correct object" );
|
||||
t.ok(layer.addNodes, "layer has an addNodes method");
|
||||
|
||||
}
|
||||
|
||||
function test_02_Layer_PointTrack_addNodes(t) {
|
||||
t.plan(11);
|
||||
|
||||
var layer = new OpenLayers.Layer.PointTrack(name,
|
||||
{dataFrom: OpenLayers.Layer.PointTrack.dataFrom.TARGET_NODE});
|
||||
|
||||
var point1 = new OpenLayers.Geometry.Point(-111.04, 45.68);
|
||||
var sourceNode = new OpenLayers.Feature.Vector(point1);
|
||||
var point2 = new OpenLayers.Geometry.Point(-112.34, 45.67);
|
||||
var targetNode = new OpenLayers.Feature.Vector(point2, {foo: "bar"});
|
||||
layer.addNodes([sourceNode, targetNode]);
|
||||
|
||||
t.eq(layer.features.length, 1, "OpenLayers.Layer.PointTrack.addNodes creates one feature from two vector point features");
|
||||
t.eq(layer.features[0].geometry.CLASS_NAME, "OpenLayers.Geometry.LineString", "The created feature has a LineString geometry");
|
||||
var geometry = layer.features[0].geometry;
|
||||
t.eq(geometry.components[0].x, -111.04, "The x of the first point of the line equals the x of the first point added to the layer");
|
||||
t.eq(geometry.components[1].y, 45.67, "The y of the second point of the line equals the y of the second point added to the layer");
|
||||
t.eq(layer.features[0].attributes.foo, "bar", "OpenLayers.Layer.PointTrack.addNodes assigns the attributes of the target node correctly");
|
||||
|
||||
layer.dataFrom = OpenLayers.Layer.PointTrack.dataFrom.SOURCE_NODE;
|
||||
|
||||
point1 = new OpenLayers.Geometry.Point(-123.54, 45.67);
|
||||
sourceNode = new OpenLayers.Feature.Vector(point1, {foo: "bar"});
|
||||
point2 = new OpenLayers.Geometry.Point(-123.21, 45.32);
|
||||
targetNode = new OpenLayers.Feature.Vector(point2);
|
||||
layer.addNodes([sourceNode, targetNode]);
|
||||
|
||||
t.eq(layer.features.length, 2, "added another two points, so the layer now has two features");
|
||||
t.eq(layer.features[1].attributes.foo, "bar", "OpenLayers.Layer.PointTrack.addNodes assigns the attributes of the source node correctly");
|
||||
|
||||
point1 = new OpenLayers.LonLat(-123.58, 45.69);
|
||||
sourceNode = new OpenLayers.Feature(null, point1);
|
||||
point2 = new OpenLayers.LonLat(-123.25, 45.37);
|
||||
targetNode = new OpenLayers.Feature(null, point2);
|
||||
sourceNode.data = {foo: "bar"};
|
||||
layer.addNodes([sourceNode, targetNode]);
|
||||
|
||||
t.eq(layer.features.length, 3, "added another two points, this time from features, so the layer now has two features");
|
||||
t.eq(layer.features[2].geometry.components[0].x, -123.58, "The x of the first point of the line equals the x of the first point added to the layer");
|
||||
t.eq(layer.features[2].geometry.components[1].y, 45.37, "The y of the second point of the line equals the x of the second point added to the layer");
|
||||
t.eq(layer.features[2].data, sourceNode.data, "OpenLayers.Layer.PointTrack.addNodes assigns the data of the source node correctly");
|
||||
|
||||
}
|
||||
|
||||
function test_99_Layer_PointTrack_destroy (t) {
|
||||
t.plan(3);
|
||||
layer = new OpenLayers.Layer.PointTrack(name);
|
||||
var map = new OpenLayers.Map('map');
|
||||
map.addLayer(layer);
|
||||
t.eq(layer.map.layers.length, 1, "layer added to the map successfully");
|
||||
layer.destroy();
|
||||
t.eq(layer.map, null, "layer.map is null after destroy");
|
||||
t.eq(layer.getFeatureFromEvent({'target':'map'}), null, "getFeatureIdFromEvent doesn't cause an error when called on layer which has been destroyed.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" style="width:500px;height:550px"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -57,6 +57,7 @@
|
||||
<li>Layer/test_MapServer.html</li>
|
||||
<li>Layer/test_Markers.html</li>
|
||||
<li>Layer/test_MultiMap.html</li>
|
||||
<li>Layer/test_PointTrack.html</li>
|
||||
<li>Layer/test_SphericalMercator.html</li>
|
||||
<li>Layer/test_Text.html</li>
|
||||
<li>Layer/test_TileCache.html</li>
|
||||
|
||||
Reference in New Issue
Block a user