This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function remapLinearRing(linearRing) { | |
return linearRing.map(c => [c['lng'], c['lat']]); | |
} | |
function shapesToMultiPolygon(shapes) { | |
var allRings = shapes.map(function (shape) { | |
var shell = remapLinearRing(shape['shell']); | |
var holes = shape['holes'].map(h => remapLinearRing(h)); | |
return [shell].concat(holes); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function shapesToMultiPolygon(shapes) { | |
var allRings = shapes.map(function (shape) { | |
// The shell of the polygon is in a separate property 'shell'. | |
var shell = remapLinearRing(shape['shell']); | |
// The 'holes' property is an array of linear rings for holes. | |
var holes = shape['holes'].map(h => remapLinearRing(h)); | |
// Combine the shell and holes so that the shell is the first element in the resulting array. | |
return [shell].concat(holes); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toGeojson(timeMapResponse) { | |
// Parses the response json. This is needed if the parameter is a raw string. You don't need this if the response has already been parsed. | |
var responseData = JSON.parse(timeMapResponse); | |
// Converts each result in the response into a MultiPolygon object. | |
var multiPolygons = responseData['results'].map(r => shapesToMultiPolygon(r['shapes'])); | |
// Transforms each feature into feature object | |
var features = multiPolygons.map(mp => { | |
return { | |
'geometry': mp, | |
'type': "Feature", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="location-list" style="height: 100%; width: 35%; float: left;font-family: arial"> | |
<h2>Store Locations</h2> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var startingLocation = "London Waterloo Train Station"; | |
var departureTime = new Date().toJSON(); | |
var travelTime = 60 * 15; | |
var APPLICATION_ID = "place your app id here"; | |
var API_KEY = "place your api key here"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<div id='map'></div> | |
<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 src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY_GOES_HERE&callback=initMap" async defer></script> | |
<script> | |
var map; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<div id='map'></div> | |
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY_GOES_HERE&callback=initMap" async | |
defer></script> | |
<script> | |
var map; | |
function initMap() { | |
var mapOpts = { | |
center: { lat: 51.5031653, lng: -0.1123051 }, | |
zoom: 13, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<div id='map'></div> | |
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY_GOES_HERE&callback=initMap" async | |
defer></script> | |
<script> | |
var map; | |
function initMap() { | |
var mapOpts = { | |
center: { lat: 51.5031653, lng: -0.1123051 }, | |
zoom: 13, |
OlderNewer