[英]Change string that contains a polygon points as latitude and longitude to acceptable format for leaflet.js
我有一个字符串如下:
“ [[38.0331941572647,46.4061641693115],[38.0330673980052,46.4073014259338],[38.0342335749183,46.4073550701141],[38.0342166739362,46.4078593254089],[38.0355011374604,46.4079129695892],[38.0357461970214.46。
通过以下代码通过ajax请求从服务器端发送到javascript:
$.ajax({
type: "POST",
url: "_Index.aspx/GetPolygons",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccessLoadPolygons,
failure: function (response) {
//alert(response.d);
},
error: function (response) {
//alert(response.d);
}
});
根据成功请求,我正在使用传单库在地图上绘制多边形,如下所示:
function OnSuccessLoadPolygons(response) {
var polygons = response.d;
$(polygons).each(function () {
L.polygon(latlngs, { color: 'aqua' }).addTo(mymap);
});
}
但不幸的是,传单可接受的格式是这样的:
[[38.0331941572647,46.4061641693115],[38.0330673980052、46.4073014259338],[38.0342335749183、46.4073550701141],[38.0342166739362,46.4078593254089],[38.0355011374604,46.4079129695892],[38.03574619701214.46.572647
没有双引号。 如何将我的字符串解析为传单可接受的格式?
我将代码更改如下:
L.polygon(JSON.parse(latlngs),{color:'aqua'})。addTo(mymap); });
问题就解决了...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.