<commit_before>/**
 * Created by <NAME> <<EMAIL>>
 *       on 4/7/14.
 */

(function () {
  'use strict';

  L.spatialdev.featurelabel.FeatureSet = function () {
    this.features = [];
    this._pathIdHash = {};
    L.spatialdev.featurelabel.featureSets.push(this);
  };

  L.spatialdev.featurelabel.FeatureSet.prototype.addFeature = function (featureLayer) {
    this.features.push(featureLayer);

    if (!featureLayer._leaflet_id) {
      console.error(featureLayer.feature.properties.name + ' does not have a _leaflet_id');
    }

    // feature consists of one polygon
    if (!featureLayer._layers) {
      var leafletId = featureLayer._leaflet_id;
      this._pathIdHash[leafletId] = featureLayer;
    }

    // feature consists of several polygons
    else {
      for (var id in featureLayer._layers) {
        var pathLayer = featureLayer._layers[id];
        var leafletId = pathLayer._leaflet_id;
        this._pathIdHash[leafletId] = featureLayer;
      }
    }

    pathUpdated(featureLayer);
  };

  L.spatialdev.featurelabel.FeatureSet.prototype._pathUpdated = function (leafletId) {
    var featureLayer = this._pathIdHash[leafletId];
    pathUpdated(featureLayer);
  };

  function pathUpdated(featureLayer) {
    // If the id doesnt hash, no path for the features in are feature set apply.
    if (!featureLayer) {
//      console.error('pathUpdated featureLayer empty');
      return;
    }

    if (featureLayer._layers) {

      // only calculate center after all of the polygons have been updated
      if (!featureLayer.pathsUpdated) featureLayer.pathsUpdated = 0;
      ++featureLayer.pathsUpdated;

      if (featureLayer.pathsUpdated === Object.keys(featureLayer._layers).length) {
        var l = findMostComplexLayer(featureLayer._layers);

        if (l) {
          featureLayer.labelCenterPoint = calculateCenter(l._parts);
          updateLabel(featureLayer);
        }

        featureLayer.pathsUpdated = 0;
      }

    } else {

      // there is only one polygon, so calculate center. also check to see if there are parts
      if ( featureLayer._parts && featureLayer._parts.length ) {
        featureLayer.labelCenterPoint = calculateCenter(featureLayer._parts);
        updateLabel(featureLayer);
      }

    }
  }


  function createLabel(featureLayer) {
    var point = featureLayer.labelCenterPoint;

    var properties = featureLayer.feature.properties;
    var text = properties.title || properties.name || 'Label';
    if (properties.labelProperty) {
      if (typeof properties.labelProperty === 'function') {
        text = properties.labelProperty();
      } else {
        text = properties[properties.labelProperty];
      }

    }

    console.log('LABEL: ' + text + ' (' + point.x + ', ' + point.y + ')');

    var icon = L.divIcon({
      className: 'btn btn-danger featurelabel-icon',
      iconSize: [60,60],
      html: text
    });

    var label = L.label([45,-100], {icon:icon}, point);

    label.on('mouseover', function(e) {

    });

    label.on('click', function (e) {

    });


    // NH TODO Add to featureLayer instead but make sure that it's a valid feature layer.
    label.addTo(debug.map);
<commit_msg>coloring of the border of the polygons on mouseover and mouse click for featurelabels<commit_after>/**
 * Created by <NAME> <<EMAIL>>
 *       on 4/7/14.
 */

(function () {
  'use strict';

  L.spatialdev.featurelabel.FeatureSet = function () {
    this.features = [];
    this._pathIdHash = {};
    L.spatialdev.featurelabel.featureSets.push(this);
  };

  L.spatialdev.featurelabel.FeatureSet.prototype.addFeature = function (featureLayer) {
    this.features.push(featureLayer);

    if (!featureLayer._leaflet_id) {
      console.error(featureLayer.feature.properties.name + ' does not have a _leaflet_id');
    }

    // feature consists of one polygon
    if (!featureLayer._layers) {
      var leafletId = featureLayer._leaflet_id;
      this._pathIdHash[leafletId] = featureLayer;
    }

    // feature consists of several polygons
    else {
      for (var id in featureLayer._layers) {
        var pathLayer = featureLayer._layers[id];
        var leafletId = pathLayer._leaflet_id;
        this._pathIdHash[leafletId] = featureLayer;
      }
    }

    pathUpdated(featureLayer);
  };

  L.spatialdev.featurelabel.FeatureSet.prototype._pathUpdated = function (leafletId) {
    var featureLayer = this._pathIdHash[leafletId];
    pathUpdated(featureLayer);
  };

  function pathUpdated(featureLayer) {
    // If the id doesnt hash, no path for the features in are feature set apply.
    if (!featureLayer) {
//      console.error('pathUpdated featureLayer empty');
      return;
    }

    if (featureLayer._layers) {

      // only calculate center after all of the polygons have been updated
      if (!featureLayer.pathsUpdated) featureLayer.pathsUpdated = 0;
      ++featureLayer.pathsUpdated;

      if (featureLayer.pathsUpdated === Object.keys(featureLayer._layers).length) {
        var l = findMostComplexLayer(featureLayer._layers);

        if (l) {
          featureLayer.labelCenterPoint = calculateCenter(l._parts);
          updateLabel(featureLayer);
        }

        featureLayer.pathsUpdated = 0;
      }

    } else {

      // there is only one polygon, so calculate center. also check to see if there are parts
      if ( featureLayer._parts && featureLayer._parts.length ) {
        featureLayer.labelCenterPoint = calculateCenter(featureLayer._parts);
        updateLabel(featureLayer);
      }

    }
  }


  function createLabel(featureLayer) {
    var point = featureLayer.labelCenterPoint;

    var properties = featureLayer.feature.properties;
    var text = properties.title || properties.name || 'Label';
    if (properties.labelProperty) {
      if (typeof properties.labelProperty === 'function') {
        text = properties.labelProperty();
      } else {
        text = properties[properties.labelProperty];
      }

    }

    console.log('LABEL: ' + text + ' (' + point.x + ', ' + point.y + ')');

    var icon = L.divIcon({
      className: 'btn btn-danger featurelabel-icon',
      iconSize: [60,60],
      html: text
    });

    var label = L.label([45,-100], {icon:icon}, point);

    label.on('mouseover', function(e) {
//      yellow EAED6B
      featureLayer.setStyle({
        color: '#EAED6B'
      });
    });

    label.on('mouseout', function(e) {
      featureLayer.setStyle({
        color: properties.color || 'white'
      });
    });

    label.on('click', function (e) {
      // red cross red #ed1b2e
      featureLayer.setStyle({
        color: '#d9534f'
      });
    });


    // NH TODO Add to featureLayer instead but make sure that it's a valid feature layer.
    label.addTo(debug.map);

{'fraction_non_alphanumeric': 0.11895579946603382, 'fraction_numerical': 0.005636309700385643, 'mean_word_length': 2.73987798114254, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1555545', 'n_tokens_mistral': 2022, 'n_tokens_neox': 1920, 'n_words': 447}