<commit_before>(function () {
  'use strict';

  angular
    .module('app')
    .factory('MapDrawFactory', MapDrawFactory);

  MapDrawFactory.$inject = ['$document', '$ionicPopup', '$location', '$log', '$q', '$rootScope', 'SpotFactory'];

  function MapDrawFactory($document, $ionicPopup, $location, $log, $q, $rootScope, SpotFactory) {
    var draw;               // draw is a ol3 drawing interaction
    var drawButtonActive;   // drawButtonActive used to keep state of which selected drawing tool is active
    var drawLayer;
    var featuresOrig = [];
    var imageBasemap;       // id of an image basemap if an image basemap is being used
    var isFreeHand;
    var map;
    var modify;
    var spotsEdited = [];    // array of spots edited with the edit button

    // Variables for a long press event
    var longpress = false;
    var endTime;
    var startTime;

    return {
      'cancelEdits': cancelEdits,
      'doOnDrawEnd': doOnDrawEnd,
      'DrawControls': DrawControls,
      'getDrawMode': getDrawMode,
      'groupSpots': groupSpots,
      'isDrawMode': isDrawMode,
      'saveEdits': saveEdits
    };

    /**
     * Private Functions
     */

    // Remove draw interaction
    function cancelDraw() {
      if (draw !== null) {
        map.removeInteraction(draw);
        draw = null;
        drawButtonActive = null;
      }
    }

    function enableDrawMode(inIsFreeHand, type) {
      isFreeHand = inIsFreeHand;
      if (isFreeHand) {
        // yes -- then disable the map drag pan
        map.getInteractions().forEach(function (interaction) {
          if (interaction instanceof ol.interaction.DragPan) {
            $log.log(interaction);
            map.getInteractions().remove(interaction);
          }
        });
        draw = new ol.interaction.Draw({
          'source': drawLayer.getSource(),
          'type': type,
          'condition': ol.events.condition.singleClick,
          'freehandCondition': ol.events.condition.noModifierKeys,
          'snapTolerance': 96
        });
      }
      else {
        draw = new ol.interaction.Draw({
          'source': drawLayer.getSource(),
          'type': type
        });
      }
      map.addInteraction(draw);
      $rootScope.$broadcast('changedDrawMode');
    }

    function enableEditMode() {
      var features = [];
      featuresOrig = [];
      map.getLayers().forEach(function (layerGroup) {
        if (layerGroup.get('name') === 'featureLayer') {
          layerGroup.getLayers().forEach(function (layer) {
            features.push.apply(features, layer.getSource().getFeatures());
          });
          modify = new ol.interaction.Modify({
            'features': new ol.Collection(features),
            // the SHIFT key must be pressed to delete vertices, so
            // that new vertices can be drawn at the same position
            // of existing vertices
            'deleteCondition': function (event) {
              return (ol.events.condition.shiftKeyOnly(event) && ol.events.condition.singleClick(event)) ||
                (longpress && ol.events.condition.singleClick(event));
            }
          });
        }
      });
      map.addInteraction(modify);
      $rootScope.$broadcast('enableSaveEdits', true);

      // Create a trigger for a change in any of the features
      features.forEach(function (feature) {
        featuresOrig.push(feature.clone());
        feature.on('change', function (e) {
          var spot = SpotFactory.getSpotById(e.target.get('id'));

          var newGeom = e.target.get('geometry');
          var newCoords = newGeom.getCoordinates();
          if (!imageBasemap) {
            switch (newGeom.getType()) {
              case 'Point':
                newCoords = ol.proj.toLonLat(newCoords);<commit_msg>fixed bug with map edits not being saved<commit_after>(function () {
  'use strict';

  angular
    .module('app')
    .factory('MapDrawFactory', MapDrawFactory);

  MapDrawFactory.$inject = ['$document', '$ionicPopup', '$location', '$log', '$q', '$rootScope', 'SpotFactory'];

  function MapDrawFactory($document, $ionicPopup, $location, $log, $q, $rootScope, SpotFactory) {
    var draw;               // draw is a ol3 drawing interaction
    var drawButtonActive;   // drawButtonActive used to keep state of which selected drawing tool is active
    var drawLayer;
    var featuresOrig = [];
    var imageBasemap;       // id of an image basemap if an image basemap is being used
    var isFreeHand;
    var map;
    var modify;
    var spotsEdited = [];    // array of spots edited with the edit button

    // Variables for a long press event
    var longpress = false;
    var endTime;
    var startTime;

    return {
      'cancelEdits': cancelEdits,
      'doOnDrawEnd': doOnDrawEnd,
      'DrawControls': DrawControls,
      'getDrawMode': getDrawMode,
      'groupSpots': groupSpots,
      'isDrawMode': isDrawMode,
      'saveEdits': saveEdits
    };

    /**
     * Private Functions
     */

    // Remove draw interaction
    function cancelDraw() {
      if (draw !== null) {
        map.removeInteraction(draw);
        draw = null;
        drawButtonActive = null;
      }
    }

    function enableDrawMode(inIsFreeHand, type) {
      isFreeHand = inIsFreeHand;
      if (isFreeHand) {
        // yes -- then disable the map drag pan
        map.getInteractions().forEach(function (interaction) {
          if (interaction instanceof ol.interaction.DragPan) {
            $log.log(interaction);
            map.getInteractions().remove(interaction);
          }
        });
        draw = new ol.interaction.Draw({
          'source': drawLayer.getSource(),
          'type': type,
          'condition': ol.events.condition.singleClick,
          'freehandCondition': ol.events.condition.noModifierKeys,
          'snapTolerance': 96
        });
      }
      else {
        draw = new ol.interaction.Draw({
          'source': drawLayer.getSource(),
          'type': type
        });
      }
      map.addInteraction(draw);
      $rootScope.$broadcast('changedDrawMode');
    }

    function enableEditMode() {
      var features = [];
      featuresOrig = [];
      map.getLayers().forEach(function (layerGroup) {
        if (layerGroup.get('name') === 'featureLayer') {
          layerGroup.getLayers().forEach(function (layer) {
            features.push.apply(features, layer.getSource().getFeatures());
          });
          modify = new ol.interaction.Modify({
            'features': new ol.Collection(features),
            // the SHIFT key must be pressed to delete vertices, so
            // that new vertices can be drawn at the same position
            // of existing vertices
            'deleteCondition': function (event) {
              return (ol.events.condition.shiftKeyOnly(event) && ol.events.condition.singleClick(event)) ||
                (longpress && ol.events.condition.singleClick(event));
            }
          });
        }
      });
      map.addInteraction(modify);
      $rootScope.$broadcast('enableSaveEdits', true);

      // Create a trigger for a change in any of the features
      features.forEach(function (feature) {
        featuresOrig.push(feature.clone());
        feature.on('change', function (e) {
          var spot = JSON.parse(JSON.stringify(SpotFactory.getSpotById(e.target.get('id'))));

          var newGeom = e.target.get('geometry');
          var newCoords = newGeom.getCoordinates();
          if (!imageBasemap) {
            switch (newGeom.getType()) {
              case 'Point':
                newCoords = ol.proj.toLonLat(newCoords);
{'fraction_non_alphanumeric': 0.12156295224312591, 'fraction_numerical': 0.0007893698197605578, 'mean_word_length': 2.2293967714528464, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6865103', 'n_tokens_mistral': 2127, 'n_tokens_neox': 2087, 'n_words': 516}