From 477c1109eb7e2c09ad5ae6e607222cd6a4193dc4 Mon Sep 17 00:00:00 2001 From: mourner Date: Thu, 23 Feb 2012 11:01:03 +0200 Subject: [PATCH] clean up, move attribution prefix arg to options --- CHANGELOG.md | 1 + src/Leaflet.js | 2 +- src/control/Control.Attribution.js | 32 +++++++++++----------- src/layer/GeoJSON.js | 17 ++++++------ src/layer/vector/Polyline.Edit.js | 4 +-- src/map/Map.js | 44 +++++++++++++++--------------- 6 files changed, 50 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad69edde..c410ce2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ An in-progress version being developed on the master branch. * Replaced ugly control position constants (e.g. L.Control.Position.TOP_LEFT) with light strings ('topleft', 'bottomright', etc.) * Removed `Map` `locateAndSetView` method (use `locate` with `setView: true` option) * Changed popup `minWidth` and `maxWidth` options to be applied to content element, not the whole popup. + * Moved `prefix` argument to `options` in `Control.Attribution` constructor. #### Other API improvements diff --git a/src/Leaflet.js b/src/Leaflet.js index f6797c28..222b8221 100644 --- a/src/Leaflet.js +++ b/src/Leaflet.js @@ -5,7 +5,7 @@ ROOT_URL: root.L_ROOT_URL || (function () { var scripts = document.getElementsByTagName('script'), - leafletRe = /\/?leaflet[\-\._]?([\w\-\._]*)\.js\??/; + leafletRe = /\/?leaflet[\-\._]?([\w\-\._]*)\.js\??/; var i, len, src, matches; diff --git a/src/control/Control.Attribution.js b/src/control/Control.Attribution.js index cf0cc721..59fe5935 100644 --- a/src/control/Control.Attribution.js +++ b/src/control/Control.Attribution.js @@ -1,52 +1,51 @@ L.Control.Attribution = L.Control.extend({ options: { - position: 'bottomright' + position: 'bottomright', + prefix: 'Powered by Leaflet' }, - initialize: function (prefix, options) { + initialize: function (options) { L.Util.setOptions(this, options); - this._prefix = prefix || 'Powered by Leaflet'; this._attributions = {}; }, onAdd: function (map) { + this._map = map; + this._container = L.DomUtil.create('div', 'leaflet-control-attribution'); L.DomEvent.disableClickPropagation(this._container); - this._map = map; + this._update(); return this._container; }, setPrefix: function (prefix) { - this._prefix = prefix; + this.options.prefix = prefix; this._update(); }, addAttribution: function (text) { - if (!text) { - return; - } + if (!text) { return; } + if (!this._attributions[text]) { this._attributions[text] = 0; } this._attributions[text]++; + this._update(); }, removeAttribution: function (text) { - if (!text) { - return; - } + if (!text) { return; } + this._attributions[text]--; this._update(); }, _update: function () { - if (!this._map) { - return; - } + if (!this._map) { return; } var attribs = []; @@ -57,8 +56,9 @@ L.Control.Attribution = L.Control.extend({ } var prefixAndAttribs = []; - if (this._prefix) { - prefixAndAttribs.push(this._prefix); + + if (this.options.prefix) { + prefixAndAttribs.push(this.options.prefix); } if (attribs.length) { prefixAndAttribs.push(attribs.join(', ')); diff --git a/src/layer/GeoJSON.js b/src/layer/GeoJSON.js index 7556f46f..29fbc03b 100644 --- a/src/layer/GeoJSON.js +++ b/src/layer/GeoJSON.js @@ -13,7 +13,7 @@ L.GeoJSON = L.FeatureGroup.extend({ addGeoJSON: function (geojson) { var features = geojson.features, - i, len; + i, len; if (features) { for (i = 0, len = features.length; i < len; i++) { @@ -23,8 +23,8 @@ L.GeoJSON = L.FeatureGroup.extend({ } var isFeature = (geojson.type === 'Feature'), - geometry = isFeature ? geojson.geometry : geojson, - layer = L.GeoJSON.geometryToLayer(geometry, this.options.pointToLayer); + geometry = isFeature ? geojson.geometry : geojson, + layer = L.GeoJSON.geometryToLayer(geometry, this.options.pointToLayer); this.fire('featureparse', { layer: layer, @@ -41,8 +41,8 @@ L.GeoJSON = L.FeatureGroup.extend({ L.Util.extend(L.GeoJSON, { geometryToLayer: function (geometry, pointToLayer) { var coords = geometry.coordinates, - layers = [], - latlng, latlngs, i, len, layer; + layers = [], + latlng, latlngs, i, len, layer; switch (geometry.type) { case 'Point': @@ -87,16 +87,15 @@ L.Util.extend(L.GeoJSON, { coordsToLatLng: function (coords, reverse) { // (Array, Boolean) -> LatLng var lat = parseFloat(coords[reverse ? 0 : 1]), - lng = parseFloat(coords[reverse ? 1 : 0]); + lng = parseFloat(coords[reverse ? 1 : 0]); return new L.LatLng(lat, lng, true); }, coordsToLatLngs: function (coords, levelsDeep, reverse) { // (Array, Number, Boolean) -> Array var latlng, - latlngs = [], - i, - len; + latlngs = [], + i, len; for (i = 0, len = coords.length; i < len; i++) { latlng = levelsDeep ? diff --git a/src/layer/vector/Polyline.Edit.js b/src/layer/vector/Polyline.Edit.js index 68217f3b..efa65ff3 100644 --- a/src/layer/vector/Polyline.Edit.js +++ b/src/layer/vector/Polyline.Edit.js @@ -180,8 +180,8 @@ L.Handler.PolyEdit = L.Handler.extend({ _getMiddleLatLng: function (marker1, marker2) { var map = this._poly._map, - p1 = map.latLngToLayerPoint(marker1.getLatLng()), - p2 = map.latLngToLayerPoint(marker2.getLatLng()); + p1 = map.latLngToLayerPoint(marker1.getLatLng()), + p2 = map.latLngToLayerPoint(marker2.getLatLng()); return map.layerPointToLatLng(p1._add(p2).divideBy(2)); } diff --git a/src/map/Map.js b/src/map/Map.js index 42ddfee2..0a608bb3 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -70,7 +70,7 @@ L.Map = L.Class.extend({ } var center = options.center, - zoom = options.zoom; + zoom = options.zoom; if (center && typeof zoom !== 'undefined') { this.setView(center, zoom, true); @@ -108,7 +108,7 @@ L.Map = L.Class.extend({ fitWorld: function () { var sw = new L.LatLng(-60, -170), - ne = new L.LatLng(85, 179); + ne = new L.LatLng(85, 179); return this.fitBounds(new L.LatLngBounds(sw, ne)); }, @@ -152,12 +152,12 @@ L.Map = L.Class.extend({ panInsideBounds: function (bounds) { var viewBounds = this.getBounds(), - viewSw = this.project(viewBounds.getSouthWest()), - viewNe = this.project(viewBounds.getNorthEast()), - sw = this.project(bounds.getSouthWest()), - ne = this.project(bounds.getNorthEast()), - dx = 0, - dy = 0; + viewSw = this.project(viewBounds.getSouthWest()), + viewNe = this.project(viewBounds.getNorthEast()), + sw = this.project(bounds.getSouthWest()), + ne = this.project(bounds.getNorthEast()), + dx = 0, + dy = 0; if (viewNe.y < ne.y) { // north dy = ne.y - viewNe.y; @@ -288,7 +288,7 @@ L.Map = L.Class.extend({ getCenter: function (unbounded) { // (Boolean) var viewHalf = this.getSize().divideBy(2), - centerPoint = this._getTopLeftPoint().add(viewHalf); + centerPoint = this._getTopLeftPoint().add(viewHalf); return this.unproject(centerPoint, this._zoom, unbounded); }, @@ -299,37 +299,37 @@ L.Map = L.Class.extend({ getBounds: function () { var bounds = this.getPixelBounds(), - sw = this.unproject(new L.Point(bounds.min.x, bounds.max.y), this._zoom, true), - ne = this.unproject(new L.Point(bounds.max.x, bounds.min.y), this._zoom, true); + sw = this.unproject(new L.Point(bounds.min.x, bounds.max.y), this._zoom, true), + ne = this.unproject(new L.Point(bounds.max.x, bounds.min.y), this._zoom, true); return new L.LatLngBounds(sw, ne); }, getMinZoom: function () { var z1 = this.options.minZoom || 0, - z2 = this._layersMinZoom || 0, - z3 = this._boundsMinZoom || 0; + z2 = this._layersMinZoom || 0, + z3 = this._boundsMinZoom || 0; return Math.max(z1, z2, z3); }, getMaxZoom: function () { var z1 = typeof this.options.maxZoom === 'undefined' ? Infinity : this.options.maxZoom, - z2 = typeof this._layersMaxZoom === 'undefined' ? Infinity : this._layersMaxZoom; + z2 = typeof this._layersMaxZoom === 'undefined' ? Infinity : this._layersMaxZoom; return Math.min(z1, z2); }, getBoundsZoom: function (bounds, inside) { // (LatLngBounds, Boolean) -> Number var size = this.getSize(), - zoom = this.options.minZoom || 0, - maxZoom = this.getMaxZoom(), - ne = bounds.getNorthEast(), - sw = bounds.getSouthWest(), - boundsSize, - nePoint, - swPoint, - zoomNotFound = true; + zoom = this.options.minZoom || 0, + maxZoom = this.getMaxZoom(), + ne = bounds.getNorthEast(), + sw = bounds.getSouthWest(), + boundsSize, + nePoint, + swPoint, + zoomNotFound = true; if (inside) { zoom--;