Last active
April 24, 2020 13:12
-
-
Save LouisaKB/ee67e97279691bee7b99c444776fbe98 to your computer and use it in GitHub Desktop.
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
The complete code for reference: | |
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] + holes; | |
}); | |
return { | |
'type': 'MultiPolygon', | |
'coordinates': allRings | |
}; | |
} | |
function toGeojson(timeMapResponse) { | |
var responseData = JSON.parse(timeMapResponse); | |
var multiPolygons = responseData['results'].map(r => shapesToMultiPolygon(r['shapes'])); | |
return { | |
'type': 'FeatureCollection', | |
'features': multiPolygons | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The code is not working
Here is a Working typescript code: