forked from icarusion/amap-building-crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtilesToFeatures.js
54 lines (49 loc) · 1.58 KB
/
tilesToFeatures.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const TileLnglatTransform = require('tile-lnglat-transform');
const coordtransform = require('coordtransform');
const chunk = require('lodash').chunk;
const matchClasses = require('./matchClasses');
const hashString = str => {
const hash = require('crypto').createHash('md5');
hash.update(str);
return hash.digest('hex');
};
const pixelToLnglat = (pixels, index) => {
const points = chunk(pixels, 2);
const lnglatPoints = points.map(point => {
// 像素转坐标值
const gaodeTransfer = TileLnglatTransform.TileLnglatTransformGaode;
const location = gaodeTransfer.pixelToLnglat(point[0], point[1], index.x, index.y, index.z);
// 国测局坐标转wgs84坐标
return coordtransform.gcj02towgs84(location.lng, location.lat);
});
return lnglatPoints;
};
const tilesToFeatures = tilesJson => {
const features = [];
if (tilesJson.list) {
tilesJson.list.forEach((tileData, i) => {
tileData.tile.forEach((region, j) => {
const feature = {
type: 'Feature',
properties: {
level: 1,
name: region.name ? region.name : hashString(`tile_${i}_region_${j}`),
height: parseInt(region.floor, 10) * 10,
base_height: 0,
color: '#ddd',
},
geometry: {
type: 'Polygon',
coordinates: [
pixelToLnglat(region.coords, tileData.index),
],
},
};
feature.properties = matchClasses(feature.properties);
features.push(feature);
});
});
}
return features;
};
module.exports = tilesToFeatures;