Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

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

              
                <!DOCTYPE html>
<html lang="en" >
   <head>
      <meta charset="UTF-8">
      <title>Tiles test and isochrone drawing</title>
   </head>
   <body>
      <!DOCTYPE html>
      <html>
         <meta name="description" content="Class 10 Show+Tell: GeoJson">
         <meta charset="utf-8">
         <meta name="viewport" content="width=device-width">
         <head>
            <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v1.3.0/leaflet.css" />
            <link rel="stylesheet" href="css.css" />
      
            <style>
               html, body, #mapid { 
               height: 100%;
               width: 100%;
               padding: 0;
               margin: 0;
               }
               #error {
                  position: absolute;
                  width: 80%;
                  margin: 0px;
                  z-index: 2000;
                  width: 270px;
                  border-radius: 5px;
                  max-width: 500px;
                  font-family: sans-serif;
                  font-size: 12px;
                  top: 30%;  /* position the top  edge of the element at the middle of the parent */
                  left: 50%; /* position the left edge of the element at the middle of the parent */
                  transform: translate(-50%, -50%);
                  background-color: white;
                  padding: 10px;
                  display: none;
                  text-align: center;
              }
            </style>
            <script src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js"
               integrity="sha512-QVftwZFqvtRNi0ZyCtsznlKSWOStnDORoefr1enyq5mVL4tmKB3S/EnC3rRJcxCPavG10IcrVGSmPh6Qw5lwrg=="
               crossorigin=""></script>
         </head>
         <body>
            <div id="mapid"></div>
         </body>
      </html>
      <div id="error" class="tippy-tooltip honeybee-theme">
         <p><b>No API and APPLICATION_ID key inserted </b></p>
         <p><a target="_blank" href="http://docs.traveltimeplatform.com/overview/getting-keys/">Sign up for an API key</a> 
         <p>Place it in API and APPLICATION_ID variables</p>
      </div>
      <script>
         // The name of the starting location. We will have to geocode this to coordinates.
         var startingLocation = "The White House, DC";
         // The departure time in an ISO format.
         var departureTime = new Date().toJSON();
         // Travel time in seconds. We want 1 hour travel time so it is 60 minutes x 60 seconds.
         var travelTime = 60 * 60;
         // These secret variables are needed to authenticate the request. Get them from http://docs.traveltimeplatform.com/overview/getting-keys/ and replace 
         var APPLICATION_ID = "place your application id here";
         var API_KEY = "place your api key here";
        
         var mymap = L.map('mapid').setView([38.8, -77.0365], 9);
         
         sendGeocodingRequest(startingLocation); 
         
         	L.tileLayer('https://tiles.traveltime.com/lux/{z}/{x}/{y}.png?key=' + APPLICATION_ID, {
attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> | Created with <a href="http://traveltimeplatform.com" target="_blank">TravelTime API</a>',
maxZoom: 18,
tileSize: 512,
zoomOffset: -1            
}).addTo(mymap);
         
         // Sends the geocoding request.
         function sendGeocodingRequest(location) {
           // The request for the geocoder. Reference: http://docs.traveltimeplatform.com/reference/geocoding-search/
           var request = {
             query: location };
           document.getElementById("error").style.display = "none";
           var xhr = new XMLHttpRequest();
           xhr.responseType = "json";
           xhr.open("GET", "https://api.traveltimeapp.com/v4/geocoding/search?query="+ location)
           xhr.setRequestHeader( "X-Application-Id", APPLICATION_ID);
           xhr.setRequestHeader( "X-Api-Key", API_KEY);
           xhr.setRequestHeader( "Accept-Language", " en-US");
           xhr.onreadystatechange = function () {
              if (xhr.status >= 200 && xhr.status < 300) {
                if(xhr.readyState === 4){
                  sendTimeMapRequest(xhr.response)
                }
              } else {
                if(APPLICATION_ID === "place your app id here" || API_KEY ===  "place your api key here") {
                  document.getElementById("error").style.display = "block";
                }
              }
          };
          xhr.send();
          };
         
         // Sends the request of the Time Map multipolygon.
         function sendTimeMapRequest(geocodingResponse) {
         
           // The request for Time Map. Reference: http://docs.traveltimeplatform.com/reference/time-map/
           var coords = geocodingResponse.features[0].geometry.coordinates;
           var latLng = { lat: coords[1], lng: coords[0] };
         
           var request = {
             departure_searches: [{
               id: "first_location",
               coords: latLng,
               transportation: {
                 type: "public_transport" },
         
               departure_time: departureTime,
               travel_time: travelTime }],
         
             arrival_searches: [] };
         
          var xhr = new XMLHttpRequest()
          xhr.addEventListener("readystatechange", function () {
            if (this.readyState === 4) {
              drawTimeMap(mymap, this.response);
            }
          });
          xhr.open("POST", "https://api.traveltimeapp.com/v4/time-map")
          xhr.setRequestHeader("X-Application-Id", APPLICATION_ID);
          xhr.setRequestHeader("X-Api-Key", API_KEY);
          xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
          xhr.responseType = "json";
          xhr.send(JSON.stringify(request));
         
         // A helper function that converts [{lat: <lat>, lng: <lng>}, ...] to a [[<lat>, <lng>], ...] format.
         function ringCoordsHashToArray(ring) {
           return ring.map(function (latLng) {return [latLng.lat, latLng.lng];});
         };
         
         // Draws the resulting multipolygon from the response on the map.
         function drawTimeMap(map, response) {
         
             // Reference for the response: http://docs.traveltimeplatform.com/reference/time-map/#response-body-json-attributes
             var shapesCoords = response.results[0].shapes.map(function (polygon) {
               var shell = ringCoordsHashToArray(polygon.shell);
               var holes = polygon.holes.map(ringCoordsHashToArray);
               return [shell].concat(holes);
             });
             var polygon = L.polygon(shapesCoords, { color: 'red' });
             polygon.addTo(map);
             map.fitBounds(polygon.getBounds());
         };
         }
            
      </script>
   </body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console