From 36d22bbb158283855700b5113056e2dd3c43918c Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Sat, 3 Mar 2012 16:05:58 -0700 Subject: [PATCH] Single argument constructor for UTFGrid layer. --- examples/utfgrid.js | 10 +++++----- examples/utfgrid_twogrids.js | 20 ++++++++++---------- lib/OpenLayers/Layer/UTFGrid.js | 30 ++++++++++++++++-------------- tests/Tile/UTFGrid.html | 10 +++++----- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/examples/utfgrid.js b/examples/utfgrid.js index 546957186f..dc06c415e8 100644 --- a/examples/utfgrid.js +++ b/examples/utfgrid.js @@ -1,10 +1,10 @@ var osm = new OpenLayers.Layer.OSM(); -var utfgrid = new OpenLayers.Layer.UTFGrid( - "Invisible UTFGrid Layer", - "./utfgrid/world_utfgrid/${z}/${x}/${y}.json", - {utfgridResolution: 4} // default is 2 -); +var utfgrid = new OpenLayers.Layer.UTFGrid({ + url: "utfgrid/world_utfgrid/${z}/${x}/${y}.json", + utfgridResolution: 4, // default is 2 + displayInLayerSwitcher: false +}); var map = new OpenLayers.Map({ div: "map", diff --git a/examples/utfgrid_twogrids.js b/examples/utfgrid_twogrids.js index 05f5eb08de..c9cb4980e9 100644 --- a/examples/utfgrid_twogrids.js +++ b/examples/utfgrid_twogrids.js @@ -1,15 +1,15 @@ var osm = new OpenLayers.Layer.OSM(); -var population = new OpenLayers.Layer.UTFGrid( - "World Population", - "./utfgrid/world_utfgrid/${z}/${x}/${y}.json", - {utfgridResolution: 4} // default is 2 -); -var bioregions = new OpenLayers.Layer.UTFGrid( - "World Bioregions", - "./utfgrid/bio_utfgrid/${z}/${x}/${y}.json", - {utfgridResolution: 4} // default is 2 -); +var population = new OpenLayers.Layer.UTFGrid({ + name: "World Population", + url: "utfgrid/world_utfgrid/${z}/${x}/${y}.json", + utfgridResolution: 4 // default is 2 +}); +var bioregions = new OpenLayers.Layer.UTFGrid({ + name: "World Bioregions", + url: "utfgrid/bio_utfgrid/${z}/${x}/${y}.json", + utfgridResolution: 4 // default is 2 +}); var map = new OpenLayers.Map({ div: "map", diff --git a/lib/OpenLayers/Layer/UTFGrid.js b/lib/OpenLayers/Layer/UTFGrid.js index c37d9b5db6..36bb03319e 100644 --- a/lib/OpenLayers/Layer/UTFGrid.js +++ b/lib/OpenLayers/Layer/UTFGrid.js @@ -19,9 +19,10 @@ * Example: * * (start code) - * var world_utfgrid = new OpenLayers.Layer.UTFGrid( - * 'UTFGrid Layer', - * "http://tiles/world_utfgrid/${z}/${x}/${y}.json" + * var world_utfgrid = new OpenLayers.Layer.UTFGrid({ + * url: "/tiles/world_utfgrid/${z}/${x}/${y}.json", + * utfgridResolution: 4, + * displayInLayerSwitcher: false * ); * map.addLayer(world_utfgrid); * @@ -99,14 +100,18 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, { /** * Constructor: OpenLayers.Layer.UTFGrid + * Create a new UTFGrid layer. * * Parameters: - * name - {String} - * url - {String} - * options - {Object} Hashtable of extra options to tag onto the layer + * config - {Object} Configuration properties for the layer. + * + * Required configuration properties: + * url - {String} The url template for UTFGrid tiles. See the property. */ - initialize: function(name, url, options) { - OpenLayers.Layer.Grid.prototype.initialize.apply(this, [name, url, {}, options]); + initialize: function(options) { + OpenLayers.Layer.Grid.prototype.initialize.apply( + this, [options.name, options.url, {}, options] + ); this.tileOptions = OpenLayers.Util.extend({ utfgridResolution: this.utfgridResolution }, this.tileOptions); @@ -117,20 +122,17 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, { * Create a clone of this layer * * Parameters: - * obj - {Object} Is this ever used? + * obj - {Object} Only used by a subclass of this layer. * * Returns: * {} An exact clone of this OpenLayers.Layer.UTFGrid */ clone: function (obj) { - if (obj == null) { - obj = new OpenLayers.Layer.UTFGrid(this.name, - this.url, - this.getOptions()); + obj = new OpenLayers.Layer.UTFGrid(this.getOptions()); } - //get all additions from superclasses + // get all additions from superclasses obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); return obj; diff --git a/tests/Tile/UTFGrid.html b/tests/Tile/UTFGrid.html index efe06882cd..84eecca34f 100644 --- a/tests/Tile/UTFGrid.html +++ b/tests/Tile/UTFGrid.html @@ -22,11 +22,11 @@ var map, layer; function setUp() { - layer = new OpenLayers.Layer.UTFGrid( - null, - "../data/utfgrid/world_utfgrid/${z}/${x}/${y}.json", - {isBaseLayer: true, utfgridResolution: 4} - ); + layer = new OpenLayers.Layer.UTFGrid({ + url: "../data/utfgrid/world_utfgrid/${z}/${x}/${y}.json", + isBaseLayer: true, + utfgridResolution: 4 + }); map = new OpenLayers.Map({ div: "map", projection: "EPSG:900913",