From 28659c9ebcb27d5252eb2335fe21d26a5cd8f22b Mon Sep 17 00:00:00 2001 From: crschmidt Date: Wed, 16 Jan 2008 17:07:20 +0000 Subject: [PATCH] Add setUrl function for GML layer. Thanks to a well done patch (with tests!) from Ian Johnson. (Closes #1264) git-svn-id: http://svn.openlayers.org/trunk/openlayers@5776 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- doc/authors.txt | 1 + lib/OpenLayers/Layer/GML.js | 16 +++++++++++++++- tests/Layer/test_GML.html | 10 ++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/doc/authors.txt b/doc/authors.txt index 7883bd8c54..b6d921502d 100644 --- a/doc/authors.txt +++ b/doc/authors.txt @@ -10,6 +10,7 @@ John Frank Sean Gilles Pierre Giraud Andreas Hocevar +Ian Johnson Eric Lemoine Philip Lindsay Corey Puffault diff --git a/lib/OpenLayers/Layer/GML.js b/lib/OpenLayers/Layer/GML.js index c87df8f898..a93fe9bbdb 100644 --- a/lib/OpenLayers/Layer/GML.js +++ b/lib/OpenLayers/Layer/GML.js @@ -97,7 +97,21 @@ OpenLayers.Layer.GML = OpenLayers.Class(OpenLayers.Layer.Vector, { this.loaded = true; } }, - + + /** + * Method: setUrl + * Change the URL and reload the GML + * + * Parameters: + * url - {String} URL of a GML file. + */ + setUrl:function(url) { + this.url = url; + this.destroyFeatures(); + this.loaded = false; + this.events.triggerEvent("loadstart"); + this.loadGML(); + }, /** * Method: requestSuccess diff --git a/tests/Layer/test_GML.html b/tests/Layer/test_GML.html index 4f8d04b179..b8b1f8ffbb 100644 --- a/tests/Layer/test_GML.html +++ b/tests/Layer/test_GML.html @@ -6,6 +6,7 @@ var name = "GML Layer"; var gml = "./owls.xml"; + var gml2 = "./mice.xml"; // if this test is running online, different rules apply var isMSIE = (navigator.userAgent.indexOf("MSIE") > -1); @@ -40,6 +41,15 @@ }); } + function test_GML_setUrl(t) { + t.plan(2); + var layer = new OpenLayers.Layer.GML(name, gml); + var map = new OpenLayers.Map("map"); + map.addLayer(layer); + t.eq(layer.url, gml, "layer has correct original url"); + layer.setUrl(gml2); + t.eq(layer.url, gml2, "layer has correctly changed url"); + }