Advertisement
Sovun

Untitled

Sep 11th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.   @module ember-flexberry-gis
  3. */
  4.  
  5. import Ember from 'ember';
  6. import layout from '../templates/components/flexberry-boundingbox';
  7. import FlexberryMapActionsHandlerMixin from '../mixins/flexberry-map-actions-handler';
  8.  
  9.  
  10.  
  11. export default Ember.Component.extend(
  12.   FlexberryMapActionsHandlerMixin, {
  13.   /**
  14.     Reference to component's template.
  15.   */
  16.   layout,
  17.   /**
  18.     Leaflet map.
  19.     @property leafletMap
  20.     @type <a href="http://leafletjs.com/reference-1.0.0.html#map">L.Map</a>
  21.     @default null
  22.   */
  23.   leafletMap: null,
  24.   calledByAreaSelect: false,
  25.   /**
  26.     Observes changes in reference to leaflet map.
  27.     Initializes area select plugin.
  28.     @method _leafletMapDidChange
  29.     @private
  30.   */
  31.     _leafletMapDidChange: Ember.on('init', Ember.observer('leafletMap', function() {
  32.       let leafletMap = this.get('leafletMap');
  33.       if (!Ember.isNone(leafletMap)) {
  34.          let areaSelect = L.areaSelect({width:100, height:100});
  35.          areaSelect.addTo(leafletMap);
  36.          this.set('areaSelect', areaSelect);
  37.          areaSelect.on("change", () => {
  38.              let bounds = areaSelect.getBounds();
  39.              this.calledByAreaSelect = true;
  40.              this.set('minLgt', bounds.getWest());
  41.  
  42.              this.calledByAreaSelect = true;
  43.              this.set('maxLgt', bounds.getEast());
  44.  
  45.              this.calledByAreaSelect = true;
  46.              this.set('minLat', bounds.getSouth());
  47.  
  48.              this.calledByAreaSelect = true;
  49.              this.set('maxLat', bounds.getNorth());
  50.  
  51.              console.log("сработал ареаселект чендж");
  52.              return bounds;
  53.          });
  54.        }
  55.    })),
  56.  
  57.      _latDidChange: Ember.observer('minLat', 'maxLat', function () {
  58.  
  59.     //   Ember.run.once(this, function(){
  60.          let minLat = Number(this.get('minLat'));
  61.          let maxLat = Number(this.get('maxLat'));
  62.          if(minLat>maxLat){
  63.            [minLat, maxLat] = [maxLat, minLat];
  64.            this.set('minLat', minLat);
  65.            this.set('maxLat', maxLat);
  66.          }
  67.          if(minLat<-90){
  68.            minLat = -90;
  69.            this.set('minLat', minLat);
  70.          }
  71.          if(maxLat>90){
  72.            maxLat = 90;
  73.            this.set('maxLat', maxLat);
  74.          }
  75.  
  76.          if(this.calledByAreaSelect === true){
  77.            this.calledByAreaSelect = false;
  78.            return;
  79.          }
  80.          let leafletMap = this.get('leafletMap');
  81.          let areaSelect = this.get('areaSelect');
  82.          let maxLgt = Number(this.get('maxLgt')),
  83.              minLgt = Number(this.get('minLgt'));
  84.         let coords = L.latLng((maxLat+minLat)/2, (maxLgt+minLgt)/2);
  85.         leafletMap.panTo(coords);
  86.         leafletMap.fitBounds(L.latLngBounds(L.latLng(minLat, minLgt),L.latLng(maxLat, maxLgt)));
  87.         let newWidth = Math.abs(leafletMap.latLngToLayerPoint(L.latLng(minLat, maxLgt)).x) - Math.abs(leafletMap.latLngToLayerPoint(L.latLng(minLat, minLgt)).x);
  88.         let newHeight = Math.abs(leafletMap.latLngToLayerPoint(L.latLng(maxLat, minLgt)).y) - Math.abs(leafletMap.latLngToLayerPoint(L.latLng(minLat, minLgt)).y);
  89.         newWidth = Math.abs(newWidth);
  90.         newHeight = Math.abs(newHeight);
  91.         console.log("w: ", newWidth,"h: ", newHeight);
  92.         areaSelect.setDimensions({width:newWidth, height:newHeight});
  93.       // });
  94.      }),
  95.  
  96.      _lgtDidChange: Ember.observer('minLgt', 'maxLgt', function () {
  97.       // Ember.run.once(this, function(){
  98.           let minLgt = Number(this.get('minLgt'));
  99.           let maxLgt = Number(this.get('maxLgt'));
  100.           if(minLgt > maxLgt){
  101.             [minLgt, maxLgt] = [maxLgt, minLgt];
  102.             this.set('minLgt', minLgt);
  103.             this.set('maxLgt', maxLgt);
  104.           }
  105.           if(minLgt < -90){
  106.             minLgt = -90;
  107.             this.set('minLgt', minLgt);
  108.           }
  109.           if(maxLgt > 90){
  110.             maxLgt = 90;
  111.             this.set('maxLgt', maxLgt);
  112.           }
  113.           if(this.calledByAreaSelect === true){
  114.             this.calledByAreaSelect = false;
  115.             return;
  116.           }
  117.           let leafletMap = this.get('leafletMap');
  118.           let areaSelect = this.get('areaSelect');
  119.           let maxLat = Number(this.get('maxLat')),
  120.               minLat = Number(this.get('minLat'));
  121.               let coords = L.latLng((maxLat+minLat)/2, (maxLgt+minLgt)/2);
  122.           leafletMap.panTo(coords);
  123.           leafletMap.fitBounds(L.latLngBounds(L.latLng(minLat, minLgt),L.latLng(maxLat, maxLgt)));
  124.           let newWidth = Math.abs(leafletMap.latLngToLayerPoint(L.latLng(minLat, maxLgt)).x) - Math.abs(leafletMap.latLngToLayerPoint(L.latLng(minLat, minLgt)).x);
  125.           let newHeight = Math.abs(leafletMap.latLngToLayerPoint(L.latLng(maxLat, minLgt)).y) - Math.abs(leafletMap.latLngToLayerPoint(L.latLng(minLat, minLgt)).y);
  126.           newWidth = Math.abs(newWidth);
  127.           newHeight = Math.abs(newHeight);
  128.           console.log("w: ", newWidth,"h: ", newHeight);
  129.           areaSelect.setDimensions({width:newWidth, height:newHeight});
  130.           // });
  131.       }),
  132.  
  133.  
  134.  
  135.   actions: {
  136.   },
  137. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement