gpt4 book ai didi

javascript - 如何解决 "Uncaught SyntaxError: Unexpected token <"错误

转载 作者:行者123 更新时间:2023-11-30 16:43:19 25 4
gpt4 key购买 nike

我正在开发 openlayers 3,我正在尝试执行这个简单的 JavaScript 函数:

function mapScript() {
// create a vector source that loads a GeoJSON file
var vectorSource = new ol.source.Vector({
projection: 'EPSG:3857',
format: new ol.format.GeoJSON(),
url: 'countries.geojson'
});

// a vector layer to render the source
var vectorLayer = new ol.layer.Vector({
source: vectorSource
});

var center = ol.proj.transform([0, 0], 'EPSG:4326', 'EPSG:3857');

var view = new ol.View({
center: center,
zoom: 1
});

// the vector layer gets added like a raster layer
var map = new ol.Map({
target: 'map',
layers: [vectorLayer],
view: view
});
} // END of mapScript()

我见过很多类似的问题,但这些解决方案都不适用于我的情况。我是 openlayers 的新手,所以请任何人指导我解决这个问题。

提前感谢您抽出时间。

更新:

我浏览器的“网络”栏显示如下:

enter image description here

“countries.geojson”的来源是这样的:

https://github.com/openlayers/ol3/blob/master/examples/data/geojson/countries.geojson

我下载了这个文件,现在它在我的本地目录中。我认为我项目中的这种文件链接导致了问题。任何机构都可以帮助我正确使用此文件吗?

最佳答案

https://github.com/openlayers/ol3/blob/master/examples/data/geojson/countries.geojson不是 GeoJSON 文档,它是 github 上关于 repo 中 GeoJSON 文档的 HTML 页面。单击该页面上的“原始”链接可以找到实际的 GeoJSON 数据:https://raw.githubusercontent.com/openlayers/ol3/master/examples/data/geojson/countries.geojson

关于javascript - 如何解决 "Uncaught SyntaxError: Unexpected token <"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31609338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com