-
Notifications
You must be signed in to change notification settings - Fork 227
/
wicket-amap.js
56 lines (48 loc) · 1.23 KB
/
wicket-amap.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
55
56
(function (Wkt) {
Wkt.Wkt.prototype.construct = {
point: function(config) {
var opt = config || {};
opt.position = new AMap.LngLat(this.components[0].x, this.components[0].y);
return new AMap.Marker(opt);
},
polygon: function (config) {
var opt = config || {};
opt.path = this.components[0].map(function(p) {
return new AMap.LngLat(p.x, p.y);
});
opt.path.pop(); // unclosure
return new AMap.Polygon(opt);
}
};
Wkt.Wkt.prototype.deconstruct = deconstruct;
function deconstruct(obj) {
if (obj.constructor === AMap.Marker) {
var p = obj.getPosition();
return {
type: 'point',
components: [{
x: p.getLng(),
y: p.getLat()
}]
};
}
if (obj.constructor === AMap.Polygon) {
var verts = obj.getPath().map(function(p) {
return {
x: p.getLng(),
y: p.getLat()
};
});
verts.push({ // closure
x: verts[0].x,
y: verts[0].y
});
return {
type: 'polygon',
components: [verts]
};
}
console.error('Unsupported geometry class');
return null;
}
}(Wkt || require('./wicket')));