【发布时间】:2019-12-04 13:29:50
【问题描述】:
如果有人记得或看过我之前的帖子,我试图解析一个 GeoJSON 字符串,但成功有限。该问题已解决,但是我有一个大约 80k 行的 geojson 文件。我取出了 .js 文件中的字符串,并试图将我的 geojsonObject 指向 geojson 文件的文件路径。它看起来很简单,但现在我在 Microsoft Edge 的控制台中得到“不支持的 GeoJSON 类型:未定义”。错误指向 bundle-url.js
不知道出了什么问题。
控制台中链接的 .js 文件中的代码:
var bundleURL = null;
function getBundleURLCached() {
if (!bundleURL) {
bundleURL = getBundleURL();
}
return bundleURL;
}
function getBundleURL() {
// Attempt to find the URL of the current script and use that as the base URL
try {
throw new Error;
} catch (err) {
var matches = ('' + err.stack).match(/(https?|file|ftp|chrome-extension|moz-extension):$
if (matches) {
return getBaseURL(matches[0]);
}
}
return '/';
}
function getBaseURL(url) {
return ('' + url).replace(/^((?:https?|file|ftp|chrome-extension|moz-extension):\/\/.+)\/$
}
exports.getBundleURL = getBundleURLCached;
exports.getBaseURL = getBaseURL;
我的 .js 文件中的代码。该 url 指向与 .js 相同的文件夹中的 geojson 文件:
var geojsonObject = {
url: './locality.geojson',
format: new GeoJSON()
}
var vectorSource = new VectorSource({
features: new GeoJSON().readFeatures(geojsonObject, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
})
});
我已通过两个验证器将我的 geojson 放入,这两个验证器都没有出现任何问题。这一切都在本地主机(Ubuntu VPS)上,使用 npm。
如上所述,geojson 文件有 80k 行长,所以我不能把它全部贴在这里,所以这里是一个 sn-p;
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ -6.65073,54.34794 ]
},
"properties": {
"Site":"ARMAGH"
}
},
【问题讨论】:
-
您的功能之一是否缺少“类型”字段?
-
不,每个功能都是正确的,没有语法错误或缺少内容。
-
请提供一个minimal reproducible example 来证明该问题。
-
您可以从 geojson.io 和 geojsonlint 的来源验证您的 geojson。
标签: javascript openlayers geojson