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
<html> | |
<head> | |
<script src='https://api.mapbox.com/mapbox-gl-js/v1.11.1/mapbox-gl.js'></script> | |
<link href='https://api.mapbox.com/mapbox-gl-js/v1.11.1/mapbox-gl.css' rel='stylesheet' /> | |
<style> | |
body { | |
background-color: gray; | |
} |
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
<html> | |
<head> | |
<style> | |
body { | |
background-color: gray; | |
} | |
html, | |
body, |
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
import json | |
def remap_linear_ring(linear_ring): | |
return list(map(lambda c: [c['lng'], c['lat']], linear_ring)) | |
def shapes_to_multipolygon(shapes): | |
allRings = [] | |
for shape in shapes: |
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
<html> | |
<head> | |
<style> | |
body { | |
background-color: gray; | |
} | |
html, | |
body, |
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
{ | |
"coords": { | |
"lat": 40.750580, | |
"lng": -73.993584 | |
}, | |
"resolution": { | |
"height": "", | |
"width": "" | |
}, | |
"zoom": 11, |
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 properties = Object.values(location.properties); | |
var travelTime = properties[0].travel_time; | |
var travelTime = parseInt(travelTime); | |
listItem.innerHTML = location.id + ' - ETA: ' + Math.round(travelTime / 60) + ' mins'; | |
var properties = Object.values(location.properties); | |
var travelTime = properties[0].travel_time; | |
var travelTime = parseInt(travelTime); | |
listItem.innerHTML = location.id + ' - ETA: ' + Math.round(travelTime / 60) + ' mins'; |
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
createLocationList(locationsInRange); |