[TASK] Cleanup duplicate code
- map buttons - layer getTileBBox
This commit is contained in:
		
							parent
							
								
									59a73a3fb5
								
							
						
					
					
						commit
						6505f5491d
					
				
							
								
								
									
										46
									
								
								lib/map.js
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								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) {
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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];
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user