-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support(point, polygon) for AMap(高德 from China)
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
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
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'))); |