From 9ea3c2f12110d8b3b5f3d563b1e29fe5e0011f22 Mon Sep 17 00:00:00 2001 From: Peter Robins Date: Mon, 14 May 2012 08:49:48 +0100 Subject: [PATCH 1/6] Fix GPX write Point transform --- lib/OpenLayers/Format/GPX.js | 12 ++++++------ notes/2.12.md | 2 ++ tests/Format/GPX.html | 32 +++++++++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/lib/OpenLayers/Format/GPX.js b/lib/OpenLayers/Format/GPX.js index 16b979fd1b..c8d447899d 100644 --- a/lib/OpenLayers/Format/GPX.js +++ b/lib/OpenLayers/Format/GPX.js @@ -280,7 +280,8 @@ OpenLayers.Format.GPX = OpenLayers.Class(OpenLayers.Format.XML, { this.externalProjection); } if (geometry.CLASS_NAME == "OpenLayers.Geometry.Point") { - var wpt = this.buildWptNode(feature); + var wpt = this.buildWptNode(geometry); + this.appendAttributesNode(wpt, feature); return wpt; } else { var trkNode = this.createElementNSPlus("gpx:trk"); @@ -348,16 +349,15 @@ OpenLayers.Format.GPX = OpenLayers.Class(OpenLayers.Format.XML, { * Builds a wpt node given a point * * Parameters: - * feature - {} + * geometry - {} * * Returns: * {DOMElement} A wpt node */ - buildWptNode: function(feature) { + buildWptNode: function(geometry) { var node = this.createElementNSPlus("gpx:wpt"); - node.setAttribute("lon", feature.geometry.x); - node.setAttribute("lat", feature.geometry.y); - this.appendAttributesNode(node, feature); + node.setAttribute("lon", geometry.x); + node.setAttribute("lat", geometry.y); return node; }, diff --git a/notes/2.12.md b/notes/2.12.md index 0ffca1769f..6a6bdb8fee 100644 --- a/notes/2.12.md +++ b/notes/2.12.md @@ -152,6 +152,8 @@ Corresponding issues/pull requests: The `gpxns` API property has been removed. The GPX namespace is now defined in the `namespaces` property but is not intended to be overriden. +GPX also now has a basic write function. + Corresponding issues/pull requests: * https://github.com/openlayers/openlayers/pull/221 diff --git a/tests/Format/GPX.html b/tests/Format/GPX.html index 0b0f1d2aca..65e6677685 100644 --- a/tests/Format/GPX.html +++ b/tests/Format/GPX.html @@ -19,13 +19,21 @@ "default external projection is EPSG:4326"); } function test_Format_GPX_read(t) { - t.plan(4); + t.plan(7); var f = new OpenLayers.Format.GPX(); var features = f.read(gpx_data); t.eq(features.length, 3, "Number of features read is correct"); t.eq(features[2].geometry.toString(), "POINT(-0.1853562259 51.3697845627)", "waypoint feature correctly created"); t.eq(features[0].geometry.toString(), "LINESTRING(-0.1721292044 51.3768216433,-0.1649230916 51.370833767,-0.1736741378 51.3644368725,-0.166259525 51.3576354272)", "track feature correctly created"); t.eq(features[1].geometry.toString(), "LINESTRING(-0.1829991904 51.3761803674,-0.1758887005 51.3697894659,-0.1833202965 51.3639790884,-0.1751119509 51.3567607069)", "route feature correctly created"); + + f.internalProjection = new OpenLayers.Projection("EPSG:3857"); + features = f.read(gpx_data); + t.eq(features[2].geometry.toString(), "POINT(-20633.760679678744 6686966.841929403)", "transformed waypoint feature correctly created"); + features[0].geometry.components.pop();//hack to suppress rounding errors + t.eq(features[0].geometry.toString(), "LINESTRING(-19161.33538179203 6688221.743275255,-18359.1545744088 6687153.931130851,-19333.316581165607 6686013.33343931)", "transformed track feature correctly created"); + features[1].geometry.components.pop();//hack to suppress rounding errors + t.eq(features[1].geometry.toString(), "LINESTRING(-20371.3766880736 6688107.378491073,-19579.84057322507 6686967.716235109,-20407.12205561124 6685931.714395953)", "transformed route feature correctly created"); } function test_format_GPX_read_attributes(t) { t.plan(2); @@ -35,7 +43,7 @@ t.eq(features[2].attributes['sym'], "Flag", "CDATA attribute node read correctly."); } function test_Format_GPX_serialize_points(t) { - t.plan(1); + t.plan(2); var parser = new OpenLayers.Format.GPX(); @@ -47,9 +55,19 @@ ]; var data = parser.write(features); t.xml_eq(data, 'foobarfoobar', 'GPX serializes points correctly'); + + parser.internalProjection = new OpenLayers.Projection("EPSG:3857"); + point = new OpenLayers.Geometry.Point(-12367595.42541111, 5621521.485409545); + point2 = new OpenLayers.Geometry.Point(-12472235.746742222, 5621521.485409545); + features = [ + new OpenLayers.Feature.Vector(point, {name: 'foo', description: 'bar'}), + new OpenLayers.Feature.Vector(point2, {name: 'foo', description: 'bar'}) + ]; + data = parser.write(features); + t.xml_eq(data, 'foobarfoobar', 'GPX serializes transformed points correctly'); } function test_Format_GPX_serialize_line(t) { - t.plan(1); + t.plan(2); var parser = new OpenLayers.Format.GPX(); @@ -59,6 +77,14 @@ var f = new OpenLayers.Feature.Vector(line, {name: 'foo', description: 'bar'}); var data = parser.write(f); t.xml_eq(data, 'foobar', 'GPX serializes line correctly'); + + parser.internalProjection = new OpenLayers.Projection("EPSG:3857"); + point = new OpenLayers.Geometry.Point(-12367595.42541111, 5621521.485409545); + point2 = new OpenLayers.Geometry.Point(-12472235.746742222, 5621521.485409545); + line = new OpenLayers.Geometry.LineString([point, point2]); + f = new OpenLayers.Feature.Vector(line, {name: 'foo', description: 'bar'}); + data = parser.write(f); + t.xml_eq(data, 'foobar', 'GPX serializes transformed line correctly'); } function test_Format_GPX_serialize_lines(t) { t.plan(1); From 05672deefa47b9334acbd286fd9aee678ff0bc91 Mon Sep 17 00:00:00 2001 From: Xavier Mamano Date: Mon, 14 May 2012 23:02:53 +0200 Subject: [PATCH 2/6] Add style = "position: absolute;" on the SVG to skip the bug of Chrome 18 --- lib/OpenLayers/Renderer/SVG.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Renderer/SVG.js b/lib/OpenLayers/Renderer/SVG.js index e65da76a9a..ecaac9e27f 100644 --- a/lib/OpenLayers/Renderer/SVG.js +++ b/lib/OpenLayers/Renderer/SVG.js @@ -446,7 +446,9 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, { * {DOMElement} The specific render engine's root element */ createRenderRoot: function() { - return this.nodeFactory(this.container.id + "_svgRoot", "svg"); + var svg = this.nodeFactory(this.container.id + "_svgRoot", "svg"); + svg.style.position = "absolute"; + return svg; }, /** From 114541d0b714767b560e8de34cfd1057ccfeb372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Tue, 15 May 2012 08:58:23 +0200 Subject: [PATCH 3/6] use t.geom_eq in GPX tests --- tests/Format/GPX.html | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/tests/Format/GPX.html b/tests/Format/GPX.html index 65e6677685..ee08de9556 100644 --- a/tests/Format/GPX.html +++ b/tests/Format/GPX.html @@ -20,20 +20,47 @@ } function test_Format_GPX_read(t) { t.plan(7); + var expected, + P = OpenLayers.Geometry.Point, + LS = OpenLayers.Geometry.LineString; var f = new OpenLayers.Format.GPX(); var features = f.read(gpx_data); t.eq(features.length, 3, "Number of features read is correct"); - t.eq(features[2].geometry.toString(), "POINT(-0.1853562259 51.3697845627)", "waypoint feature correctly created"); - t.eq(features[0].geometry.toString(), "LINESTRING(-0.1721292044 51.3768216433,-0.1649230916 51.370833767,-0.1736741378 51.3644368725,-0.166259525 51.3576354272)", "track feature correctly created"); - t.eq(features[1].geometry.toString(), "LINESTRING(-0.1829991904 51.3761803674,-0.1758887005 51.3697894659,-0.1833202965 51.3639790884,-0.1751119509 51.3567607069)", "route feature correctly created"); + expected = new P(-0.1853562259, 51.3697845627); + t.geom_eq(features[2].geometry, expected, "waypoint feature correctly created"); + expected = new LS([ + new P(-0.1721292044, 51.3768216433), + new P(-0.1649230916, 51.370833767), + new P(-0.1736741378, 51.3644368725), + new P(-0.166259525, 51.3576354272) + ]); + t.geom_eq(features[0].geometry, expected, "track feature correctly created"); + expected = new LS([ + new P(-0.1829991904, 51.3761803674), + new P(-0.1758887005, 51.3697894659), + new P(-0.1833202965, 51.3639790884), + new P(-0.1751119509, 51.3567607069) + ]); + t.geom_eq(features[1].geometry, expected, "route feature correctly created"); f.internalProjection = new OpenLayers.Projection("EPSG:3857"); features = f.read(gpx_data); - t.eq(features[2].geometry.toString(), "POINT(-20633.760679678744 6686966.841929403)", "transformed waypoint feature correctly created"); - features[0].geometry.components.pop();//hack to suppress rounding errors - t.eq(features[0].geometry.toString(), "LINESTRING(-19161.33538179203 6688221.743275255,-18359.1545744088 6687153.931130851,-19333.316581165607 6686013.33343931)", "transformed track feature correctly created"); - features[1].geometry.components.pop();//hack to suppress rounding errors - t.eq(features[1].geometry.toString(), "LINESTRING(-20371.3766880736 6688107.378491073,-19579.84057322507 6686967.716235109,-20407.12205561124 6685931.714395953)", "transformed route feature correctly created"); + expected = new P(-20633.760679678744, 6686966.841929403); + t.geom_eq(features[2].geometry, expected, "transformed waypoint feature correctly created"); + expected = new LS([ + new P(-19161.33538179203, 6688221.743275255), + new P(-18359.1545744088, 6687153.931130851), + new P(-19333.316581165607, 6686013.33343931), + new P(-18507.925659955214, 6684800.777090962) + ]); + t.geom_eq(features[0].geometry, expected, "transformed track feature correctly created"); + expected = new LS([ + new P(-20371.3766880736, 6688107.378491073), + new P(-19579.84057322507, 6686967.716235109), + new P(-20407.12205561124, 6685931.714395953), + new P(-19493.373203291227, 6684644.845706556) + ]); + t.geom_eq(features[1].geometry, expected, "transformed route feature correctly created"); } function test_format_GPX_read_attributes(t) { t.plan(2); From bca3e4594041034790b1ed2d22b0072809af6b02 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Tue, 15 May 2012 12:18:42 +0200 Subject: [PATCH 4/6] BBOX strategy should not request data if its layer is out of range when changing layer visibility --- lib/OpenLayers/Strategy/BBOX.js | 4 ++-- tests/Strategy/BBOX.html | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/Strategy/BBOX.js b/lib/OpenLayers/Strategy/BBOX.js index 154a8ae6b2..a476b90cb8 100644 --- a/lib/OpenLayers/Strategy/BBOX.js +++ b/lib/OpenLayers/Strategy/BBOX.js @@ -87,7 +87,7 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, { "refresh": this.update, scope: this }); - if(this.layer.visibility === true && this.layer.inRange === true) { + if(this.layer.visibility === true) { this.update(); } else { this.layer.events.on({ @@ -134,7 +134,7 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, { update: function(options) { var mapBounds = this.getMapBounds(); if (mapBounds !== null && ((options && options.force) || - this.invalidBounds(mapBounds))) { + (this.layer.calculateInRange() && this.invalidBounds(mapBounds)))) { this.calculateBounds(mapBounds); this.resolution = this.layer.map.getResolution(); this.triggerRead(options); diff --git a/tests/Strategy/BBOX.html b/tests/Strategy/BBOX.html index 84c0ad02ee..4194b59175 100644 --- a/tests/Strategy/BBOX.html +++ b/tests/Strategy/BBOX.html @@ -305,7 +305,7 @@ // Test fix for Ticket #3142 function test_layerLoadedAfterBeingAdded(t) { - t.plan(2); + t.plan(3); var dummy = new OpenLayers.Layer(null, {isBaseLayer: true}); @@ -341,6 +341,11 @@ // test that the strategy bounds were set t.ok(map.getExtent().equals(strategy.bounds), "[set center] bounds set to map extent"); t.eq(layerOutOfRange.strategies[0].bounds, null, "Data not requested if layer is out of range"); + + layerOutOfRange.setVisibility(false); + layerOutOfRange.setVisibility(true); + t.eq(layerOutOfRange.strategies[0].bounds, null, "Data not requested if layer is out of range when switching visibility"); + map.destroy(); } From 44f9b8108545cc10585fc112c67b80dc8db3a559 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Tue, 15 May 2012 12:26:21 +0200 Subject: [PATCH 5/6] also check for visibility of the layer in the central place: the update function --- lib/OpenLayers/Strategy/BBOX.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/OpenLayers/Strategy/BBOX.js b/lib/OpenLayers/Strategy/BBOX.js index a476b90cb8..6df04b1a03 100644 --- a/lib/OpenLayers/Strategy/BBOX.js +++ b/lib/OpenLayers/Strategy/BBOX.js @@ -81,20 +81,11 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, { if(activated) { this.layer.events.on({ "moveend": this.update, - scope: this - }); - this.layer.events.on({ "refresh": this.update, + "visibilitychanged": this.update, scope: this }); - if(this.layer.visibility === true) { - this.update(); - } else { - this.layer.events.on({ - "visibilitychanged": this.update, - scope: this - }); - } + this.update(); } return activated; }, @@ -134,7 +125,7 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, { update: function(options) { var mapBounds = this.getMapBounds(); if (mapBounds !== null && ((options && options.force) || - (this.layer.calculateInRange() && this.invalidBounds(mapBounds)))) { + (this.layer.visibility && this.layer.calculateInRange() && this.invalidBounds(mapBounds)))) { this.calculateBounds(mapBounds); this.resolution = this.layer.map.getResolution(); this.triggerRead(options); From 62bd06f46580aa4d512ee424bce5cb06b27b611f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Wed, 16 May 2012 08:24:55 +0200 Subject: [PATCH 6/6] use Util.indexOf in Layer.Bing, for compatibility with IE < 9 --- lib/OpenLayers/Layer/Bing.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Layer/Bing.js b/lib/OpenLayers/Layer/Bing.js index 9a477f6c0b..51c2b9d045 100644 --- a/lib/OpenLayers/Layer/Bing.js +++ b/lib/OpenLayers/Layer/Bing.js @@ -224,7 +224,8 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, { new OpenLayers.Projection("EPSG:4326") ); var providers = res.imageryProviders, - zoom = this.serverResolutions.indexOf(this.getServerResolution()), + zoom = OpenLayers.Util.indexOf(this.serverResolutions, + this.getServerResolution()), copyrights = "", provider, i, ii, j, jj, bbox, coverage; for (i=0,ii=providers.length; i