diff --git a/lib/map.js b/lib/map.js index 23dcd22..665b8bb 100644 --- a/lib/map.js +++ b/lib/map.js @@ -9,7 +9,7 @@ define(['map/clientlayer', 'map/labelslayer', zoomControl: false }; - var LocateButton = L.Control.extend({ + var ButtonBase = L.Control.extend({ options: { position: 'bottomright' }, @@ -22,6 +22,17 @@ define(['map/clientlayer', 'map/labelslayer', this.f = f; }, + update: function () { + this.button.classList.toggle('active', this.active); + }, + + set: function (v) { + this.active = v; + this.update(); + } + }); + + var LocateButton = ButtonBase.extend({ onAdd: function () { var button = L.DomUtil.create('button', 'ion-locate shadow'); button.setAttribute('data-tooltip', _.t('button.tracking')); @@ -33,33 +44,12 @@ define(['map/clientlayer', 'map/labelslayer', return button; }, - update: function () { - this.button.classList.toggle('active', this.active); - }, - - set: function (v) { - this.active = v; - this.update(); - }, - onClick: function () { this.f(!this.active); } }); - var CoordsPickerButton = L.Control.extend({ - options: { - position: 'bottomright' - }, - - active: false, - button: undefined, - - initialize: function (f, o) { - L.Util.setOptions(this, o); - this.f = f; - }, - + var CoordsPickerButton = ButtonBase.extend({ onAdd: function () { var button = L.DomUtil.create('button', 'ion-pin shadow'); button.setAttribute('data-tooltip', _.t('button.location')); @@ -73,20 +63,10 @@ define(['map/clientlayer', 'map/labelslayer', return button; }, - update: function () { - this.button.classList.toggle('active', this.active); - }, - - set: function (v) { - this.active = v; - this.update(); - }, - onClick: function (e) { L.DomEvent.stopPropagation(e); this.f(!this.active); } - }); function mkMarker(dict, iconFunc, router) { diff --git a/lib/map/clientlayer.js b/lib/map/clientlayer.js index 1773b3f..a85f2e4 100644 --- a/lib/map/clientlayer.js +++ b/lib/map/clientlayer.js @@ -1,5 +1,5 @@ -define(['leaflet'], - function (L) { +define(['leaflet', 'helper'], + function (L, helper) { 'use strict'; return L.TileLayer.Canvas.extend({ @@ -13,13 +13,6 @@ define(['leaflet'], this.redraw(); }, drawTile: function (canvas, tilePoint) { - function getTileBBox(s, map, tileSize, margin) { - var tl = map.unproject([s.x - margin, s.y - margin]); - var br = map.unproject([s.x + margin + tileSize, s.y + margin + tileSize]); - - return [br.lat, tl.lng, tl.lat, br.lng]; - } - if (!this.data) { return; } @@ -29,7 +22,7 @@ define(['leaflet'], var map = this._map; var margin = 50; - var bbox = getTileBBox(s, map, tileSize, margin); + var bbox = helper.getTileBBox(s, map, tileSize, margin); var nodes = this.data.search(bbox); diff --git a/lib/map/labelslayer.js b/lib/map/labelslayer.js index 2382522..910421a 100644 --- a/lib/map/labelslayer.js +++ b/lib/map/labelslayer.js @@ -1,5 +1,5 @@ -define(['leaflet', 'rbush'], - function (L, rbush) { +define(['leaflet', 'rbush', 'helper'], + function (L, rbush, helper) { 'use strict'; var labelLocations = [['left', 'middle', 0 / 8], @@ -188,13 +188,6 @@ define(['leaflet', 'rbush'], this.redraw(); }, drawTile: function (canvas, tilePoint, zoom) { - function getTileBBox(s, map, tileSize, margin) { - var tl = map.unproject([s.x - margin, s.y - margin]); - var br = map.unproject([s.x + margin + tileSize, s.y + margin + tileSize]); - - return [br.lat, tl.lng, tl.lat, br.lng]; - } - if (!this.labels) { return; } @@ -212,7 +205,7 @@ define(['leaflet', 'rbush'], return { p: p, label: d.label }; } - var bbox = getTileBBox(s, map, tileSize, this.margin); + var bbox = helper.getTileBBox(s, map, tileSize, this.margin); var labels = this.labels.search(bbox).map(projectNodes); diff --git a/lib/utils/helper.js b/lib/utils/helper.js index b9fa5ed..7be6362 100644 --- a/lib/utils/helper.js +++ b/lib/utils/helper.js @@ -232,5 +232,11 @@ define({ } return p; + }, + getTileBBox: function getTileBBox(s, map, tileSize, margin) { + var tl = map.unproject([s.x - margin, s.y - margin]); + var br = map.unproject([s.x + margin + tileSize, s.y + margin + tileSize]); + + return [br.lat, tl.lng, tl.lat, br.lng]; } });