HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>Drawing isochrones</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="https://unpkg.com/leaflet@1.8.0/dist/leaflet.css"
integrity="sha512-hoalWLoI8r4UszCkZ5kL8vayOGVae1oxXe/2A4AO6J9+580uKHDO3JdHb7NzwwzK5xr/Fs0W40kiNHxM9vyTtQ=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.8.0/dist/leaflet.js"
integrity="sha512-BB3hKbKWOc9Ez/TAwyWxNXeoV9c1v6FIeYiBieIWkpLjauysF18NzgR1MBNBXf8/KABdlkX68nAhlwcDFLGPCQ=="
crossorigin=""></script>
<style>
html, body, #mapid {
height: 100%;
width: 100%;
padding: 0;
margin: 0;
}
#error {
position: absolute;
width: 80%;
margin: 0px;
z-index: 2000;
width: 80%;
border-radius: 20px;
max-width: 500px;
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 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 * 20;
// 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 app 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}`, {
maxZoom: 18,
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +
'<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
id: 'mapbox.streets'
}).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>
Also see: Tab Triggers