From 4df1104b7ab73063d57bad7be0c9a06895e2019e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Sat, 7 Apr 2012 21:01:52 +0200 Subject: [PATCH 01/49] Revert "Merge pull request #312 from elemoine/redraw" This reverts commit 7f94945244a83494e88eaa9bcd6e83387fa9864f, reversing changes made to dfa70fafac8c1ce380d918511e7cd8089138fe64. Conflicts: lib/OpenLayers/Layer/Vector.js --- lib/OpenLayers/Layer/Vector.js | 14 -------------- tests/Layer/Vector.html | 25 ------------------------- 2 files changed, 39 deletions(-) diff --git a/lib/OpenLayers/Layer/Vector.js b/lib/OpenLayers/Layer/Vector.js index 4a62f53454..ed2271a89a 100644 --- a/lib/OpenLayers/Layer/Vector.js +++ b/lib/OpenLayers/Layer/Vector.js @@ -520,20 +520,6 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { } }, - /** - * APIMethod: redraw - * Redraws the layer. Returns true if the layer was redrawn, false if not. - * - * Returns: - * {Boolean} The layer was redrawn. - */ - redraw: function() { - // this is to force Layer.redraw set zoomChanged - // to true in the moveTo call - this.resolution = null; - return OpenLayers.Layer.prototype.redraw.apply(this, arguments); - }, - /** * APIMethod: display * Hide or show the Layer diff --git a/tests/Layer/Vector.html b/tests/Layer/Vector.html index 160f2314d7..aa3e2f8a7e 100644 --- a/tests/Layer/Vector.html +++ b/tests/Layer/Vector.html @@ -869,32 +869,7 @@ "featuresadded event received expected number of features"); } - function test_redraw(t) { - t.plan(2); - // test that when redraw is called on a vector layer then - // moveTo gets called on the layer and receives zoomChanged - // true - - var log = []; - - var map = new OpenLayers.Map("map"); - var layer = new OpenLayers.Layer.Vector("vector", {isBaseLayer: true}); - map.addLayer(layer); - map.setCenter([0, 0], 5); - - layer.moveTo = function(extent, zoomChanged) { - log.push(zoomChanged); - }; - - layer.redraw(); - t.eq(log.length, 1, "redraw makes moveTo be called once"); - if (log.length == 1) { - t.eq(log[0], true, "redraw makes moveTo be called with zoomChanged true"); - } - - map.destroy(); - } From 58e86a37f57ec896fd0a2632215a389819992e84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Sat, 7 Apr 2012 21:02:24 +0200 Subject: [PATCH 02/49] Revert "Declare zoomChanged." This reverts commit b910a5f4d0c98b142e85b810f734d21b975af454. --- lib/OpenLayers/Layer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index 05747f2cbf..762f00c1e3 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -561,7 +561,7 @@ OpenLayers.Layer = OpenLayers.Class({ var extent = this.getExtent(); if (extent && this.inRange && this.visibility) { - var zoomChanged = this.resolution == null || + zoomChanged = this.resolution == null || this.resolution !== this.map.getResolution(); this.moveTo(extent, zoomChanged, false); this.events.triggerEvent("moveend", From ae75fdacd7624dcc1ffc817cf2d50f12cdac166d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Sat, 7 Apr 2012 21:07:03 +0200 Subject: [PATCH 03/49] Revert "Merge pull request #116 from elemoine/redraw" This reverts commit 7a5b4691922f7b427d4abd3a6a47193966492864, reversing changes made to a719de7e9394640ea8a48c27bd441cc3fb2761e7. Conflicts: tests/Tile/Image.html --- lib/OpenLayers/Layer.js | 16 +------ lib/OpenLayers/Layer/HTTPRequest.js | 3 +- tests/Layer.html | 69 ++--------------------------- tests/Layer/HTTPRequest.html | 6 +-- tests/Tile/Image.html | 49 +------------------- 5 files changed, 8 insertions(+), 135 deletions(-) diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index 762f00c1e3..eb3640fe21 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -275,16 +275,6 @@ OpenLayers.Layer = OpenLayers.Class({ * {Float} */ minResolution: null, - - /** - * Property: resolution - * {Float} Current resolution that the layer is drawn in. This is - * used to determine whether the zoom has changed when calling - * from . Subclasses may set this.resolution to - * null prior to calling redraw to force passing zoomChanged - * true to moveTo. - */ - resolution: null, /** * APIProperty: numZoomLevels @@ -561,8 +551,7 @@ OpenLayers.Layer = OpenLayers.Class({ var extent = this.getExtent(); if (extent && this.inRange && this.visibility) { - zoomChanged = this.resolution == null || - this.resolution !== this.map.getResolution(); + var zoomChanged = true; this.moveTo(extent, zoomChanged, false); this.events.triggerEvent("moveend", {"zoomChanged": zoomChanged}); @@ -587,7 +576,6 @@ OpenLayers.Layer = OpenLayers.Class({ display = display && this.inRange; } this.display(display); - this.resolution = this.map.getResolution(); }, /** @@ -643,8 +631,6 @@ OpenLayers.Layer = OpenLayers.Class({ // deal with gutters this.setTileSize(); - - this.resolution = null; } }, diff --git a/lib/OpenLayers/Layer/HTTPRequest.js b/lib/OpenLayers/Layer/HTTPRequest.js index 35b5638491..9483e4997f 100644 --- a/lib/OpenLayers/Layer/HTTPRequest.js +++ b/lib/OpenLayers/Layer/HTTPRequest.js @@ -122,7 +122,6 @@ OpenLayers.Layer.HTTPRequest = OpenLayers.Class(OpenLayers.Layer, { */ mergeNewParams:function(newParams) { this.params = OpenLayers.Util.extend(this.params, newParams); - this.resolution = null; var ret = this.redraw(); if(this.map != null) { this.map.events.triggerEvent("changelayer", { @@ -147,7 +146,7 @@ OpenLayers.Layer.HTTPRequest = OpenLayers.Class(OpenLayers.Layer, { if (force) { return this.mergeNewParams({"_olSalt": Math.random()}); } else { - return OpenLayers.Layer.prototype.redraw.call(this); + return OpenLayers.Layer.prototype.redraw.apply(this, []); } }, diff --git a/tests/Layer.html b/tests/Layer.html index eb2c9270f7..c6ce1f80e1 100644 --- a/tests/Layer.html +++ b/tests/Layer.html @@ -672,82 +672,19 @@ // test that the moveend event was triggered t.ok(log.event, "an event was logged"); t.eq(log.event.type, "moveend", "moveend was triggered"); - t.eq(log.event.zoomChanged, false, "event says zoomChanged false"); + t.eq(log.event.zoomChanged, true, "event says zoomChanged true - poor name"); layer.moveTo = function(bounds, zoomChanged, dragging) { var extent = layer.map.getExtent(); t.ok(bounds.equals(extent), "redraw calls moveTo with the map extent"); - t.ok(!zoomChanged, - "redraw calls moveTo with zoomChanged false"); + t.ok(zoomChanged, + "redraw calls moveTo with zoomChanged true"); t.ok(!dragging, "redraw calls moveTo with dragging false"); } layer.redraw(); } - - // This function includes integration tests to verify that the - // layer's moveTo function is called with the expected value - // for zoomChanged - function test_moveTo_zoomChanged(t) { - t.plan(6); - - var log = {}; - var map = new OpenLayers.Map('map'); - - var l1 = new OpenLayers.Layer('l1', {isBaseLayer: true}); - l1.moveTo = function(bounds, zoomChanged, dragging) { - log.moveTo = {zoomChanged: zoomChanged}; - OpenLayers.Layer.prototype.moveTo.apply(this, arguments); - }; - - map.addLayer(l1); - map.zoomToMaxExtent(); - - log = {}; - l1.redraw(); - t.eq(log.moveTo.zoomChanged, false, - "[a] redraw calls moveTo with zoomChanged false"); - - log = {}; - l1.resolution = null; - l1.redraw(); - t.eq(log.moveTo.zoomChanged, true, - "[b] redraw calls moveTo with zoomChanged true"); - - l1.setVisibility(false); - log = {}; - l1.setVisibility(true); - t.eq(log.moveTo.zoomChanged, false, - "[c] redraw calls moveTo with zoomChanged false"); - - l1.setVisibility(false); - map.zoomIn(); - log = {}; - l1.setVisibility(true); - t.eq(log.moveTo.zoomChanged, true, - "[d] redraw calls moveTo with zoomChanged true"); - - l1.moveTo = OpenLayers.Layer.prototype.moveTo; - - var l2 = new OpenLayers.Layer('l2'); - l2.moveTo = function(bounds, zoomChanged, dragging) { - log.moveTo = {zoomChanged: zoomChanged}; - OpenLayers.Layer.prototype.moveTo.apply(this, arguments); - }; - log = {}; - map.addLayer(l2); - t.eq(log.moveTo.zoomChanged, true, - "[e] redraw calls moveTo with zoomChanged true"); - - map.removeLayer(l2); - log = {}; - map.addLayer(l2); - t.eq(log.moveTo.zoomChanged, true, - "[f] redraw calls moveTo with zoomChanged true"); - - map.destroy(); - } function test_layer_setIsBaseLayer(t) { t.plan(2); diff --git a/tests/Layer/HTTPRequest.html b/tests/Layer/HTTPRequest.html index 6ea34810e5..dcb6e23017 100644 --- a/tests/Layer/HTTPRequest.html +++ b/tests/Layer/HTTPRequest.html @@ -68,7 +68,7 @@ } function test_Layer_HTTPRequest_mergeNewParams (t) { - t.plan( 9 ); + t.plan( 8 ); var map = new OpenLayers.Map('map'); layer = new OpenLayers.Layer.HTTPRequest(name, url, params, options); @@ -100,9 +100,7 @@ layer.redraw = function() { t.ok(true, "layer.mergeNewParams calls layer.redraw"); - t.ok(layer.resolution === null, "layer.mergeNewParams sets resolution to null"); - }; - layer.resolution = 'fake'; + } layer.mergeNewParams(); } diff --git a/tests/Tile/Image.html b/tests/Tile/Image.html index 545a6d2826..6ef426e386 100644 --- a/tests/Tile/Image.html +++ b/tests/Tile/Image.html @@ -374,53 +374,6 @@ map.destroy(); } - // test for https://github.com/openlayers/openlayers/pull/36 - // (more an integration test than a unit test) - function test_olImageLoadError(t) { - t.plan(6); - - var map = new OpenLayers.Map('map'); - var layer = new OpenLayers.Layer.WMS("invalid", "foo", {layers: 'basic'}); - map.addLayer(layer); - - var size = new OpenLayers.Size(5, 6); - var position = new OpenLayers.Pixel(20, 30); - var bounds = new OpenLayers.Bounds(1, 2, 3, 4); - - var tile = new OpenLayers.Tile.Image(layer, position, bounds, null, size); - var log = []; - tile.events.register("loaderror", this, function(e) { - log.push([ - e.object.imgDiv.style.visibility, - OpenLayers.Element.hasClass(e.object.imgDiv, 'olImageLoadError') - ]); - }); - tile.events.register("loadend", this, function(e) { - log.push(e); - }) - tile.draw(); - - t.delay_call(0.1, function() { - - t.eq(log.length, 2, "loaderror and loadend events triggered"); - t.eq(log[0][0], "hidden", "tile still hidden when loaderror is triggered"); - t.eq(log[0][1], true, "tile has olImageLoadError class already when loaderror is triggered"); - t.ok(log[1].object === tile, "loadend event triggered after loaderror"); - - // check initial state - t.ok(OpenLayers.Element.hasClass(tile.imgDiv, 'olImageLoadError'), - 'tile image has the olImageLoadError class (init state)'); - - layer.setVisibility(false); - layer.setVisibility(true); - - t.ok(OpenLayers.Element.hasClass(tile.imgDiv, 'olImageLoadError'), - 'tile image still has the olImageLoadError class'); - - map.destroy(); - }); - } - function test_getCanvasContext(t) { if (!OpenLayers.CANVAS_SUPPORTED) { t.plan(0); @@ -445,7 +398,7 @@ }); } } - + From ebfbb354ed9586f824656a74994c995f53308b74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Wed, 11 Apr 2012 17:43:17 +0200 Subject: [PATCH 04/49] fix the TMS zoomOffset test --- tests/Layer/TMS.html | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/Layer/TMS.html b/tests/Layer/TMS.html index 20bad5dc77..4ac629fe2e 100644 --- a/tests/Layer/TMS.html +++ b/tests/Layer/TMS.html @@ -175,10 +175,9 @@ // test offset of 2 offset = 2; zoom = 3; - + var map = new OpenLayers.Map({ - div: "map", - maxResolution: OpenLayers.Projection.defaults["EPSG:4326"].maxResolution / Math.pow(2, offset) + div: "map" }); var layer = new OpenLayers.Layer.TMS("TMS", "", { layername: "basic", @@ -189,7 +188,6 @@ map.setCenter(new OpenLayers.LonLat(0, 0), zoom); var tileurl = layer.getURL(new OpenLayers.Bounds(3.515625,45,4.21875,45.703125)); - level = parseInt(tileurl.split("/")[2]); t.eq(parseInt(tileurl.split("/")[2]), zoom + offset, "correct level for offset 2"); map.destroy(); @@ -199,8 +197,7 @@ zoom = 3; var map = new OpenLayers.Map({ - div: "map", - maxResolution: OpenLayers.Projection.defaults["EPSG:4326"].maxResolution / Math.pow(2, offset) + div: "map" }); var layer = new OpenLayers.Layer.TMS("TMS", "", { layername: "basic", @@ -211,12 +208,9 @@ map.setCenter(new OpenLayers.LonLat(0, 0), zoom); var tileurl = layer.getURL(new OpenLayers.Bounds(3.515625,45,4.21875,45.703125)); - level = parseInt(tileurl.split("/")[2]); t.eq(parseInt(tileurl.split("/")[2]), zoom + offset, "correct level for offset -1"); map.destroy(); - - } function test_Layer_TMS_setMap(t) { From bfd6be634f5ee624151778c96786ac93dd07397c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Wed, 11 Apr 2012 17:01:35 +0200 Subject: [PATCH 05/49] if maxResolution is "auto" calculate maxResolution based on maxExtent and map size, else calculate maxResolution based on maxExtent and tile size --- lib/OpenLayers/Layer.js | 22 ++++++++++++---------- tests/Layer.html | 7 +++++-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index 05747f2cbf..9ccc9c9f3a 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -884,16 +884,6 @@ OpenLayers.Layer = OpenLayers.Class({ props.resolutions = this.resolutionsFromScales(props.scales); } if(props.resolutions == null) { - var maxExtent = this.maxExtent; - if (!props.maxResolution && maxExtent) { - // maxResolution for default grid sets assumes that at zoom - // level zero, the whole world fits on one tile. - var tileSize = this.tileSize || this.map.getTileSize(); - props.maxResolution = Math.max( - maxExtent.getWidth() / tileSize.w, - maxExtent.getHeight() / tileSize.h - ); - } props.resolutions = this.calculateResolutions(props); } } @@ -1029,6 +1019,18 @@ OpenLayers.Layer = OpenLayers.Class({ minResolution = Math.max(wRes, hRes); } + if(typeof maxResolution !== "number" && + typeof minResolution !== "number" && + this.maxExtent != null) { + // maxResolution for default grid sets assumes that at zoom + // level zero, the whole world fits on one tile. + var tileSize = this.tileSize || this.map.getTileSize(); + maxResolution = Math.max( + this.maxExtent.getWidth() / tileSize.w, + this.maxExtent.getHeight() / tileSize.h + ); + } + // determine numZoomLevels var maxZoomLevel = props.maxZoomLevel; var numZoomLevels = props.numZoomLevels; diff --git a/tests/Layer.html b/tests/Layer.html index eb2c9270f7..1391ac9396 100644 --- a/tests/Layer.html +++ b/tests/Layer.html @@ -398,6 +398,9 @@ "1.20", null, {maxScale: 100000, numZoomLevels: 3, units: "m"}, [141.11103491115225, 70.55551745557612, 35.27775872778806], 35.27775872778806, 141.11103491115225 ], [ + "1.21", null, {numZoomLevels: 2}, // maxResolution calculated based on the projection's maxExtent here + [1.40625, 0.703125], 0.703125, 1.40625 + ], [ /* * Batch 2: custom map options map and sensible layer options @@ -541,8 +544,8 @@ /* * Batch 2.8: numZoomLevels set in the layer options */ - "2.8.0", {maxResolution: 80}, {numZoomLevels: 4}, - [80, 40, 20, 10], 10, 80 + "2.8.0", {maxResolution: 80}, {numZoomLevels: 4}, // maxResolution calculated based on the projection's maxExtent here + [1.40625, 0.703125, 0.3515625, 0.17578125], 0.17578125, 1.40625 ], [ "2.8.1", {maxResolution: 80, numZoomLevels: 4}, {numZoomLevels: null}, [80, 40, 20, 10], 10, 80 From b683c9bae175495e8e71ee290cac87eaa340fa50 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Sat, 14 Apr 2012 18:32:47 +0200 Subject: [PATCH 06/49] No csstidy, because it changes the css and breaks the zoom buttons. --- tools/update_dev_dir.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tools/update_dev_dir.sh b/tools/update_dev_dir.sh index 9c272293fc..1bab6ab513 100755 --- a/tools/update_dev_dir.sh +++ b/tools/update_dev_dir.sh @@ -35,10 +35,6 @@ if [ ! o$GITREV = $OLD_GITREV ]; then cp OpenLayers.*.js .. cd .. - for i in google ie6-style style; do - csstidy theme/default/$i.css --template=highest theme/default/$i.tidy.css - cp theme/default/$i.tidy.css theme/default/$i.css - done sed -i -e 's!../lib/OpenLayers.js?mobile!../OpenLayers.mobile.js!' examples/*.html sed -i -e 's!../lib/OpenLayers.js!../OpenLayers.js!' examples/*.html From e14d7d686e245b68e4dd73f5e91527b86e77ae0f Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 11 Apr 2012 12:40:57 +0200 Subject: [PATCH 07/49] Fix Util.html test for Chrome/Chromium browsers. --- tests/Util.html | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/Util.html b/tests/Util.html index 2357b54e2c..ecb583beb0 100644 --- a/tests/Util.html +++ b/tests/Util.html @@ -507,9 +507,8 @@ t.eq(element.style.opacity, '', "element.style.opacity is removed when opacity = " + opacity); - //Safari 3 returns null for this value, which is okay - var filterString = (OpenLayers.BROWSER_NAME == 'safari') ? null : ''; - t.eq(element.style.filter, filterString, + // Some browser returns null instead of '', which is okay + t.ok(element.style.filter == '' || element.style.filter == null, "element.style.filter is removed when opacity = " + opacity); } From 90a8ac9c71dac42197134ca2ae9d8838723c025b Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Tue, 17 Apr 2012 14:23:56 +0200 Subject: [PATCH 08/49] allow for negative years in dates --- lib/OpenLayers/BaseTypes/Date.js | 2 +- tests/BaseTypes/Date.html | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/BaseTypes/Date.js b/lib/OpenLayers/BaseTypes/Date.js index f42b713e12..7e721fed0c 100644 --- a/lib/OpenLayers/BaseTypes/Date.js +++ b/lib/OpenLayers/BaseTypes/Date.js @@ -91,7 +91,7 @@ OpenLayers.Date = { */ parse: function(str) { var date; - var match = str.match(/^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/); + var match = str.match(/^(?:(-?\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/); if (match && (match[1] || match[7])) { // must have at least year or time var year = parseInt(match[1], 10) || 0; var month = (parseInt(match[2], 10) - 1) || 0; diff --git a/tests/BaseTypes/Date.html b/tests/BaseTypes/Date.html index a433d84f24..af12348772 100644 --- a/tests/BaseTypes/Date.html +++ b/tests/BaseTypes/Date.html @@ -35,7 +35,7 @@ function test_Date_parse(t) { - t.plan(114); + t.plan(121); var cases = { "2000": { @@ -139,6 +139,11 @@ year: 2000, month: 3, date: 15 + }, + "-0501-03-01T00:00:00.000Z": { + year: -501, + month: 2, + date: 1 } }; From f07660e8c503a9782fb028154c8faf374cc99bc2 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Tue, 17 Apr 2012 15:57:51 +0200 Subject: [PATCH 09/49] implement @ahocevar's suggestion instead --- lib/OpenLayers/BaseTypes/Date.js | 9 ++++++++- tests/BaseTypes/Date.html | 16 ++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/OpenLayers/BaseTypes/Date.js b/lib/OpenLayers/BaseTypes/Date.js index 7e721fed0c..5dba9da4b6 100644 --- a/lib/OpenLayers/BaseTypes/Date.js +++ b/lib/OpenLayers/BaseTypes/Date.js @@ -15,6 +15,13 @@ */ OpenLayers.Date = { + /** + * APIProperty: regex + * The regex to be used for validating dates. You can provide your own + * regex for instance for adding support for years before BC. + */ + regex: /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/, + /** * APIMethod: toISOString * Generates a string representing a date. The format of the string follows @@ -91,7 +98,7 @@ OpenLayers.Date = { */ parse: function(str) { var date; - var match = str.match(/^(?:(-?\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/); + var match = str.match(this.regex); if (match && (match[1] || match[7])) { // must have at least year or time var year = parseInt(match[1], 10) || 0; var month = (parseInt(match[2], 10) - 1) || 0; diff --git a/tests/BaseTypes/Date.html b/tests/BaseTypes/Date.html index af12348772..387fcf60f7 100644 --- a/tests/BaseTypes/Date.html +++ b/tests/BaseTypes/Date.html @@ -35,7 +35,7 @@ function test_Date_parse(t) { - t.plan(121); + t.plan(114); var cases = { "2000": { @@ -139,11 +139,6 @@ year: 2000, month: 3, date: 15 - }, - "-0501-03-01T00:00:00.000Z": { - year: -501, - month: 2, - date: 1 } }; @@ -180,6 +175,15 @@ t.ok(isNaN(invalid.getTime()), "invalid has no time"); } + function test_regex(t) { + t.plan(1); + var regex = OpenLayers.Date.regex; + OpenLayers.Date.regex = /^(?:(-?\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/; + var date = OpenLayers.Date.parse("-0501-03-01T00:00:00.000Z"); + t.ok(!isNaN(date.getTime()), "date with negative year is parsed when providing alternative regex"); + OpenLayers.Date.regex = regex; + } + From a96d32d284d9cfb9bf28d96b04a212bb8b54a322 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Tue, 17 Apr 2012 17:39:37 +0200 Subject: [PATCH 10/49] rename to dateRegEx and provide default value in api docs --- lib/OpenLayers/BaseTypes/Date.js | 9 +++++---- tests/BaseTypes/Date.html | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/OpenLayers/BaseTypes/Date.js b/lib/OpenLayers/BaseTypes/Date.js index 5dba9da4b6..937b12d108 100644 --- a/lib/OpenLayers/BaseTypes/Date.js +++ b/lib/OpenLayers/BaseTypes/Date.js @@ -16,11 +16,12 @@ OpenLayers.Date = { /** - * APIProperty: regex + * APIProperty: dateRegEx * The regex to be used for validating dates. You can provide your own - * regex for instance for adding support for years before BC. + * regex for instance for adding support for years before BC. Default + * value is: /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/ */ - regex: /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/, + dateRegEx: /^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/, /** * APIMethod: toISOString @@ -98,7 +99,7 @@ OpenLayers.Date = { */ parse: function(str) { var date; - var match = str.match(this.regex); + var match = str.match(this.dateRegEx); if (match && (match[1] || match[7])) { // must have at least year or time var year = parseInt(match[1], 10) || 0; var month = (parseInt(match[2], 10) - 1) || 0; diff --git a/tests/BaseTypes/Date.html b/tests/BaseTypes/Date.html index 387fcf60f7..e54fb31bc3 100644 --- a/tests/BaseTypes/Date.html +++ b/tests/BaseTypes/Date.html @@ -177,11 +177,11 @@ function test_regex(t) { t.plan(1); - var regex = OpenLayers.Date.regex; - OpenLayers.Date.regex = /^(?:(-?\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/; + var regex = OpenLayers.Date.dateRegEx; + OpenLayers.Date.dateRegEx = /^(?:(-?\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))|Z)?$/; var date = OpenLayers.Date.parse("-0501-03-01T00:00:00.000Z"); t.ok(!isNaN(date.getTime()), "date with negative year is parsed when providing alternative regex"); - OpenLayers.Date.regex = regex; + OpenLayers.Date.dateRegEx = regex; } From 8533edd19bca5612e42e71f630ecf72ea09e633b Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Tue, 17 Apr 2012 12:03:58 -0400 Subject: [PATCH 11/49] Toward dotless identifiers. --- lib/OpenLayers/Util.js | 11 ++++++++--- tests/Feature.html | 2 +- tests/Geometry.html | 4 ++-- tests/Popup.html | 2 +- tests/Popup/Anchored.html | 2 +- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 491448c9c9..cfa5ce2517 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -139,7 +139,8 @@ OpenLayers.Util.indexOf = function(array, obj) { * * Parameters: * element - {DOMElement} DOM element to modify. - * id - {String} The element id attribute to set. + * id - {String} The element id attribute to set. Note that dots (".") will be + * replaced with underscore ("_") in setting the element id. * px - {|Object} The element left and top position, * OpenLayers.Pixel or an object with * a 'x' and 'y' properties. @@ -157,7 +158,7 @@ OpenLayers.Util.modifyDOMElement = function(element, id, px, sz, position, border, overflow, opacity) { if (id) { - element.id = id; + element.id = id.replace(/\./g, "_"); } if (px) { element.style.left = px.x + "px"; @@ -195,7 +196,8 @@ OpenLayers.Util.modifyDOMElement = function(element, id, px, sz, position, * Parameters: * id - {String} An identifier for this element. If no id is * passed an identifier will be created - * automatically. + * automatically. Note that dots (".") will be replaced with + * underscore ("_") when generating ids. * px - {|Object} The element left and top position, * OpenLayers.Pixel or an object with * a 'x' and 'y' properties. @@ -928,6 +930,7 @@ OpenLayers.Util.lastSeqID = 0; * * Parameters: * prefix - {String} Optional string to prefix unique id. Default is "id_". + * Note that dots (".") in the prefix will be replaced with underscore ("_"). * * Returns: * {String} A unique id string, built on the passed in prefix. @@ -935,6 +938,8 @@ OpenLayers.Util.lastSeqID = 0; OpenLayers.Util.createUniqueID = function(prefix) { if (prefix == null) { prefix = "id_"; + } else { + prefix = prefix.replace(/\./g, "_"); } OpenLayers.Util.lastSeqID += 1; return prefix + OpenLayers.Util.lastSeqID; diff --git a/tests/Feature.html b/tests/Feature.html index 4a50d5143a..aa3db24a3d 100644 --- a/tests/Feature.html +++ b/tests/Feature.html @@ -21,7 +21,7 @@ t.ok( feature instanceof OpenLayers.Feature, "new OpenLayers.Feature returns Feature object" ); t.eq( feature.layer, layer, "feature.layer set correctly" ); - t.ok(OpenLayers.String.startsWith(feature.id, "OpenLayers.Feature_"), + t.ok(OpenLayers.String.startsWith(feature.id, "OpenLayers_Feature_"), "feature.id set correctly"); t.ok( feature.lonlat.equals(lonlat), "feature.lonlat set correctly" ); t.eq( feature.data.iconURL, iconURL, "feature.data.iconURL set correctly" ); diff --git a/tests/Geometry.html b/tests/Geometry.html index e61326d34f..6bae0ca16f 100644 --- a/tests/Geometry.html +++ b/tests/Geometry.html @@ -11,7 +11,7 @@ var g = new OpenLayers.Geometry(); t.eq(g.CLASS_NAME, "OpenLayers.Geometry", "correct CLASS_NAME") - t.ok(OpenLayers.String.startsWith(g.id, "OpenLayers.Geometry_"), + t.ok(OpenLayers.String.startsWith(g.id, "OpenLayers_Geometry_"), "id correctly set"); } @@ -22,7 +22,7 @@ var clone = geometry.clone(); t.eq(clone.CLASS_NAME, "OpenLayers.Geometry", "correct CLASS_NAME") - t.ok(OpenLayers.String.startsWith(clone.id, "OpenLayers.Geometry_"), + t.ok(OpenLayers.String.startsWith(clone.id, "OpenLayers_Geometry_"), "id correctly set"); } diff --git a/tests/Popup.html b/tests/Popup.html index 2d6a90b98e..766ac59e0d 100644 --- a/tests/Popup.html +++ b/tests/Popup.html @@ -13,7 +13,7 @@ popup = new OpenLayers.Popup(); t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" ); - t.ok(OpenLayers.String.startsWith(popup.id, "OpenLayers.Popup"), + t.ok(OpenLayers.String.startsWith(popup.id, "OpenLayers_Popup"), "valid default popupid"); var firstID = popup.id; t.ok(popup.contentSize.equals(size), "good default popup.size"); diff --git a/tests/Popup/Anchored.html b/tests/Popup/Anchored.html index f53546b0c0..3197e84655 100644 --- a/tests/Popup/Anchored.html +++ b/tests/Popup/Anchored.html @@ -11,7 +11,7 @@ popup = new OpenLayers.Popup.Anchored(); t.ok( popup instanceof OpenLayers.Popup.Anchored, "new OpenLayers.Popup.Anchored returns Popup.Anchored object" ); - t.ok(OpenLayers.String.startsWith(popup.id, "OpenLayers.Popup.Anchored"), "valid default popupid"); + t.ok(OpenLayers.String.startsWith(popup.id, "OpenLayers_Popup_Anchored"), "valid default popupid"); var firstID = popup.id; t.eq(popup.contentHTML, null, "good default popup.contentHTML"); From 163caf0e8d73cf2e31db8737a9851d62ea1b86be Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 18 Apr 2012 09:16:07 -0400 Subject: [PATCH 12/49] Underscore in canvas hit detection. --- lib/OpenLayers/Renderer/Canvas.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OpenLayers/Renderer/Canvas.js b/lib/OpenLayers/Renderer/Canvas.js index 7c2421ae96..feca10eef0 100644 --- a/lib/OpenLayers/Renderer/Canvas.js +++ b/lib/OpenLayers/Renderer/Canvas.js @@ -799,7 +799,7 @@ OpenLayers.Renderer.Canvas = OpenLayers.Class(OpenLayers.Renderer, { if (data[3] === 255) { // antialiased var id = data[2] + (256 * (data[1] + (256 * data[0]))); if (id) { - featureId = "OpenLayers.Feature.Vector_" + (id - 1 + this.hitOverflow); + featureId = "OpenLayers_Feature_Vector_" + (id - 1 + this.hitOverflow); try { feature = this.features[featureId][0]; } catch(err) { From faaa2cec1fc1edfe1a23feae4e871b3876bb2035 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 18 Apr 2012 09:46:24 -0400 Subject: [PATCH 13/49] Using compiled regexp to replace dots. Though split and join appear to be more efficient in Chrome, a compiled regexp looks to be a safer bet across the board. See http://jsperf.com/dotless (and http://jsperf.com/dotless-nop for the NOP). --- lib/OpenLayers/Util.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index cfa5ce2517..4c44dbe599 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -130,6 +130,17 @@ OpenLayers.Util.indexOf = function(array, obj) { }; +/** + * Property: dotless + * {RegExp} + * Compiled regular expression to match dots ("."). This is used for replacing + * dots in identifiers. Because object identifiers are frequently used for + * DOM element identifiers by the library, we avoid using dots to make for + * more sensible CSS selectors. + * + * TODO: Use a module pattern to avoid bloating the API with stuff like this. + */ +OpenLayers.Util.dotless = /\./g; /** * Function: modifyDOMElement @@ -158,7 +169,7 @@ OpenLayers.Util.modifyDOMElement = function(element, id, px, sz, position, border, overflow, opacity) { if (id) { - element.id = id.replace(/\./g, "_"); + element.id = id.replace(OpenLayers.Util.dotless, "_"); } if (px) { element.style.left = px.x + "px"; @@ -939,7 +950,7 @@ OpenLayers.Util.createUniqueID = function(prefix) { if (prefix == null) { prefix = "id_"; } else { - prefix = prefix.replace(/\./g, "_"); + prefix = prefix.replace(OpenLayers.Util.dotless, "_"); } OpenLayers.Util.lastSeqID += 1; return prefix + OpenLayers.Util.lastSeqID; From ef33f015043151091aef65b9620c809f6cd0d9e7 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 19 Apr 2012 12:02:18 +0200 Subject: [PATCH 14/49] Respect alwaysInRange from prototype, but allow changes in addOptions. --- lib/OpenLayers/Layer.js | 7 ++++++- tests/Layer.html | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index 05747f2cbf..158301174a 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -338,6 +338,11 @@ OpenLayers.Layer = OpenLayers.Class({ this.metadata = {}; + options = OpenLayers.Util.extend({}, options); + // make sure we respect alwaysInRange if set on the prototype + if (this.alwaysInRange != null) { + options.alwaysInRange = this.alwaysInRange; + } this.addOptions(options); this.name = name; @@ -858,7 +863,7 @@ OpenLayers.Layer = OpenLayers.Class({ alwaysInRange = false; } } - if(this.alwaysInRange == null) { + if(this.options.alwaysInRange == null) { this.alwaysInRange = alwaysInRange; } diff --git a/tests/Layer.html b/tests/Layer.html index eb2c9270f7..bd089abf6d 100644 --- a/tests/Layer.html +++ b/tests/Layer.html @@ -174,6 +174,16 @@ t.eq(log, 0, "addOptions doesn't call initResolutions when layer is not in map"); } + function test_addOptionsScale(t) { + t.plan(1); + var map = new OpenLayers.Map("map"); + var layer = new OpenLayers.Layer.WMS(); + map.addLayer(layer); + map.zoomToMaxExtent(); + layer.addOptions({maxResolution: 0.5, numZoomLevels: 15}); + t.eq(layer.alwaysInRange, false, "alwaysInRange should not be true anymore"); + } + function test_Layer_StandardOptionsAccessors (t) { t.plan( 4 ); From 363f837acb0d005a036bebbe4278da2835ca1c82 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 19 Apr 2012 13:29:56 +0200 Subject: [PATCH 15/49] Using resolution instead of zoom level for initial center (see #418). --- examples/bing-tiles.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/bing-tiles.js b/examples/bing-tiles.js index 0d4546bd09..e99c589656 100644 --- a/examples/bing-tiles.js +++ b/examples/bing-tiles.js @@ -23,7 +23,9 @@ var hybrid = new OpenLayers.Layer.Bing({ map.addLayers([road, aerial, hybrid]); map.addControl(new OpenLayers.Control.LayerSwitcher()); +// Zoom level numbering depends on metadata from Bing, which is not yet loaded. +var zoom = map.getZoomForResolution(76.43702827453613); map.setCenter(new OpenLayers.LonLat(-71.147, 42.472).transform( new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject() -), 11); +), zoom); From 551f509b490234e637ea6d1507d8744b7db0d6f1 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 19 Apr 2012 15:26:16 +0200 Subject: [PATCH 16/49] Make sure tiles are loaded for Bing overlays. Previously, Bing overlays that were added to an existing map had empty tiles, because tiles are added before the layer url is set in initLayer. This change makes sure tiles are only rendered when the layer url is available, by not processing the tile queue before the layer url is set. --- lib/OpenLayers/Layer/Bing.js | 16 ++++++++++++---- tests/Layer/Bing.html | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/lib/OpenLayers/Layer/Bing.js b/lib/OpenLayers/Layer/Bing.js index 30bb412550..162edf98a5 100644 --- a/lib/OpenLayers/Layer/Bing.js +++ b/lib/OpenLayers/Layer/Bing.js @@ -176,6 +176,18 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, { res.zoomMax + 1 - res.zoomMin, this.numZoomLevels ) }, true); + this.updateAttribution(); + }, + + /** + * Method: drawTileFromQueue + * Draws the first tile from the tileQueue, and unqueues that tile + */ + drawTileFromQueue: function() { + // don't start working on the queue before we have a url from initLayer + if (this.url) { + OpenLayers.Layer.XYZ.prototype.drawTileFromQueue.apply(this, arguments); + } }, /** @@ -185,9 +197,6 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, { * bounds - {} */ getURL: function(bounds) { - if (!this.url) { - return; - } var xyz = this.getXYZ(bounds), x = xyz.x, y = xyz.y, z = xyz.z; var quadDigits = []; for (var i = z; i > 0; --i) { @@ -253,7 +262,6 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, { */ setMap: function() { OpenLayers.Layer.XYZ.prototype.setMap.apply(this, arguments); - this.updateAttribution(); this.map.events.register("moveend", this, this.updateAttribution); }, diff --git a/tests/Layer/Bing.html b/tests/Layer/Bing.html index a55d2ebb24..b37de906fd 100644 --- a/tests/Layer/Bing.html +++ b/tests/Layer/Bing.html @@ -1,5 +1,19 @@ + From b61cfdb05411f7a1ec4c12187c1767d5ee0c1c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Fri, 4 May 2012 00:12:26 +0200 Subject: [PATCH 34/49] remove the editing toolbar from the highlight-feature.html, it does not make sense in this example and it prevents selection from working when activating navigation again --- examples/highlight-feature.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/highlight-feature.html b/examples/highlight-feature.html index 73cae24e0f..81e5c6f853 100644 --- a/examples/highlight-feature.html +++ b/examples/highlight-feature.html @@ -68,8 +68,6 @@ highlightCtrl.activate(); selectCtrl.activate(); - map.addControl(new OpenLayers.Control.EditingToolbar(vectors)); - map.setCenter(new OpenLayers.LonLat(0, 0), 1); } From 2608a0ebe7aa5c67bdddc9a2825f0bf2f1af7a57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Fri, 4 May 2012 14:26:42 +0200 Subject: [PATCH 35/49] fix resize handling in IE 9 and better (refs #449) --- lib/OpenLayers/Map.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index ba727f5189..f344a0b7f1 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -580,8 +580,8 @@ OpenLayers.Map = OpenLayers.Class({ // Because Mozilla does not support the "resize" event for elements // other than "window", we need to put a hack here. - if (OpenLayers.String.contains(navigator.appName, "Microsoft")) { - // If IE, register the resize on the div + if (parseFloat(navigator.appVersion.split("MSIE")[1]) < 9) { + // If IE < 9, register the resize on the div this.events.register("resize", this, this.updateSize); } else { // Else updateSize on catching the window's resize From 98fb795f97b37a1980ad7029172384f0cf6ed62b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Sat, 5 May 2012 14:27:12 +0200 Subject: [PATCH 36/49] set VERSION_NUMBER to 2.12-rc3 --- lib/OpenLayers.js | 2 +- lib/OpenLayers/SingleFile.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index f6df5e1915..24c7d0e8b5 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -414,4 +414,4 @@ /** * Constant: VERSION_NUMBER */ -OpenLayers.VERSION_NUMBER="Release 2.12-rc2"; +OpenLayers.VERSION_NUMBER="Release 2.12-rc3"; diff --git a/lib/OpenLayers/SingleFile.js b/lib/OpenLayers/SingleFile.js index 5ea5ae5a31..53060cc956 100644 --- a/lib/OpenLayers/SingleFile.js +++ b/lib/OpenLayers/SingleFile.js @@ -7,7 +7,7 @@ var OpenLayers = { /** * Constant: VERSION_NUMBER */ - VERSION_NUMBER: "Release 2.12-rc2", + VERSION_NUMBER: "Release 2.12-rc3", /** * Constant: singleFile From 81ee9524c7fc033856fb35609a1163ea164e75d9 Mon Sep 17 00:00:00 2001 From: Javier de la Torre Date: Sun, 6 May 2012 21:24:21 -0400 Subject: [PATCH 37/49] Added example to retrieve and display data from CartoDB using the SQL API --- examples/cartodb-geojson.html | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 examples/cartodb-geojson.html diff --git a/examples/cartodb-geojson.html b/examples/cartodb-geojson.html new file mode 100644 index 0000000000..ac3f40187e --- /dev/null +++ b/examples/cartodb-geojson.html @@ -0,0 +1,58 @@ + + + + Reading Features From CartoDB using GeoJSON + + + + + + + + +

Reading Features From CartoDB using GeoJSON

+
+ protocol, script, cartodb +
+

+ Demonstrates how to load features on OpenLayers using CartoDB SQL API. +

+
+
+

+ CartoDB is an Open Source Geopatial Database on the cloud. It allows you to import your data in shapefiles, KML, OpenStreeMap files, CSV, etc. and then analyze and visualize it. Internally CartoDB uses PostGIS 2.0 so all functionality in PostGIS can be used straight away. CartoDB exposes two APIS. One to generate maps as tiles with interactivity, and another SQL API to retrieve vector data using among other formats, GeoJSON. In this example we do a very simple query to obtain all protected areas in Costa Rica from a public table. You can adapt the SQL to include where clauses or complicate geospatial queries. +

+

+ View the + source code of this page to see how this is done. And check the table on CartoDB for Protected Areas in Costa Rica +

+
+ + + \ No newline at end of file From 6e34b048ffa2dc46c8083c07945f217b1fa05b6c Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Mon, 7 May 2012 13:06:14 +0200 Subject: [PATCH 38/49] examples/cartodb-geojson.html: kill long lines, use local OpenLayers.js --- examples/cartodb-geojson.html | 71 +++++++++++++++++++++-------------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/examples/cartodb-geojson.html b/examples/cartodb-geojson.html index ac3f40187e..2d7897045d 100644 --- a/examples/cartodb-geojson.html +++ b/examples/cartodb-geojson.html @@ -1,33 +1,45 @@ - + Reading Features From CartoDB using GeoJSON - - - -

Reading Features From CartoDB using GeoJSON

-
- protocol, script, cartodb -
-

- Demonstrates how to load features on OpenLayers using CartoDB SQL API. -

-
-
-

- CartoDB is an Open Source Geopatial Database on the cloud. It allows you to import your data in shapefiles, KML, OpenStreeMap files, CSV, etc. and then analyze and visualize it. Internally CartoDB uses PostGIS 2.0 so all functionality in PostGIS can be used straight away. CartoDB exposes two APIS. One to generate maps as tiles with interactivity, and another SQL API to retrieve vector data using among other formats, GeoJSON. In this example we do a very simple query to obtain all protected areas in Costa Rica from a public table. You can adapt the SQL to include where clauses or complicate geospatial queries. -

-

- View the - source code of this page to see how this is done. And check the table on CartoDB for Protected Areas in Costa Rica -

-
- + + +

Reading Features From CartoDB using GeoJSON

+
+ protocol, script, cartodb +
+

+ Demonstrates how to load features on OpenLayers using CartoDB SQL API. +

+
+
+

+ CartoDB is an Open Source + Geopatial Database on the cloud. It allows you to import your + data in shapefiles, KML, OpenStreeMap files, CSV, etc. and + then analyze and visualize it. Internally CartoDB uses PostGIS + 2.0 so all functionality in PostGIS can be used straight + away. CartoDB exposes two APIS. One + to generate maps + as tiles with interactivity, and another SQL API + to retrieve vector data using among other formats, GeoJSON. In + this example we do a very simple query to obtain all protected + areas in Costa Rica from a public table. You can adapt the SQL + to include where clauses or complicate geospatial queries. +

+

+ View the source code of this page to see how this is done. And + check the table on CartoDB + for Protected Areas in Costa Rica +

+
+ - - \ No newline at end of file + + + From 18b4d6808da1278e9ec43caba56281804f82e63e Mon Sep 17 00:00:00 2001 From: ahocevar Date: Wed, 9 May 2012 11:03:13 +0200 Subject: [PATCH 39/49] Adding missing dependency. Non-functional change. --- lib/OpenLayers/Request.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/OpenLayers/Request.js b/lib/OpenLayers/Request.js index 63edf6b72c..2d1540e4ad 100644 --- a/lib/OpenLayers/Request.js +++ b/lib/OpenLayers/Request.js @@ -5,6 +5,7 @@ /** * @requires OpenLayers/Events.js + * @requires OpenLayers/Request/XMLHttpRequest.js */ /** From f115c7a943473ed2ef4c202cd45fe742683bf82f Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 9 May 2012 19:48:51 -0600 Subject: [PATCH 40/49] Use commit hash instead of (mock) svn rev. When we upgraded to git, we didn't fully change over the way the website and examples are built. The cron job that runs the update script only built the website & examples if the revision returned by the svn interface to the GitHub repo was different than the previously stored revision. At some point, using `svn info` on the repo stopped being reliable. For example, this is what I get when running this today (in 2012): svn info https://github.com/openlayers/openlayers/ Path: openlayers URL: https://github.com/openlayers/openlayers Repository Root: https://github.com/openlayers/openlayers Repository UUID: d631b94f-4ba7-6298-eb8f-ce57b7db7bff Revision: 5488 Node Kind: directory Last Changed Author: schuyler.erle Last Changed Rev: 5488 Last Changed Date: 2006-05-12 12:35:22 -0700 (Fri, 12 May 2006) (Last change looks like it was 6 years ago.) We should be using a proper clone of the git repo and building the website and examples out of this. Until then, we can at least use `git-ls-remote` to check what the latest HEAD from the canonical repo looks like. This should get the website and examples building again (they stopped being updated a few weeks ago). --- tools/update_dev_dir.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/update_dev_dir.sh b/tools/update_dev_dir.sh index 1bab6ab513..cfb9814c9d 100755 --- a/tools/update_dev_dir.sh +++ b/tools/update_dev_dir.sh @@ -4,7 +4,7 @@ # Get current 'Last Changed Rev' -GITREV=`svn info https://github.com/openlayers/openlayers/ | grep 'Revision' | awk '{print $2}'` +GITREV=`git ls-remote https://github.com/openlayers/openlayers/ | grep HEAD | awk '{print $1}'` SVNREV=`svn info http://svn.openlayers.org/ | grep 'Revision' | awk '{print $2}'` # Get the last svn rev From 8dabefebb2f17c2e8e3ec2df6e5119b7e9fa9244 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Thu, 10 May 2012 01:02:40 -0600 Subject: [PATCH 41/49] Remove unused urllib2 --- tools/exampleparser.py | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/tools/exampleparser.py b/tools/exampleparser.py index 593d2fd181..98ecb4d980 100755 --- a/tools/exampleparser.py +++ b/tools/exampleparser.py @@ -3,7 +3,6 @@ import sys import os import re -import urllib2 import time from xml.dom.minidom import Document @@ -35,18 +34,6 @@ except ImportError, E: feedName = "example-list.xml" feedPath = "http://openlayers.org/dev/examples/" -def getListOfOnlineExamples(baseUrl): - """ - useful if you want to get a list of examples a url. not used by default. - """ - html = urllib2.urlopen(baseUrl) - soup = BeautifulSoup(html) - examples = soup.findAll('li') - examples = [example.find('a').get('href') for example in examples] - examples = [example for example in examples if example.endswith('.html')] - examples = [example for example in examples] - return examples - def getListOfExamples(relPath): """ returns list of .html filenames within a given path - excludes example-list.html @@ -56,18 +43,15 @@ def getListOfExamples(relPath): return examples -def getExampleHtml(location): +def getExampleHtml(path): """ - returns html of a specific example that is available online or locally + returns html of a specific example """ print '.', - if location.startswith('http'): - return urllib2.urlopen(location).read() - else: - f = open(location) - html = f.read() - f.close() - return html + f = open(path) + html = f.read() + f.close() + return html def extractById(soup, tagId, value=None): From cadb20c18a286bfbb834398ae52447b00b3a0f61 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Thu, 10 May 2012 01:03:54 -0600 Subject: [PATCH 42/49] Use clones of git repos for site building. The svn interface to our repos on git is not behaving well. This is resulting in the website, examples, and api docs not being updated when they should (`svn up` is not doing what it should). Instead of using svn checkouts, we should use clones of the git repos. At the same time, it makes sense to organize things a bit. These changes depend on a new structure on the openlayers.org machine: /osgeo/openlayers/repos - clones of our openlayers, docs, and website repos /osgeo/openlayers/sites - sources for openlayers.org, dev.openlayers.org, and docs.openlayers.org Where things are "built" (e.g. minifying js and modifying example markup to point to that js), changes are now made outside of the repo cleans. Having dirty repos was another source of build failures. Changes still need to be made to the release process/script. --- tools/exampleparser.py | 55 ++++++++------- tools/update_dev_dir.sh | 145 ++++++++++++++++++++++++++-------------- 2 files changed, 126 insertions(+), 74 deletions(-) diff --git a/tools/exampleparser.py b/tools/exampleparser.py index 98ecb4d980..6ef123a95c 100755 --- a/tools/exampleparser.py +++ b/tools/exampleparser.py @@ -87,15 +87,20 @@ def parseHtml(html,ids): d['classes'] = classes return d -def getSvnInfo(path): - h = os.popen("svn info %s --xml" % path) - tree = ElementTree.fromstring(h.read()) +def getGitInfo(exampleDir, exampleName): + orig = os.getcwd() + os.chdir(exampleDir) + h = os.popen("git log -n 1 --pretty=format:'%an|%ai' " + exampleName) + os.chdir(orig) + log = h.read() h.close() - d = { - 'url': tree.findtext('entry/url'), - 'author': tree.findtext('entry/commit/author'), - 'date': tree.findtext('entry/commit/date') - } + d = {} + parts = log.split("|") + d["author"] = parts[0] + # compensate for spaces in git log time + td = parts[1].split(" ") + td.insert(1, "T") + d["date"] = "".join(td) return d def createFeed(examples): @@ -190,34 +195,33 @@ if __name__ == "__main__": print "This script requires json or simplejson and BeautifulSoup. You don't have them. \n(%s)" % E sys.exit() - if len(sys.argv) > 1: - outFile = open(sys.argv[1],'w') + if len(sys.argv) == 3: + inExampleDir = sys.argv[1] + outExampleDir = sys.argv[2] else: - outFile = open('../examples/example-list.js','w') + inExampleDir = "../examples" + outExampleDir = "../examples" - examplesLocation = '../examples' - print 'Reading examples from %s and writing out to %s' % (examplesLocation, outFile.name) + outFile = open(os.path.join(outExampleDir, "example-list.js"), "w") + + print 'Reading examples from %s and writing out to %s' % (inExampleDir, outFile.name) exampleList = [] docIds = ['title','shortdesc','tags'] - #comment out option to create docs from online resource - #examplesLocation = 'http://svn.openlayers.org/sandbox/docs/examples/' - #examples = getListOfOnlineExamples(examplesLocation) - - examples = getListOfExamples(examplesLocation) + examples = getListOfExamples(inExampleDir) modtime = time.strftime("%Y-%m-%dT%I:%M:%SZ", time.gmtime()) for example in examples: - url = os.path.join(examplesLocation,example) - html = getExampleHtml(url) + path = os.path.join(inExampleDir, example) + html = getExampleHtml(path) tagvalues = parseHtml(html,docIds) tagvalues['example'] = example - # add in svn info - d = getSvnInfo(url) - tagvalues["modified"] = d["date"] or modtime + # add in author/date info + d = getGitInfo(inExampleDir, example) tagvalues["author"] = d["author"] or "anonymous" + tagvalues["modified"] = d["date"] or modtime tagvalues['link'] = example exampleList.append(tagvalues) @@ -234,8 +238,9 @@ if __name__ == "__main__": outFile.write(json) outFile.close() - print "writing feed to ../examples/%s " % feedName - atom = open('../examples/%s' % feedName, 'w') + outFeedPath = os.path.join(outExampleDir, feedName); + print "writing feed to %s " % outFeedPath + atom = open(outFeedPath, 'w') doc = createFeed(exampleList) atom.write(doc.toxml()) atom.close() diff --git a/tools/update_dev_dir.sh b/tools/update_dev_dir.sh index cfb9814c9d..4b1016c0b5 100755 --- a/tools/update_dev_dir.sh +++ b/tools/update_dev_dir.sh @@ -1,65 +1,112 @@ #!/bin/sh -# Used to update http://openlayers.org/dev/ +# check to see if the hosted examples or API docs need an update +cd /osgeo/openlayers/repos/openlayers +REMOTE_HEAD=`git ls-remote https://github.com/openlayers/openlayers/ | grep HEAD | awk '{print $1}'` +OLD_REMOTE_HEAD=`git rev-parse HEAD` +# if there's something different in the remote, update and build +if [ ! o$REMOTE_HEAD = o$OLD_REMOTE_HEAD ]; then + + git checkout master + git clean -f + git pull origin master + + # copy everything over to the dev dir within the website (keep the clone clean) + rsync -r --exclude=.git . /osgeo/openlayers/sites/openlayers.org/dev + + # make examples use built lib + cd /osgeo/openlayers/sites/openlayers.org/dev/tools -# Get current 'Last Changed Rev' -GITREV=`git ls-remote https://github.com/openlayers/openlayers/ | grep HEAD | awk '{print $1}'` -SVNREV=`svn info http://svn.openlayers.org/ | grep 'Revision' | awk '{print $2}'` + python exampleparser.py /osgeo/openlayers/repos/openlayers/examples /osgeo/openlayers/sites/openlayers.org/dev/examples + + if [ ! -f closure-compiler.jar ]; then + wget -c http://closure-compiler.googlecode.com/files/compiler-latest.zip + unzip compiler-latest.zip + mv compiler.jar closure-compiler.jar + fi -# Get the last svn rev -touch /tmp/ol_git_rev -touch /tmp/ol_svn_rev -OLD_GITREV="o`cat /tmp/ol_git_rev`" -OLD_SVNREV="o`cat /tmp/ol_svn_rev`" - -# If they're not equal, do some work. -if [ ! o$GITREV = $OLD_GITREV ]; then - svn revert -R /osgeo/openlayers/docs/dev - svn up /osgeo/openlayers/docs/dev - - # Also update website - svn up /osgeo/openlayers/docs/ - - cd /osgeo/openlayers/docs/dev/tools/ - python exampleparser.py - cd /osgeo/openlayers/docs/dev/build + cd /osgeo/openlayers/sites/openlayers.org/dev/build ./build.py -c closure tests.cfg ./build.py -c closure mobile.cfg OpenLayers.mobile.js ./build.py -c closure light.cfg OpenLayers.light.js - ./build.py -c none tests.cfg OpenLayers.debug.js - ./build.py -c none mobile.cfg OpenLayers.mobile.debug.js - ./build.py -c none light.cfg OpenLayers.light.debug.js - - cp OpenLayers.js .. - cp OpenLayers.*.js .. - - cd .. + ./build.py -c none tests.cfg OpenLayers.debug.js + ./build.py -c none mobile.cfg OpenLayers.mobile.debug.js + ./build.py -c none light.cfg OpenLayers.light.debug.js + cp OpenLayers*.js .. + cd /osgeo/openlayers/sites/openlayers.org/dev sed -i -e 's!../lib/OpenLayers.js?mobile!../OpenLayers.mobile.js!' examples/*.html sed -i -e 's!../lib/OpenLayers.js!../OpenLayers.js!' examples/*.html - naturaldocs -i /osgeo/openlayers/docs/dev/lib -o HTML /osgeo/openlayers/dev/apidocs -p /osgeo/openlayers/docs/dev/apidoc_config -s Default OL >/dev/null - naturaldocs -i /osgeo/openlayers/docs/dev/lib -o HTML /osgeo/openlayers/dev/docs -p /osgeo/openlayers/docs/dev/doc_config -s Default OL >/dev/null - # Record the revision - echo -n $GITREV > /tmp/ol_git_rev + + # update the API docs + if [ ! -d /osgeo/openlayers/sites/dev.openlayers.org/apidocs ]; then + mkdir -p /osgeo/openlayers/sites/dev.openlayers.org/apidocs + fi + if [ ! -d /osgeo/openlayers/sites/dev.openlayers.org/docs ]; then + mkdir -p /osgeo/openlayers/sites/dev.openlayers.org/docs + fi + naturaldocs --input lib --output HTML /osgeo/openlayers/sites/dev.openlayers.org/apidocs -p apidoc_config -s Default OL + naturaldocs --input lib --output HTML /osgeo/openlayers/sites/dev.openlayers.org/docs -p doc_config -s Default OL + fi + +# check to see if the website needs an update +cd /osgeo/openlayers/repos/website +REMOTE_HEAD=`git ls-remote https://github.com/openlayers/website/ | grep HEAD | awk '{print $1}'` +OLD_REMOTE_HEAD=`git rev-parse HEAD` + +# if there's something different in the remote, update the clone +if [ ! o$REMOTE_HEAD = o$OLD_REMOTE_HEAD ]; then + + git checkout master + git clean -f + git pull origin master + + # copy everything over to the website dir (keep the clone clean) + # can't use --delete here because of nested dev dir from above + rsync -r --exclude=.git . /osgeo/openlayers/sites/openlayers.org + +fi + +# check to see if prose docs need an update +cd /osgeo/openlayers/repos/docs +REMOTE_HEAD=`git ls-remote https://github.com/openlayers/docs/ | grep HEAD | awk '{print $1}'` +OLD_REMOTE_HEAD=`git rev-parse HEAD` + +# if there's something different in the remote, update the clone +if [ ! o$REMOTE_HEAD = o$OLD_REMOTE_HEAD ]; then + + git checkout master + git clean -f + git pull origin master + + mkdir -p /tmp/ol/docs/build/html /tmp/ol/docs/build/doctrees + sphinx-build -b html -d /tmp/ol/docs/build/doctrees . /tmp/ol/docs/build/html + + rsync -r --delete /tmp/ol/docs/build/html/ /osgeo/openlayers/sites/docs.openlayers.org + +fi + +## UPDATES FROM THE OLD SVN REPO + +# Get current 'Last Changed Rev' +SVNREV=`svn info http://svn.openlayers.org/ | grep 'Revision' | awk '{print $2}'` + +# Get the last svn rev +touch /tmp/ol_svn_rev +OLD_SVNREV="o`cat /tmp/ol_svn_rev`" + +# If they're not equal, do some work. if [ ! o$SVNREV = $OLD_SVNREV ]; then - svn up /osgeo/openlayers/dev/sandbox/ - svn up /osgeo/openlayers/dev/addins/ + svn up /osgeo/openlayers/repos/old_svn_repo/ # Record the revision echo -n $SVNREV > /tmp/ol_svn_rev -fi - -svn up /osgeo/openlayers/documentation-checkout -REV=`svn info /osgeo/openlayers/documentation-checkout | grep 'Last Changed Rev' | awk '{print $4}'` -# Get the last svn rev -touch /tmp/ol_doc_rev -OLD_REV="o`cat /tmp/ol_doc_rev`" -# If they're not equal, do some work. -if [ ! o$REV = $OLD_REV ]; then - cd /osgeo/openlayers/documentation-checkout - make html > /dev/null - cp -r _build/html/* /osgeo/openlayers/documentation - echo -n $REV > /tmp/ol_doc_rev -fi + # update the hosted sandboxes + rsync -r --delete --exclude=.svn --delete-excluded /osgeo/openlayers/repos/old_svn_repo/sandbox /osgeo/openlayers/sites/dev.openlayers.org/ + + # update the hosted addins + rsync -r --delete --exclude=.svn --delete-excluded /osgeo/openlayers/repos/old_svn_repo/addins /osgeo/openlayers/sites/dev.openlayers.org/ + +fi From 4ad6bacc5d1507aa379e11e534491acdf5186731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Thu, 10 May 2012 15:42:59 +0200 Subject: [PATCH 43/49] when calculating maxResolution from maxExtent and tileSize we dont want to the actual tile size for single layers --- lib/OpenLayers/Layer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index 73ce4e8024..d152400977 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -1010,7 +1010,7 @@ OpenLayers.Layer = OpenLayers.Class({ this.maxExtent != null) { // maxResolution for default grid sets assumes that at zoom // level zero, the whole world fits on one tile. - var tileSize = this.tileSize || this.map.getTileSize(); + var tileSize = this.map.getTileSize(); maxResolution = Math.max( this.maxExtent.getWidth() / tileSize.w, this.maxExtent.getHeight() / tileSize.h From a2c556f5c7c76405e8ccccf776ab4d77a9b8dfd2 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Thu, 10 May 2012 16:03:38 -0600 Subject: [PATCH 44/49] Updating release script to work with new structure After the website infrastructure changes (cadb20c18a286bfbb834398ae52447b00b3a0f61), the release script now puts stuff in /osgeo/openlayers/sites/openlayers.org (instead of /osgeo/openlayers/docs). --- tools/release.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/release.sh b/tools/release.sh index 890b65f407..a7a182f39b 100755 --- a/tools/release.sh +++ b/tools/release.sh @@ -33,10 +33,10 @@ mkdir doc/devdocs mkdir doc/apidocs rm tools/*.pyc -mkdir -p /osgeo/openlayers/docs/api/$VERSION -cp OpenLayers*.js /osgeo/openlayers/docs/api/$VERSION -cp -a img/ /osgeo/openlayers/docs/api/$VERSION -cp -a theme/ /osgeo/openlayers/docs/api/$VERSION +mkdir -p /osgeo/openlayers/sites/openlayers.org/api/$VERSION +cp OpenLayers*.js /osgeo/openlayers/sites/openlayers.org/api/$VERSION +cp -a img/ /osgeo/openlayers/sites/openlayers.org/api/$VERSION +cp -a theme/ /osgeo/openlayers/sites/openlayers.org/api/$VERSION cd .. @@ -46,4 +46,4 @@ naturaldocs -i OpenLayers-$VERSION/lib -o HTML OpenLayers-$VERSION/doc/apidocs - tar cvfz OpenLayers-$VERSION.tar.gz OpenLayers-$VERSION/ zip -9r OpenLayers-$VERSION.zip OpenLayers-$VERSION/ -cp OpenLayers-$VERSION.* /osgeo/openlayers/docs/download +cp OpenLayers-$VERSION.* /osgeo/openlayers/sites/openlayers.org/download From 9585341d9c39b8971cb6d6279a7b1f8f241056b2 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 26 Apr 2012 10:55:03 -0400 Subject: [PATCH 45/49] Changing/fixing the meaning of getServerZoom. If a layer is configured with serverResolutions, then getServerZoom should return the zoom level as index of the current resolution in the serverResolutions array. --- lib/OpenLayers/Layer/Grid.js | 5 ++++- lib/OpenLayers/Layer/TMS.js | 4 +--- lib/OpenLayers/Layer/WMTS.js | 5 +---- lib/OpenLayers/Layer/XYZ.js | 5 +---- tests/Layer/Grid.html | 4 ++-- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index 5c3c46d4e3..9c3f70c0d4 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -658,7 +658,10 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { * {Number} The closest server supported zoom. */ getServerZoom: function() { - return this.map.getZoomForResolution(this.getServerResolution()); + var serverResolution = this.getServerResolution(); + return this.serverResolutions ? + this.serverResolutions.indexOf(serverResolution) : + this.map.getZoomForResolution(serverResolution); }, /** diff --git a/lib/OpenLayers/Layer/TMS.js b/lib/OpenLayers/Layer/TMS.js index 74a7f0dfac..c4024edde3 100644 --- a/lib/OpenLayers/Layer/TMS.js +++ b/lib/OpenLayers/Layer/TMS.js @@ -173,9 +173,7 @@ OpenLayers.Layer.TMS = OpenLayers.Class(OpenLayers.Layer.Grid, { var res = this.getServerResolution(); var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w)); var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h)); - var z = this.serverResolutions != null ? - OpenLayers.Util.indexOf(this.serverResolutions, res) : - this.getServerZoom() + this.zoomOffset; + var z = this.getServerZoom() + (this.zoomOffset || 0); var path = this.serviceVersion + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type; var url = this.url; if (OpenLayers.Util.isArray(url)) { diff --git a/lib/OpenLayers/Layer/WMTS.js b/lib/OpenLayers/Layer/WMTS.js index f7f1dd040a..168ef5a89e 100644 --- a/lib/OpenLayers/Layer/WMTS.js +++ b/lib/OpenLayers/Layer/WMTS.js @@ -332,10 +332,7 @@ OpenLayers.Layer.WMTS = OpenLayers.Class(OpenLayers.Layer.Grid, { * Get the current index in the matrixIds array. */ getIdentifier: function() { - return this.serverResolutions != null ? - OpenLayers.Util.indexOf(this.serverResolutions, - this.getServerResolution()) : - this.getServerZoom() + this.zoomOffset; + return this.getServerZoom() + (this.zoomOffset || 0); }, /** diff --git a/lib/OpenLayers/Layer/XYZ.js b/lib/OpenLayers/Layer/XYZ.js index ef5a1950d9..dd1cc3c76f 100644 --- a/lib/OpenLayers/Layer/XYZ.js +++ b/lib/OpenLayers/Layer/XYZ.js @@ -143,10 +143,7 @@ OpenLayers.Layer.XYZ = OpenLayers.Class(OpenLayers.Layer.Grid, { (res * this.tileSize.w)); var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h)); - var resolutions = this.serverResolutions || this.resolutions; - var z = this.zoomOffset == 0 ? - OpenLayers.Util.indexOf(resolutions, res) : - this.getServerZoom() + this.zoomOffset; + var z = this.getServerZoom() + (this.zoomOffset || 0); if (this.wrapDateLine) { var limit = Math.pow(2, z); diff --git a/tests/Layer/Grid.html b/tests/Layer/Grid.html index 43791a67cb..bb632d1ea5 100644 --- a/tests/Layer/Grid.html +++ b/tests/Layer/Grid.html @@ -837,12 +837,12 @@ layer.serverResolutions = [2, 1]; resolution = 1; zoom = layer.getServerZoom(); - t.eq(zoom, 3, '[3] getServerZoom return value is correct'); + t.eq(zoom, 1, '[3] getServerZoom return value is correct'); layer.serverResolutions = [2]; resolution = 0.5; zoom = layer.getServerZoom(); - t.eq(zoom, 2, '[4] getServerZoom return value is correct'); + t.eq(zoom, 0, '[4] getServerZoom return value is correct'); var exc; layer.serverResolutions = [0.5]; From 40b4cc49e0dd820c07d1e68aead3a1d54ab8c589 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Thu, 26 Apr 2012 11:47:40 -0400 Subject: [PATCH 46/49] Using OpenLayers.Util.indexOf. Thanks @jorix for catching this. --- lib/OpenLayers/Layer/Grid.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index 9c3f70c0d4..f5837b15fc 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -660,7 +660,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { getServerZoom: function() { var serverResolution = this.getServerResolution(); return this.serverResolutions ? - this.serverResolutions.indexOf(serverResolution) : + OpenLayers.Util.indexOf(this.serverResolutions, serverResolution) : this.map.getZoomForResolution(serverResolution); }, From 72d1b54956ec2e04ada213318a1f6578c49204a2 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Fri, 27 Apr 2012 09:25:52 -0400 Subject: [PATCH 47/49] Also taking into account zoomOffset. Now the meaning of getServerZoom is fully clarified, and we can get rid of some code again as well. --- lib/OpenLayers/Layer/Grid.js | 13 +++++++------ lib/OpenLayers/Layer/TMS.js | 2 +- lib/OpenLayers/Layer/WMTS.js | 2 +- lib/OpenLayers/Layer/XYZ.js | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index f5837b15fc..ab83779334 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -651,17 +651,18 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { /** * Method: getServerZoom - * Return the zoom value corresponding to the best zoom supported by the server - * resolution. + * Return the zoom value corresponding to the best matching server + * resolution, taking into account and . * * Returns: - * {Number} The closest server supported zoom. + * {Number} The closest server supported zoom. This is not the map zoom + * level, but an index of the server's resolutions array. */ getServerZoom: function() { - var serverResolution = this.getServerResolution(); + var resolution = this.getServerResolution(); return this.serverResolutions ? - OpenLayers.Util.indexOf(this.serverResolutions, serverResolution) : - this.map.getZoomForResolution(serverResolution); + OpenLayers.Util.indexOf(this.serverResolutions, resolution) : + this.map.getZoomForResolution(resolution) + (this.zoomOffset || 0); }, /** diff --git a/lib/OpenLayers/Layer/TMS.js b/lib/OpenLayers/Layer/TMS.js index c4024edde3..da879b1de4 100644 --- a/lib/OpenLayers/Layer/TMS.js +++ b/lib/OpenLayers/Layer/TMS.js @@ -173,7 +173,7 @@ OpenLayers.Layer.TMS = OpenLayers.Class(OpenLayers.Layer.Grid, { var res = this.getServerResolution(); var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w)); var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h)); - var z = this.getServerZoom() + (this.zoomOffset || 0); + var z = this.getServerZoom(); var path = this.serviceVersion + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type; var url = this.url; if (OpenLayers.Util.isArray(url)) { diff --git a/lib/OpenLayers/Layer/WMTS.js b/lib/OpenLayers/Layer/WMTS.js index 168ef5a89e..bf4cc5a38f 100644 --- a/lib/OpenLayers/Layer/WMTS.js +++ b/lib/OpenLayers/Layer/WMTS.js @@ -332,7 +332,7 @@ OpenLayers.Layer.WMTS = OpenLayers.Class(OpenLayers.Layer.Grid, { * Get the current index in the matrixIds array. */ getIdentifier: function() { - return this.getServerZoom() + (this.zoomOffset || 0); + return this.getServerZoom(); }, /** diff --git a/lib/OpenLayers/Layer/XYZ.js b/lib/OpenLayers/Layer/XYZ.js index dd1cc3c76f..504f093f62 100644 --- a/lib/OpenLayers/Layer/XYZ.js +++ b/lib/OpenLayers/Layer/XYZ.js @@ -143,7 +143,7 @@ OpenLayers.Layer.XYZ = OpenLayers.Class(OpenLayers.Layer.Grid, { (res * this.tileSize.w)); var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h)); - var z = this.getServerZoom() + (this.zoomOffset || 0); + var z = this.getServerZoom(); if (this.wrapDateLine) { var limit = Math.pow(2, z); From cb7cf5e18e17ff3e09627a2b5303f1f6cce0d933 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 11 May 2012 17:41:24 -0600 Subject: [PATCH 48/49] Allow for circular dependency in XMLHttpRequest.js To make custom builds easier, it's convenient to have a OpenLayers.Request depend on OpenLayers.Request.XMLHttpRequest (see 18b4d6808da1278e9ec43caba56281804f82e63e). This makes it so we don't know which is going to be included first. To get around this, we can be careful about when we define OpenLayers.Request. --- lib/OpenLayers/Request.js | 11 +++++++++-- lib/OpenLayers/Request/XMLHttpRequest.js | 7 +++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Request.js b/lib/OpenLayers/Request.js index 2d1540e4ad..b64696f113 100644 --- a/lib/OpenLayers/Request.js +++ b/lib/OpenLayers/Request.js @@ -20,7 +20,14 @@ OpenLayers.ProxyHost = ""; * with XMLHttpRequests. These methods work with a cross-browser * W3C compliant class. */ -OpenLayers.Request = { +if (!OpenLayers.Requst) { + /** + * This allows for OpenLayers/Request/XMLHttpRequest.js to be included + * before or after this script. + */ + OpenLayers.Request = {}; +} +OpenLayers.Util.extend(OpenLayers.Request, { /** * Constant: DEFAULT_CONFIG @@ -420,4 +427,4 @@ OpenLayers.Request = { return OpenLayers.Request.issue(config); } -}; +}); diff --git a/lib/OpenLayers/Request/XMLHttpRequest.js b/lib/OpenLayers/Request/XMLHttpRequest.js index db322955d9..21200a6dae 100644 --- a/lib/OpenLayers/Request/XMLHttpRequest.js +++ b/lib/OpenLayers/Request/XMLHttpRequest.js @@ -447,5 +447,12 @@ * XMLHttpRequest object. From * http://code.google.com/p/xmlhttprequest/. */ + if (!OpenLayers.Request) { + /** + * This allows for OpenLayers/Request.js to be included + * before or after this script. + */ + OpenLayers.Request = {}; + } OpenLayers.Request.XMLHttpRequest = cXMLHttpRequest; })(); From f7d4657c142788b9b7296d44b372330caf6b994b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Sat, 12 May 2012 08:56:21 +0200 Subject: [PATCH 49/49] fix typo in Request.js (refs #462) --- lib/OpenLayers/Request.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/OpenLayers/Request.js b/lib/OpenLayers/Request.js index b64696f113..0c7eb3c4b0 100644 --- a/lib/OpenLayers/Request.js +++ b/lib/OpenLayers/Request.js @@ -20,7 +20,7 @@ OpenLayers.ProxyHost = ""; * with XMLHttpRequests. These methods work with a cross-browser * W3C compliant class. */ -if (!OpenLayers.Requst) { +if (!OpenLayers.Request) { /** * This allows for OpenLayers/Request/XMLHttpRequest.js to be included * before or after this script.