Skip to content

Commit

Permalink
Minor formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Dec 7, 2011
1 parent f249b95 commit 9e4fd37
Showing 1 changed file with 31 additions and 32 deletions.
63 changes: 31 additions & 32 deletions src/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
if(!(layerOrLayers instanceof Array)) {
layerOrLayers = [ layerOrLayers ];
}

for (var i = 0; i < layerOrLayers.length; i++) {
this.addLayer(layerOrLayers[i]);
}
Expand All @@ -51,7 +51,7 @@
this.tileSize = new MM.Point(256, 256);

// default 0-18 zoom level
// with infinite horizontal pan and clamped vertical pan
// with infinite horizontal pan and clamped vertical pan
this.coordLimits = [
new MM.Coordinate(0,-Infinity,0), // top left outer
new MM.Coordinate(1,Infinity,0).zoomTo(18) // bottom right inner
Expand Down Expand Up @@ -153,14 +153,14 @@
}
return this._windowResize;
},

// A convenience function to restrict interactive zoom ranges.
// (you should also adjust map provider to restrict which tiles get loaded,
// or modify map.coordLimits and provider.tileLimits for finer control)
setZoomRange: function(minZoom, maxZoom) {
this.coordLimits[0] = this.coordLimits[0].zoomTo(minZoom);
this.coordLimits[1] = this.coordLimits[1].zoomTo(maxZoom);
},
},

// zooming
zoomBy: function(zoomOffset) {
Expand Down Expand Up @@ -397,7 +397,6 @@
},

// layers

// HACK for 0.x.y - stare at @RandomEtc
// this method means we can also pass a URL template or a MapProvider to addLayer
coerceLayer: function(layerish) {
Expand All @@ -412,7 +411,7 @@
return new MM.Layer(layerish);
}
},

// return a copy of the layers array
getLayers: function() {
return this.layers.slice();
Expand All @@ -422,7 +421,7 @@
getLayerAt: function(index) {
return this.layers[index];
},

// put the given layer on top of all the others
addLayer: function(layer) {
layer = this.coerceLayer(layer);
Expand All @@ -431,7 +430,7 @@
layer.map = this; // TODO: remove map property from MM.Layer?
return this;
},

// find the given layer and remove it
removeLayer: function(layer) {
for (var i = 0; i < this.layers.length; i++) {
Expand All @@ -445,8 +444,8 @@

// replace the current layer at the given index with the given layer
setLayerAt: function(index, layer) {
if(index < 0 || index >= this.layers.length) {

if (index < 0 || index >= this.layers.length) {
throw new Error('invalid index in setLayerAt(): ' + index);
}

Expand All @@ -458,22 +457,22 @@
if (index < this.layers.length) {
this.layers[index].destroy();
}

// pass it on.
this.layers[index] = layer;
this.parent.appendChild(layer.parent);
layer.map = this; // TODO: remove map property from MM.Layer
layer.map = this; // TODO: remove map property from MM.Layer

MM.getFrame(this.getRedraw());
}

return this;
},

// put the given layer at the given index, moving others if necessary
insertLayerAt: function(index, layer) {

if(index < 0 || index > this.layers.length) {
if (index < 0 || index > this.layers.length) {
throw new Error('invalid index in insertLayerAt(): ' + index);
}

Expand All @@ -491,30 +490,30 @@
}

layer.map = this; // TODO: remove map property from MM.Layer

MM.getFrame(this.getRedraw());

return this;
},

// remove the layer at the given index, call .destroy() on the layer
removeLayerAt: function(index) {
if(index < 0 || index >= this.layers.length) {
if (index < 0 || index >= this.layers.length) {
throw new Error('invalid index in removeLayer(): ' + index);
}

// gone baby gone.
var old = this.layers[index];
this.layers.splice(index, 1);
old.destroy();

return this;
},

// switch the stacking order of two layers, by index
swapLayers: function(i, j) {

if(i < 0 || i >= this.layers.length || j < 0 || j >= this.layers.length) {
if (i < 0 || i >= this.layers.length || j < 0 || j >= this.layers.length) {
throw new Error('invalid index in swapLayers(): ' + index);
}

Expand All @@ -534,15 +533,15 @@
// now do it to the layers array
this.layers[i] = layer2;
this.layers[j] = layer1;

return this;
},

// limits

enforceZoomLimits: function(coord) {
var limits = this.coordLimits;
if (limits) {
if (limits) {
// clamp zoom level:
var minZoom = limits[0].zoom;
var maxZoom = limits[1].zoom;
Expand All @@ -555,21 +554,21 @@
}
return coord;
},

enforcePanLimits: function(coord) {

var limits = this.coordLimits;
if (limits) {

if (limits) {

coord = coord.copy();

// clamp pan:
var topLeftLimit = limits[0].zoomTo(coord.zoom);
var bottomRightLimit = limits[1].zoomTo(coord.zoom);
var currentTopLeft = this.pointCoordinate(new MM.Point(0,0));
var currentBottomRight = this.pointCoordinate(this.dimensions);

// this handles infinite limits:
// (Infinity - Infinity) is Nan
// NaN is never less than anything
Expand All @@ -587,7 +586,7 @@
}
if (bottomRightLimit.column - topLeftLimit.column < currentBottomRight.column - currentTopLeft.column) {
// if the limit is smaller than the current view, center it
coord.column = (bottomRightLimit.column + topLeftLimit.column) / 2;
coord.column = (bottomRightLimit.column + topLeftLimit.column) / 2;
}
else {
if (currentTopLeft.column < topLeftLimit.column) {
Expand All @@ -598,8 +597,8 @@
}
}
}
return coord;

return coord;
},

// Prevent accidentally navigating outside the `coordLimits` of the map.
Expand Down

0 comments on commit 9e4fd37

Please sign in to comment.