<commit_before>// ==========================================================================
//                            DG.MapLayerView
//
//  Author:   <NAME>
//
//  Copyright ©2013 KCP Technologies, Inc., a McGraw-Hill Education Company
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
// ==========================================================================

/* global L */
/** @class  DG.MapLayerView

 A view on a map.

 We're using Leaflet as our map library.
 See: http://leafletjs.com/index.html

 @extends SC.Object
 */
DG.MapLayerView = SC.View.extend(
    /** @scope DG.MapLayerView.prototype */ {

      model: null,

      _layerID: null,

      _map: null,

      map: function () {
        return this._map;
      }.property('_map'),

      baseMapLayer: null,
      baseMapLabels: null,

      didCreateMap: function (iMap) {
      },

      /**
       * Property that can be observed by parent view
       */
      displayChangeCount: 0,

      /**
       * Set along with displayChangeCount so that event can be logged
       * @property(String}
       */
      lastEventType: null,

      /**
       * Property that can be observed by parent view
       */
      clickCount: 0,

      /**
       * Property that can be observed by parent view, counts times the map returns to idle
       */
      idleCount: 0,

      init: function () {
        sc_super();
      },

      /**
       * Provide an element on which we can draw.
       * @param ctx
       * @param first
       */
      render: function (ctx, first) {
        if (first) {
          this._layerID = ctx.push(
              '<div></div>'
          ).id();
        }
      },

      didCreateLayer: function () {
        // TODO: Investigate whether there is some later time to call _createMap so we don't have to use invokeLast
        this.invokeLast(this._createMap);
      },

      _createMap: function () {

        var onLayerAdd = function (iLayerEvent) {
            var tParentView = this.get('parentView');
              this._map.off('layeradd', onLayerAdd);
              tParentView.addPointLayer();
              tParentView.addAreaLayer();
              tParentView.addGridLayer();
            }.bind(this),

            onDisplayChangeEvent = function (iEvent) {
              this.set('lastEventType', iEvent.type);
              this.incrementProperty('displayChangeCount');
            }.bind(this),

            onClick = function (iEvent) {
              this.incrementProperty('clickCount');
            }.bind(this);


        if (this._map) {
          // May need to resize here
        } else {
          this._map = L.map(this._layerID, { scrollWheelZoom: false })
              .setView(this.getPath('model.center'), this.getPath('model.zoom'));
          this._map.on('layeradd', onLayerAdd)
            .on('dragstart', onDisplayChangeEvent)
            .on('drag', onDisplayChangeEvent)
            .on('dragend', onDisplayChangeEvent)
            .on('move', onDisplayChangeEvent)
            .on('zoomend', onDisplayChangeEvent)
            .on('moveend', onDisplayChangeEvent)
            .on('click', onClick)
            .on('dragstart drag move', function() { this._clearIdle(); }.bind(this))
            .on('dragend zoomend moveend', function() { this._setIdle(); }.bind(this));
          this.backgroundChanged(); // will initialize baseMap
        }
      },

      viewDidResize: function () {
        var tMap = this.get('map');
        if (tMap) {
          tMap.invalidateSize();
        }
      },

      _idleTimeout: null,
      _clearIdle: function () {
        if (this._idleTimeout) {
          clearTimeout(this._idleTimeout);
        }
      },
      _setIdle: function () {
        this._clearIdle();
        this._idleTimeout = setTimeout(function() {
          this._idleTimeout = null;
          this.incrementProperty('idleCount');
        }.bind(this), 500);
      },

      backgroundChanged: function() {
        var tMap = this.get('map'),
            tNewLayerName = this.getPath('model.baseMapLayerName'),
            tNewLayer;

        if(!tNewLayerName)
          return;
        if( this.get('baseMapLayer'))
          tMap.removeLayer( this.get('baseMapLayer'));
        if( this.get('baseMapLabels'))
          tMap.removeLayer( this.get('baseMapLabels'));
        tNewLayer = L.esri.basemapLayer( tNewLayerName);
        this._map.addLayer(tNewLayer, true /*add at bottom */);
        //this._map.addLayer( L.esri.basemapLayer(tBasemap + 'Labels'));
        this.set('baseMapLayer', tNewLayer);
      }.observes('model.baseMapLayerName')

    }
);
<commit_msg>[Fixes ###91608202] We use jQuery brute force to move the layer that contains the popup tips in front of the layer of points.<commit_after>// ==========================================================================
//                            DG.MapLayerView
//
//  Author:   <NAME>
//
//  Copyright ©2013 KCP Technologies, Inc., a McGraw-Hill Education Company
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
// ==========================================================================

/* global L */
/** @class  DG.MapLayerView

 A view on a map.

 We're using Leaflet as our map library.
 See: http://leafletjs.com/index.html

 @extends SC.Object
 */
DG.MapLayerView = SC.View.extend(
    /** @scope DG.MapLayerView.prototype */ {

      model: null,

      _layerID: null,

      _map: null,

      map: function () {
        return this._map;
      }.property('_map'),

      baseMapLayer: null,
      baseMapLabels: null,

      didCreateMap: function (iMap) {
      },

      /**
       * Property that can be observed by parent view
       */
      displayChangeCount: 0,

      /**
       * Set along with displayChangeCount so that event can be logged
       * @property(String}
       */
      lastEventType: null,

      /**
       * Property that can be observed by parent view
       */
      clickCount: 0,

      /**
       * Property that can be observed by parent view, counts times the map returns to idle
       */
      idleCount: 0,

      init: function () {
        sc_super();
      },

      /**
       * Provide an element on which we can draw.
       * @param ctx
       * @param first
       */
      render: function (ctx, first) {
        if (first) {
          this._layerID = ctx.push(
              '<div></div>'
          ).id();
        }
      },

      didCreateLayer: function () {
        // TODO: Investigate whether there is some later time to call _createMap so we don't have to use invokeLast
        this.invokeLast(this._createMap);
      },

      _createMap: function () {

        var onLayerAdd = function (iLayerEvent) {
              var tParentView = this.get('parentView');
              this._map.off('layeradd', onLayerAdd);
              tParentView.addPointLayer();
              tParentView.addAreaLayer();
              tParentView.addGridLayer();
              // We want the popup hints for the grid to be on top of the points. jQuery can
              // help with this if we hardcode the layer class names.
              // ToDo: The implementation below will not work properly when there are two maps.
              // The popups for the second grid will appear on the first map. Presumably we can
              // use more selective selectors to solve this problem.
              this.invokeOnce(function () {
                $('.leaflet-popup-pane').insertAfter('.map-layer');
              });
            }.bind(this),

            onDisplayChangeEvent = function (iEvent) {
              this.set('lastEventType', iEvent.type);
              this.incrementProperty('displayChangeCount');
            }.bind(this),

            onClick = function (iEvent) {
              this.incrementProperty('clickCount');
            }.bind(this);

        if (this._map) {
          // May need to resize here
        } else {
          this._map = L.map(this._layerID, {scrollWheelZoom: false})
              .setView(this.getPath('model.center'), this.getPath('model.zoom'));
          this._map.on('layeradd', onLayerAdd)
              .on('dragstart', onDisplayChangeEvent)
              .on('drag', onDisplayChangeEvent)
              .on('dragend', onDisplayChangeEvent)
              .on('move', onDisplayChangeEvent)
              .on('zoomend', onDisplayChangeEvent)
              .on('moveend', onDisplayChangeEvent)
              .on('click', onClick)
              .on('dragstart drag move', function () {
                this._clearIdle();
              }.bind(this))
              .on('dragend zoomend moveend', function () {
                this._setIdle();
              }.bind(this));
          this.backgroundChanged(); // will initialize baseMap
        }
      },

      viewDidResize: function () {
        var tMap = this.get('map');
        if (tMap) {
          tMap.invalidateSize();
        }
      },

      _idleTimeout: null,
      _clearIdle: function () {
        if (this._idleTimeout) {
          clearTimeout(this._idleTimeout);
        }
      },
      _setIdle: function () {
        this._clearIdle();
        this._idleTimeout = setTimeout(function () {
          this._idleTimeout = null;
          this.incrementProperty('idleCount');
        }.bind(this), 500);
      },

      backgroundChanged: function () {
        var tMap = this.get('map'),
            tNewLayerName = this.getPath('model.baseMapLayerName'),
            tNewLayer;

        if (!tNewLayerName)
          return;
        if (this.get('baseMapLayer'))
          tMap.removeLayer(this.get('baseMapLayer'));
        if (this.get('baseMapLabels'))
          tMap.removeLayer(this.get('baseMapLabels'));
        tNewLayer = L.esri.basemapLayer(tNewLayerName);
        this._map.addLayer(tNewLayer, true /*add at bottom */);
        //this._map.addLayer( L.esri.basemapLayer(tBasemap + 'Labels'));
        this.set('baseMapLayer', tNewLayer);
      }.observes('model.baseMapLayerName')

    }
);

{'fraction_non_alphanumeric': 0.1431552209017509, 'fraction_numerical': 0.0032658985757053434, 'mean_word_length': 1.9875338753387535, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '659481', 'n_tokens_mistral': 3067, 'n_tokens_neox': 2954, 'n_words': 803}