Google maps 将Google Api多边形另存为openlayers字符串
我想保存用户将其绘制到字符串中的多边形,如:Google maps 将Google Api多边形另存为openlayers字符串,google-maps,google-maps-api-3,openlayers,Google Maps,Google Maps Api 3,Openlayers,我想保存用户将其绘制到字符串中的多边形,如: "SRID=4326;GEOMETRYCOLLECTION(POLYGON((......)))" 有什么办法吗? 我不想使用谷歌API中的encodeString 谢谢我找到了这个解决方案,希望它也能帮助那些与我有同样问题的人 函数GMapPolygonToWKT(poly){ //启动多边形已知文本(WKT)表达式 wkt=“SRID=4326;几何图形集合(多边形(”; var path=poly.getpath(); 对于(var i=0
"SRID=4326;GEOMETRYCOLLECTION(POLYGON((......)))"
有什么办法吗?
我不想使用谷歌API中的encodeString
谢谢我找到了这个解决方案,希望它也能帮助那些与我有同样问题的人
函数GMapPolygonToWKT(poly){
//启动多边形已知文本(WKT)表达式
wkt=“SRID=4326;几何图形集合(多边形(”;
var path=poly.getpath();
对于(var i=0;它的答案可能与此相关。您的函数接受一个参数poly
,然后将其完全忽略。但它确实引用了一个变量geoField
;该变量来自何处?此代码的原始版本使用了该参数:var path=poly.getpath();
,为什么不在调用时将geoField
传递到函数中呢?是的,你是对的,我将其更改为poly,geoField是我的全局变量,与此答案无关。
function GMapPolygonToWKT(poly) {
// Start the Polygon Well Known Text (WKT) expression
wkt = "SRID=4326;GEOMETRYCOLLECTION(POLYGON(";
var paths = poly.getPaths();
for(var i=0; i<paths.getLength(); i++) {
var path = paths.getAt(i);
// Open a ring grouping in the Polygon Well Known Text
wkt += "(";
for(var j=0; j<path.getLength(); j++) {
// setCenteradd each vertice and anticipate another vertice (trailing comma)
wkt += path.getAt(j).lng().toString()
+ " "
+ path.getAt(j).lat().toString()
+",";
}
// Also close the ring grouping and anticipate another ring (trailing comma)
wkt += path.getAt(0).lng().toString()
+ " "
+ path.getAt(0).lat().toString()
+ "),";
}
// resolve the last trailing "," and close the Polygon
wkt = wkt.substring(0, wkt.length - 1) + "))";
return wkt;
}