【发布时间】:2016-12-15 18:11:23
【问题描述】:
我正在尝试将 GeoJSON 字符串加载到 VectorLayer 中,但遇到了 JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data 问题。
已经阅读过类似JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data 的一些文字,但无法解决我的问题。
这是我的 JSON。在http://jsonviewer.stack.hu/ 测试。
{'type': 'FeatureCollection','crs': {'type': 'name','properties': {'name': 'EPSG:4326'}},'features': [{'type': 'Feature','geometry':{'type':'MultiLineString','coordinates':[[[-43.1996056,-22.9109588],[-43.1993777,-22.9115575],[-43.1993539,-22.9116778],[-43.1993568,-22.9118156],[-43.199378,-22.9123812]]]}},{'type': 'Feature','geometry':{'type':'MultiLineString','coordinates':[[[-43.199378,-22.9123812],[-43.1994332,-22.9131767]]]}},{'type': 'Feature','geometry':{'type':'MultiLineString','coordinates':[[[-43.1994332,-22.9131767],[-43.1994563,-22.9141351],[-43.1994364,-22.9142456],[-43.199379,-22.9143303]]]}},{'type': 'Feature','geometry':{'type':'MultiLineString','coordinates':[[[-43.199379,-22.9143303],[-43.1985846,-22.9144791]]]}}]}
我的 OpenLayers 东西(featuresText 是上面的 GeoJSON):
var styleFunction = function(feature) {
return styles[feature.getGeometry().getType()];
};
var vectorSource = new ol.source.Vector({
features: ( new ol.format.GeoJSON() ).readFeatures( featuresText )
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource,
style: styleFunction
});
错误位于ol-debug.js:45632。 JSON字符串似乎没问题。我想不通。
我也读过这个http://openlayers.org/en/master/examples/geojson.html。
【问题讨论】:
-
为什么在这里而不是在 GIS 中?我认为这是一个 JSON 格式问题。
标签: javascript json openlayers-3 geojson