<commit_before>var vehiclesGeoJSON = function(callback) {
  var url = "https://api.digitransit.fi/realtime/vehicle-positions/v1/hfp/journey/tram/";

  $.getJSON(url, function(data, status, xhr) {
    var geoJSON = {
        "type": "geojson",
        "data": {
            "type": "FeatureCollection",
            "features": []
        }
    }

    Object.keys(data).forEach(function(id){
      var vehicle = data[id].VP;

      geoJSON.data.features.push({
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [vehicle.long, vehicle.lat]
        },
        "properties": {
            "title": vehicle.line.replace(/^10+/, ""),
            "marker-symbol": "marker",
            "vehicle-id": vehicle.veh
        }
      });
    });

    callback(geoJSON)
  });
}

$(document).on("turbolinks:load", function() {
  if ($("#full-map").length) {
    mapboxgl.accessToken = "<KEY>";
    var map = new mapboxgl.Map({
      container: "full-map",
      style: "mapbox://styles/mapbox/streets-v8",
      center: [24.9384, 60.1800],
      zoom: 11,
      minZoom: 5,
      maxZoom: 20
    });

    map.addControl(new mapboxgl.Navigation());

    map.fitBounds([
      [
        24.858627319335938,
        60.14526490373431
      ], // Southwest coordinates
      [
        24.991493225097656,
        60.21952545753577
      ]  // Northeast coordinates
    ]);

    map.on("load", function () {
      // Load the tram routes

      var routes = JSON.parse($("script[data-contents='tram-routes']").html());

      $.each(routes["features"], function(i, feature) {
        var id = "tram-route-" + feature["properties"]["route"];
        map.addSource(id, {
          "type": "geojson",
          "data": {
            "type": "FeatureCollection",
            "features": [feature]
          }
        });

        map.addLayer({
          "id": id,
          "type": "line",
          "source": id,
          "layout": {
            "line-join": "round",
            "line-cap": "round"
          },
          "paint": {
            "line-color": feature["properties"]["route-color"],
            "line-width": 2,
            "line-opacity": 0.9
          }
        }, "vehicle-markers");
      });

      // Load the tram stops

      var stopsJSON = JSON.parse($("script[data-contents='stops']").html());

      map.addSource("stop-markers", {
        "type": "geojson",
        "data": stopsJSON
      });

      map.addLayer({
        "id": "stop-markers",
        "type": "circle",
        "source": "stop-markers",
        "paint": {
          "circle-radius": 3,
          "circle-color": "#626262",
          "circle-opacity": 0.8
        }
      }, "vehicle-markers");
    })

    map.on("load", function () {
      vehiclesGeoJSON(function(geoJSON) {
        map.addSource("vehicle-markers", geoJSON);
        map.addLayer({
          "id": "vehicle-markers",
          "type": "symbol",
          "source": "vehicle-markers",
          "layout": {
            "icon-image": "{marker-symbol}-11",
            "text-field": "{title}",
            "text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"],
            "text-offset": [0, 0.6],
            "text-anchor": "top"
          }
        });
      });

      setInterval(function() {
        vehiclesGeoJSON(function(newJSON) {
          map.getSource("vehicle-markers").setData(newJSON.data);
        })
      }, 1000)

      if ("geolocation" in navigator) {
        var geolocation = new mapboxgl.Geolocate({position: "top-left"});
        map.addControl(geolocation);

        map.addSource("current-location", {<commit_msg>Clear the vehicle polling interval on page load<commit_after>var vehiclesGeoJSON = function(callback) {
  var url = "https://api.digitransit.fi/realtime/vehicle-positions/v1/hfp/journey/tram/";

  $.getJSON(url, function(data, status, xhr) {
    var geoJSON = {
        "type": "geojson",
        "data": {
            "type": "FeatureCollection",
            "features": []
        }
    }

    Object.keys(data).forEach(function(id){
      var vehicle = data[id].VP;

      geoJSON.data.features.push({
        "type": "Feature",
        "geometry": {
            "type": "Point",
            "coordinates": [vehicle.long, vehicle.lat]
        },
        "properties": {
            "title": vehicle.line.replace(/^10+/, ""),
            "marker-symbol": "marker",
            "vehicle-id": vehicle.veh
        }
      });
    });

    callback(geoJSON)
  });
}

$(document).on("turbolinks:load", function() {
  if (window.vehiclesIntervalID) {
    window.clearInterval(vehiclesIntervalID);
  }

  if ($("#full-map").length) {
    mapboxgl.accessToken = "<KEY>";
    var map = new mapboxgl.Map({
      container: "full-map",
      style: "mapbox://styles/mapbox/streets-v8",
      center: [24.9384, 60.1800],
      zoom: 11,
      minZoom: 5,
      maxZoom: 20
    });

    map.addControl(new mapboxgl.Navigation());

    map.fitBounds([
      [
        24.858627319335938,
        60.14526490373431
      ], // Southwest coordinates
      [
        24.991493225097656,
        60.21952545753577
      ]  // Northeast coordinates
    ]);

    map.on("load", function () {
      // Load the tram routes

      var routes = JSON.parse($("script[data-contents='tram-routes']").html());

      $.each(routes["features"], function(i, feature) {
        var id = "tram-route-" + feature["properties"]["route"];
        map.addSource(id, {
          "type": "geojson",
          "data": {
            "type": "FeatureCollection",
            "features": [feature]
          }
        });

        map.addLayer({
          "id": id,
          "type": "line",
          "source": id,
          "layout": {
            "line-join": "round",
            "line-cap": "round"
          },
          "paint": {
            "line-color": feature["properties"]["route-color"],
            "line-width": 2,
            "line-opacity": 0.9
          }
        }, "vehicle-markers");
      });

      // Load the tram stops

      var stopsJSON = JSON.parse($("script[data-contents='stops']").html());

      map.addSource("stop-markers", {
        "type": "geojson",
        "data": stopsJSON
      });

      map.addLayer({
        "id": "stop-markers",
        "type": "circle",
        "source": "stop-markers",
        "paint": {
          "circle-radius": 3,
          "circle-color": "#626262",
          "circle-opacity": 0.8
        }
      }, "vehicle-markers");
    })

    map.on("load", function () {
      vehiclesGeoJSON(function(geoJSON) {
        map.addSource("vehicle-markers", geoJSON);
        map.addLayer({
          "id": "vehicle-markers",
          "type": "symbol",
          "source": "vehicle-markers",
          "layout": {
            "icon-image": "{marker-symbol}-11",
            "text-field": "{title}",
            "text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"],
            "text-offset": [0, 0.6],
            "text-anchor": "top"
          }
        });
      });

      window.vehiclesIntervalID = setInterval(function() {
        vehiclesGeoJSON(function(newJSON) {
          map.getSource("vehicle-markers").setData(newJSON.data);
        })
      }, 1000)

      if ("geolocation" in navigator) {
        var geolocation = new mapboxgl.Geolocate({position: "top-left"});
        map.addControl(geolocation);

        map.addSource("current-location", {
{'fraction_non_alphanumeric': 0.17522861753630983, 'fraction_numerical': 0.029047875201721356, 'mean_word_length': 1.8418035918991211, 'pattern_counts': {'":': 88, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '2860686', 'n_tokens_mistral': 2484, 'n_tokens_neox': 2291, 'n_words': 389}