Single argument constructor for UTFGrid layer.

This commit is contained in:
Tim Schaub
2012-03-03 16:05:58 -07:00
parent 2feb860983
commit 36d22bbb15
4 changed files with 36 additions and 34 deletions
+5 -5
View File
@@ -1,10 +1,10 @@
var osm = new OpenLayers.Layer.OSM(); var osm = new OpenLayers.Layer.OSM();
var utfgrid = new OpenLayers.Layer.UTFGrid( var utfgrid = new OpenLayers.Layer.UTFGrid({
"Invisible UTFGrid Layer", url: "utfgrid/world_utfgrid/${z}/${x}/${y}.json",
"./utfgrid/world_utfgrid/${z}/${x}/${y}.json", utfgridResolution: 4, // default is 2
{utfgridResolution: 4} // default is 2 displayInLayerSwitcher: false
); });
var map = new OpenLayers.Map({ var map = new OpenLayers.Map({
div: "map", div: "map",
+10 -10
View File
@@ -1,15 +1,15 @@
var osm = new OpenLayers.Layer.OSM(); var osm = new OpenLayers.Layer.OSM();
var population = new OpenLayers.Layer.UTFGrid( var population = new OpenLayers.Layer.UTFGrid({
"World Population", name: "World Population",
"./utfgrid/world_utfgrid/${z}/${x}/${y}.json", url: "utfgrid/world_utfgrid/${z}/${x}/${y}.json",
{utfgridResolution: 4} // default is 2 utfgridResolution: 4 // default is 2
); });
var bioregions = new OpenLayers.Layer.UTFGrid( var bioregions = new OpenLayers.Layer.UTFGrid({
"World Bioregions", name: "World Bioregions",
"./utfgrid/bio_utfgrid/${z}/${x}/${y}.json", url: "utfgrid/bio_utfgrid/${z}/${x}/${y}.json",
{utfgridResolution: 4} // default is 2 utfgridResolution: 4 // default is 2
); });
var map = new OpenLayers.Map({ var map = new OpenLayers.Map({
div: "map", div: "map",
+16 -14
View File
@@ -19,9 +19,10 @@
* Example: * Example:
* *
* (start code) * (start code)
* var world_utfgrid = new OpenLayers.Layer.UTFGrid( * var world_utfgrid = new OpenLayers.Layer.UTFGrid({
* 'UTFGrid Layer', * url: "/tiles/world_utfgrid/${z}/${x}/${y}.json",
* "http://tiles/world_utfgrid/${z}/${x}/${y}.json" * utfgridResolution: 4,
* displayInLayerSwitcher: false
* ); * );
* map.addLayer(world_utfgrid); * map.addLayer(world_utfgrid);
* *
@@ -99,14 +100,18 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, {
/** /**
* Constructor: OpenLayers.Layer.UTFGrid * Constructor: OpenLayers.Layer.UTFGrid
* Create a new UTFGrid layer.
* *
* Parameters: * Parameters:
* name - {String} * config - {Object} Configuration properties for the layer.
* url - {String} *
* options - {Object} Hashtable of extra options to tag onto the layer * Required configuration properties:
* url - {String} The url template for UTFGrid tiles. See the <url> property.
*/ */
initialize: function(name, url, options) { initialize: function(options) {
OpenLayers.Layer.Grid.prototype.initialize.apply(this, [name, url, {}, options]); OpenLayers.Layer.Grid.prototype.initialize.apply(
this, [options.name, options.url, {}, options]
);
this.tileOptions = OpenLayers.Util.extend({ this.tileOptions = OpenLayers.Util.extend({
utfgridResolution: this.utfgridResolution utfgridResolution: this.utfgridResolution
}, this.tileOptions); }, this.tileOptions);
@@ -117,20 +122,17 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, {
* Create a clone of this layer * Create a clone of this layer
* *
* Parameters: * Parameters:
* obj - {Object} Is this ever used? * obj - {Object} Only used by a subclass of this layer.
* *
* Returns: * Returns:
* {<OpenLayers.Layer.UTFGrid>} An exact clone of this OpenLayers.Layer.UTFGrid * {<OpenLayers.Layer.UTFGrid>} An exact clone of this OpenLayers.Layer.UTFGrid
*/ */
clone: function (obj) { clone: function (obj) {
if (obj == null) { if (obj == null) {
obj = new OpenLayers.Layer.UTFGrid(this.name, obj = new OpenLayers.Layer.UTFGrid(this.getOptions());
this.url,
this.getOptions());
} }
//get all additions from superclasses // get all additions from superclasses
obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]); obj = OpenLayers.Layer.Grid.prototype.clone.apply(this, [obj]);
return obj; return obj;
+5 -5
View File
@@ -22,11 +22,11 @@
var map, layer; var map, layer;
function setUp() { function setUp() {
layer = new OpenLayers.Layer.UTFGrid( layer = new OpenLayers.Layer.UTFGrid({
null, url: "../data/utfgrid/world_utfgrid/${z}/${x}/${y}.json",
"../data/utfgrid/world_utfgrid/${z}/${x}/${y}.json", isBaseLayer: true,
{isBaseLayer: true, utfgridResolution: 4} utfgridResolution: 4
); });
map = new OpenLayers.Map({ map = new OpenLayers.Map({
div: "map", div: "map",
projection: "EPSG:900913", projection: "EPSG:900913",