<commit_before>'use strict';

var L = require('leaflet');
L.Icon.Default.imagePath = '/images/leaflet';
var AmpersandView = require('ampersand-view');
var template = require('./templates/map');

var apikey = '<KEY>';
var DeactivatedIcon = L.Icon.Default.extend({
  options: {
    iconUrl: '/images/leaflet/marker-icon_deact.png',
    iconRetinaUrl: '/images/leaflet/marker-icon-2x_deact.png'
  }
});


module.exports = AmpersandView.extend({
  autoRender: true,
  template: template,

  initialize: function() {
    this.listenTo(this.collection, 'sync', this.addMarkers);
    this.listenTo(app.user, 'change position', this.setUserPosition);
    this.listenTo(app.user, 'change targetId', function() {
      if (app.user.targetId) {
        this.addMarkers();
        this.showTarget();
      }
    });

    this.deactivatedIcon = new DeactivatedIcon();
  },

  render: function() {
    this.renderWithTemplate();
  },

  renderMap: function() {
    this.map = L.map(this.queryByHook('map'), {zoomControl: false});
    new L.Control.Zoom({position: 'bottomright'}).addTo(this.map);
    var tp;

    if (L.Browser.retina) {
      tp = 'lr';
    }
    else {
      tp = 'ls';
    }

    L.tileLayer('http://tiles.lyrk.org/' + tp + '/{z}/{x}/{y}?apikey=' + apikey,
     {
       attribution: '<a href="http://leafletjs.com" title="A JS library for ' +
                    'interactive maps">Leaflet</a> | Data: ' +
                    '<a href="http://www.overpass-api.de/">OverpassAPI</a>' +
                    ' OpenStreetMap | <a href="http://geodienste.lyrk.de/" ' +
                    'target="_blank">Tiles by Lyrk</a> | <a href="http://' +
                    'geodienste.lyrk.de/copyright">Lizenzinformationen</a>' +
                    '</div>',
       maxZoom: 18
     }).addTo(this.map);

    this.map.on('locationfound', this.setUserPosition, this);
    this.map.locate({setView: true, maxZoom: 16});
  },

  addMarkers: function(e) {
    if (this.markers) {
      this.map.removeLayer(this.markers);
    }

    this.markers = new L.FeatureGroup();
    this.map.addLayer(this.markers);

    this.collection.each(function(mapNode, index) {
      if (app.user.targetId) {
        if (mapNode.osmId === app.user.targetId) {
          this.addMarker(mapNode.toCoords());
        } else {
          this.addMarker(mapNode.toCoords(), {deactivated: true});
        }
      } else {
        this.addMarker(mapNode.toCoords());
      }

    }, this);
  },

  addMarker: function(coords, markerOptions)  {
    var options = markerOptions || {};
    var marker;

    if (options.deactivated === true) {
      marker = L.marker([coords.lat, coords.lon], {icon: this.deactivatedIcon});
    } else {
      marker = L.marker([coords.lat, coords.lon]);
    }

    marker.addTo(this.markers);<commit_msg>Added functionality to select target from Marker on Map)<commit_after>'use strict';

var L = require('leaflet');
L.Icon.Default.imagePath = '/images/leaflet';
var AmpersandView = require('ampersand-view');
var template = require('./templates/map');

var apikey = '<KEY>';
var DeactivatedIcon = L.Icon.Default.extend({
  options: {
    iconUrl: '/images/leaflet/marker-icon_deact.png',
    iconRetinaUrl: '/images/leaflet/marker-icon-2x_deact.png'
  }
});


module.exports = AmpersandView.extend({
  autoRender: true,
  template: template,

  initialize: function() {
    this.listenTo(this.collection, 'sync', this.addMarkers);
    this.listenTo(app.user, 'change position', this.setUserPosition);
    this.listenTo(app.user, 'change targetId', function() {
      if (app.user.targetId) {
        this.addMarkers();
        this.showTarget();
      }
    });

    this.deactivatedIcon = new DeactivatedIcon();
  },

  render: function() {
    this.renderWithTemplate();
  },

  renderMap: function() {
    this.map = L.map(this.queryByHook('map'), {zoomControl: false});
    new L.Control.Zoom({position: 'bottomright'}).addTo(this.map);
    var tp;

    if (L.Browser.retina) {
      tp = 'lr';
    }
    else {
      tp = 'ls';
    }

    L.tileLayer('http://tiles.lyrk.org/' + tp + '/{z}/{x}/{y}?apikey=' + apikey,
     {
       attribution: '| Data: ' +
                    '<a href="http://www.overpass-api.de/">OverpassAPI</a>' +
                    ' OpenStreetMap | <a href="http://geodienste.lyrk.de/" ' +
                    'target="_blank">Tiles by Lyrk</a> | <a href="http://' +
                    'geodienste.lyrk.de/copyright">Lizenzinformationen</a>' +
                    '</div>',
       maxZoom: 18
     }).addTo(this.map);

    this.map.on('locationfound', this.setUserPosition, this);
    this.map.locate({setView: true, maxZoom: 16});
  },

  addMarkers: function(e) {
    if (this.markers) {
      this.map.removeLayer(this.markers);
    }

    this.markers = new L.FeatureGroup();
    this.map.addLayer(this.markers);

    this.collection.each(function(mapNode, index) {
      if (app.user.targetId) {
        if (mapNode.osmId === app.user.targetId) {
          this.addMarker(mapNode);
        } else {
          this.addMarker(mapNode, {deactivated: true});
        }
      } else {
        this.addMarker(mapNode);
      }

    }, this);
  },

  addMarker: function(mapNode, markerOptions)  {
    var options = markerOptions || {};
    var marker;
    var coords = mapNode.toCoords();

    if (options.deactivated === true) {
      marker = L.marker([coords.lat, coords.lon], {icon: this.deactivatedIcon});
    } else {
      marker = L.marker([coords.lat, coords.lon]);
    }

    marker.addTo(this.markers);

    marker.on('click', function() {
      app.user.targetId = mapNode.osmId;
    });
{'fraction_non_alphanumeric': 0.1715860597439545, 'fraction_numerical': 0.0017780938833570413, 'mean_word_length': 2.589661774090619, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '4419241', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1880, 'n_words': 310}