如果有人记得或看过我之前的帖子,我试图解析 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 行长,所以我无法将其全部放在这里,所以这里是一个片段;
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ -6.65073,54.34794 ]
},
"properties": {
"Site":"ARMAGH"
}
},