cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <body style="margin: 0px 0px">
  <div id="map_isochrone" style="height:100vh;"/>
</body>
            
          
!
            
              $(function(){
  var map = L.map('map_isochrone',{
    scrollWheelZoom : false
  }).setView([50.85, 4.4], 8);
  L.tileLayer('https://{s}.tile.thunderforest.com/transport/{z}/{x}/{y}.png', {
    attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
  }).addTo(map);

  //Create our stations list on the basis of the iRail API
  var stations = {};
  var markers = {
    "8892007" : true,//Gent
    "8891009" : true,//Luik
    "8841004" : true,//Brugge
    "8821006" : true,//Antwerpen
    "8863008" : true,//Namur
    "8844404" : true,//Spa
    "8866258" : true,//Neuf-Château
    "8866001" : true,//Arlon
    "8812005" : true //Brussel Noord
  };
  
  $.get("https://api.irail.be/stations.php?format=json", function (stationslist) {
    stationslist.station.forEach(function (station) {
      var key = station["@id"].replace('http://irail.be/stations/NMBS/00','');
      stations[key] = {
        longitude : station.locationX,
        latitude : station.locationY,
        name : station.name,
        '@id' : station['@id'],
        point : new L.LatLng(station.locationY, station.locationX)
      };
      if (markers[key]) {
        markers[key] = L.marker([station.locationY, station.locationX]).addTo(map);
        markers[key].on("click", function () {
          handleClick(key, markers[key]);
        });
      }
    });
    
    var startIcon = L.icon({
      iconUrl : 'http://linkedconnections.org/images/marker-icon-start.png',
      iconRetinaUrl: 'http://linkedconnections.org/images/marker-icon-2x-start.png'
    });

    L.Icon.Default.iconUrl = 'http://linkedconnections.org/images/marker-icon.png';
    L.Icon.Default.iconRetinaUrl = 'http://linkedconnections.org/images/marker-icon-2x.png';
    
    var planner = new window.lc.Client({"entrypoints" : ["http://belgianrail.linkedconnections.org/"]});
    var departureStop = "";
    var arrivalStop = "";
    var handleClick = function (station, marker) {
      if (departureStop === "") {
        for (key in markers) {
          map.removeLayer(markers[key]);
        }
        marker.addTo(map);
        marker.setIcon(startIcon);
        departureStop = station;
        var startTime = new Date("2015-10-01T10:00Z");
        planner.query({
          "departureStop": departureStop,
          "departureTime": startTime
        }, function (stream) {
          var drawIsochrone = function (howFarHours, color, connection) {
            var secondsFromStart = (connection.arrivalTime - startTime)/1000;              
            var howFar = (howFarHours)*60*60; //how far can we get in 3 hours
            var radius = (howFar - secondsFromStart)*1.39; //we assume 1.39m/s as a walking speed
            if (radius < 0) {
              planner.end();
            }
            L.circle(connection.arrivalStop.point, radius, {
              color: color,
              stroke : false,
              weight: 1,
              fillOpacity: 0.10,
              fillRule : "nonzero"
            }).addTo(map);
          };
          var trips = {};
          var countTrips = 0;
          stream.on('data', function (connection) {
            if (stations[connection.arrivalStop] && stations[connection.departureStop]) {
              connection.arrivalStop = stations[connection.arrivalStop];
              connection.departureStop = stations[connection.departureStop];
              //circle for the isochrone to be drawn
              //Keep an occurence of different trips and give a new colour per trip
              drawIsochrone(2,'#b2182b',connection);
              //polyline for the path visualization
              var polyline = new L.Polyline([connection.departureStop.point, connection.arrivalStop.point], {
                color: "red",
                weight: 2.5,
                smoothFactor: 1
              }).addTo(map);
            } else {
              connection.arrivalStop = {
                name : connection.arrivalStop
              };
              connection.departureStop = {
                name : connection.arrivalStop
              };
            }
          });
          
          stream.on('error', function (error) {
            console.error(error);
          });
          stream.on('end', function () {
            console.log('end of stream');
          });
        });
      }
    };

  });
});
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console