Skip to content

Commit

Permalink
Add support(point, polygon) for AMap(高德 from China)
Browse files Browse the repository at this point in the history
  • Loading branch information
uqix committed May 31, 2017
1 parent bd12e95 commit 546b6bc
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions wicket-amap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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')));

0 comments on commit 546b6bc

Please sign in to comment.