-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwikimapia.js
More file actions
37 lines (33 loc) · 810 Bytes
/
wikimapia.js
File metadata and controls
37 lines (33 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const request = require('request')
const key = '8F7B5281-C532D421-0AA68391-6844DCA3-4530C7D4-BA54FA80-E0813252-453E10EB'
const toArray = obj => [obj.x, obj.y]
module.exports = id => {
const option = {
qs: {
key,
id,
function: 'place.getbyid',
language: 'en',
format: 'json',
}
}
return new Promise((resolve, reject) => {
request('http://api.wikimapia.org', option, (err, res, body) => {
if (err) reject(err)
const result = JSON.parse(body)
resolve({
type: 'Feature',
geometry: {
type: 'Polygon',
coordinates: [[
...result.polygon.map(toArray),
toArray(result.polygon[0]),
]]
},
properties: {
name: result.title
}
})
})
})
}