Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body style="margin: 0px 0px">
  <div id="map_isochrone" style="height:100vh;"/>
</body>
              
            
!

CSS

              
                
              
            
!

JS

              
                $(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 = {
    "http://irail.be/stations/NMBS/008892007" : true,//Gent
    "http://irail.be/stations/NMBS/008891009" : true,//Luik
    "http://irail.be/stations/NMBS/008841004" : true,//Brugge
    "http://irail.be/stations/NMBS/008821006" : true,//Antwerpen
    "http://irail.be/stations/NMBS/008863008" : true,//Namur
    "http://irail.be/stations/NMBS/008844404" : true,//Spa
    "http://irail.be/stations/NMBS/008866258" : true,//Neuf-Château
    "http://irail.be/stations/NMBS/008866001" : true,//Arlon
    "http://irail.be/stations/NMBS/008812005" : true //Brussel Noord
  };
  var blueIcon = L.icon({
      iconUrl : 'https://linkedconnections.org/images/marker-icon.png',
//      iconRetinaUrl : 'https://linkedconnections.org/images/marker-icon-2x.png',
      iconAnchor: [12, 41]
    });
  $.get("https://api.irail.be/stations.php?format=json", function (stationslist) {
    stationslist.station.forEach(function (station) {
      var key = station["@id"];
      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]).setIcon(blueIcon).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" : ["https://graph.irail.be/sncb/connections"]});
    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();
        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

Console