<commit_before>/* Copyright (c) 2012-2016 The TagSpaces Authors. All rights reserved.
 * Use of this source code is governed by a AGPL3 license that
 * can be found in the LICENSE file. */

/* global define, Handlebars, isNode, isFirefox */
define(function(require, exports, module) {
  'use strict';
  console.log('Loading map.ui.js ...');

  var TSCORE = require('tscore');
  var TSPOSTIO = require("tspostioapi");

  require('leaflet');
  require('leafletlocate');

  // TagSpaces Map
  function getLocation() {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(showPosition, showLocationNotFound);
    } else {
      TSCORE.showAlertDialog("Geolocation is not supported by this browser.");
    }
  }

  function showPosition(position) {
    var lat = position.coords.latitude;
    var long = position.coords.longitude;
  }

  function showLocationNotFound(error) {
    switch (error.code) {
      case error.PERMISSION_DENIED:
        TSCORE.showAlertDialog("User denied the request for Geolocation.");
        break;
      case error.POSITION_UNAVAILABLE:
        TSCORE.showAlertDialog("Location information is unavailable.");
        break;
      case error.TIMEOUT:
        TSCORE.showAlertDialog("The request to get user location timed out.");
        break;
    }
  }

  var MB_ATTR = 'Map data &copy; <a href="http://tagspaces.org">TagSpaces</a>';
  var OSM_URL = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
  var OSM_ATTRIB = '';
  var tagSpacesMapOptions = {
    //layers: [MB_ATTR],
    zoomControl: true,
    detectRetina: true
  };
  var tagSpacesMap = L.map('mapTag', tagSpacesMapOptions);
  var tileLayer = L.tileLayer(OSM_URL, {
    attribution: MB_ATTR,
    id: 'tagSpacesMap'
  });
  var marker;
  //
  //var trackMe = L.control.locate({
  //  position: 'topright',
  //  strings: {
  //    title: $.i18n.t('ns.dialogs:yourLocation') //
  //  }
  //}).addTo(tagSpacesMap);
  var currentLat, currentLng;

  function splitValue(value, index) {
    currentLat = value.substring(0, index);
    currentLng = value.substring(index);

    return parseFloat(currentLat) + "," + parseFloat(currentLng);
  }

  function showViewLocation() {
    tagSpacesMap.setView(new L.LatLng(51.51, 27.95), 3);
  }

  function showGeoLocation(coordinate) {
    showViewLocation();
    tileLayer.addTo(tagSpacesMap);
    var regExp = /^([-+]?)([\d]{1,2})(((\.)(\d+)(,)))(\s*)(([-+]?)([\d]{1,3})((\.)(\d+))?)$/g;

    var currentCoordinate;
    if (coordinate.lastIndexOf('+') !== -1) {
      currentCoordinate = splitValue(coordinate, coordinate.lastIndexOf('+'));
    } else if (coordinate.lastIndexOf('-') !== -1) {
      currentCoordinate = splitValue(coordinate, coordinate.lastIndexOf('-'));
    }
    var geoTag = TSCORE.selectedTag === 'geoTag';

    if (geoTag) {
      showViewLocation();
    }

    if (regExp.exec(currentCoordinate)) {
      tagSpacesMap.setView([currentLat, currentLng], 13);

      var getCoord = L.latLng(currentLat, currentLng);
      addMarker(getCoord);
    } else {
      showViewLocation();
      //tagSpacesMap.setView([54.5259614, +15.2551187], 5);
    }
  }

  function addMarker(currentCoord) {
    //var getLatLng = L.latLng(currentLat, currentLng);

    // Add marker to map at click location; add popup window
    if (typeof marker === 'undefined') {
      if (currentCoord.latlng) {
        marker = new L.marker(currentCoord.latlng, {
          draggable: true,
          showOnMouseOver: true
        }).update();
      } else {
        marker = new L.marker(currentCoord, {
          draggable: true,
          showOnMouseOver: true
        }).update();
      }
      marker.addTo(tagSpacesMap);
    } else {
      if (currentCoord.latlng) {
        marker.setLatLng(currentCoord.latlng);
      } else {
        marker.setLatLng(currentCoord);
      }
    }
  }

  function removeMarker(e) {
    //tagSpacesMap.removeLayer(marker);
    //if (tagSpacesMap.removeLayer(marker)) {
    //  console.log("MARKER REMOVED");
    //}
    //tagSpacesMap.clearLayers(marker);
  }

  var lat, lng;
  var latlng;

  function onMapClick(e) {
    addMarker(e);
    parseCoordinateMap(e);
    lat = e.latlng.lat.toFixed(7);
    console.log("ON map click:lng" + lat);
    lng = e.latlng.lng.toFixed(7);
    console.log("ON map click:lng" + lng);
  }

  function parseCoordinateMap(e) {
    var date = $('#dateInputCalendar')[0];
    var long = lng >= 0 ? '+' + lng : lng;
    var dateValue = e.latlng.lat.toFixed(7) + "" + long;
    date.value = dateValue.trim();
    console.log(date.value);
    console.log("Date value" + lng);
  }

  function onLocationFound() {
    tagSpacesMap.locate({
      setView: true,
      watch: true
    }) /* This will return map so you can do chaining */.on('locationfound', function(e) {
      var marker = L.marker([e.latitude, e.longitude]).bindPopup('Current position', {showOnMouseOver: true});
      var circle = L.circle([e.latitude, e.longitude], e.accuracy / 2, {
        weight: 1,
        color: 'blue',
        fillColor: '#cacaca',
        fillOpacity: 0.2
      });<commit_msg>update: calendar.ui<commit_after>/* Copyright (c) 2012-2016 The TagSpaces Authors. All rights reserved.
 * Use of this source code is governed by a AGPL3 license that
 * can be found in the LICENSE file. */

/* global define, Handlebars, isNode, isFirefox */
define(function(require, exports, module) {
  'use strict';
  console.log('Loading map.ui.js ...');

  var TSCORE = require('tscore');
  var TSPOSTIO = require("tspostioapi");

  require('leaflet');
  require('leafletlocate');

  // TagSpaces Map
  function getLocation() {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(showPosition, showLocationNotFound);
    } else {
      TSCORE.showAlertDialog("Geolocation is not supported by this browser.");
    }
  }

  function showPosition(position) {
    var lat = position.coords.latitude;
    var long = position.coords.longitude;
  }

  function showLocationNotFound(error) {
    switch (error.code) {
      case error.PERMISSION_DENIED:
        TSCORE.showAlertDialog("User denied the request for Geolocation.");
        break;
      case error.POSITION_UNAVAILABLE:
        TSCORE.showAlertDialog("Location information is unavailable.");
        break;
      case error.TIMEOUT:
        TSCORE.showAlertDialog("The request to get user location timed out.");
        break;
    }
  }

  var MB_ATTR = 'Map data &copy; <a href="http://tagspaces.org">TagSpaces</a>';
  var OSM_URL = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
  var OSM_ATTRIB = '';
  var tagSpacesMapOptions = {
    //layers: [MB_ATTR],
    zoomControl: true,
    detectRetina: true
  };
  var tagSpacesMap = L.map('mapTag', tagSpacesMapOptions);
  var tileLayer = L.tileLayer(OSM_URL, {
    attribution: MB_ATTR,
    id: 'tagSpacesMap'
  });
  var marker;
  //
  //var trackMe = L.control.locate({
  //  position: 'topright',
  //  strings: {
  //    title: $.i18n.t('ns.dialogs:yourLocation') //
  //  }
  //}).addTo(tagSpacesMap);
  var currentLat, currentLng;

  function splitValue(value, index) {
    currentLat = value.substring(0, index);
    currentLng = value.substring(index);

    return parseFloat(currentLat) + "," + parseFloat(currentLng);
  }

  function showViewLocation() {
    tagSpacesMap.setView(new L.LatLng(51.51, 27.95), 3);
  }

  function showGeoLocation(coordinate) {
    showViewLocation();
    tileLayer.addTo(tagSpacesMap);
    var regExp = /^([-+]?)([\d]{1,2})(((\.)(\d+)(,)))(\s*)(([-+]?)([\d]{1,3})((\.)(\d+))?)$/g;

    var currentCoordinate;
    if (coordinate.lastIndexOf('+') !== -1) {
      currentCoordinate = splitValue(coordinate, coordinate.lastIndexOf('+'));
    } else if (coordinate.lastIndexOf('-') !== -1) {
      currentCoordinate = splitValue(coordinate, coordinate.lastIndexOf('-'));
    }
    var geoTag = TSCORE.selectedTag === 'geoTag';

    if (geoTag) {
      showViewLocation();
    }

    if (regExp.exec(currentCoordinate)) {
      tagSpacesMap.setView([currentLat, currentLng], 13);

      var getCoord = L.latLng(currentLat, currentLng);
      addMarker(getCoord);
    } else {
      showViewLocation();
      //tagSpacesMap.setView([54.5259614, +15.2551187], 5);
    }
  }

  function addMarker(currentCoord) {
    //var getLatLng = L.latLng(currentLat, currentLng);

    // Add marker to map at click location; add popup window
    if (typeof marker === 'undefined') {
      if (currentCoord.latlng) {
        marker = new L.marker(currentCoord.latlng, {
          draggable: true,
          showOnMouseOver: true
        }).update();
      } else {
        marker = new L.marker(currentCoord, {
          draggable: true,
          showOnMouseOver: true
        }).update();
      }
      marker.addTo(tagSpacesMap);
    } else {
      if (currentCoord.latlng) {
        marker.setLatLng(currentCoord.latlng);
      } else {
        marker.setLatLng(currentCoord);
      }
    }
  }

  function removeMarker(e) {
    //tagSpacesMap.removeLayer(marker);
    //if (tagSpacesMap.removeLayer(marker)) {
    //  console.log("MARKER REMOVED");
    //}
    //tagSpacesMap.clearLayers(marker);
  }

  var lat, lng;
  var latlng;

  function onMapClick(e) {
    addMarker(e);
    parseCoordinateMap(e);
    lat = e.latlng.lat.toFixed(7);
    lng = e.latlng.lng.toFixed(7);
  }

  function parseCoordinateMap(e) {
    var date = $('#dateInputCalendar')[0];
    var long = lng >= 0 ? '+' + lng : lng;
    var dateValue = e.latlng.lat.toFixed(7) + "" + long;
    date.value = dateValue.trim();
  }

  function onLocationFound() {
    tagSpacesMap.locate({
      setView: true,
      watch: true
    }) /* This will return map so you can do chaining */.on('locationfound', function(e) {
      var marker = L.marker([e.latitude, e.longitude]).bindPopup('Current position', {showOnMouseOver: true});
      var circle = L.circle([e.latitude, e.longitude], e.accuracy / 2, {
        weight: 1,
        color: 'blue',
        fillColor: '#cacaca',
        fillOpacity: 0.2
      });
{'fraction_non_alphanumeric': 0.15248156268686466, 'fraction_numerical': 0.011361371337452662, 'mean_word_length': 2.912280701754386, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4846711', 'n_tokens_mistral': 3487, 'n_tokens_neox': 3362, 'n_words': 679}