[英]How to solve “Uncaught SyntaxError: Unexpected token <” error
I am working on openlayers 3 and I am trying to execute this simple JavaScript function: 我正在研究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()
I have seen many similar questions, but the solutions are not working for my case. 我已经看到许多类似的问题,但是解决方案不适用于我的情况。 I am new to openlayers so kindly anyone guide me to solve this issue.
我是openlayers的新手,所以请任何人指导我解决此问题。
Thanks in advance for your time guys. 在此先感谢您的宝贵时间。
UPDATE: 更新:
My browser's "Network" bar shows me this: 浏览器的“网络”栏向我显示了这一点:
The source of "countries.geojson" is this: “ 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
I downloaded this file, and now its in my local directory. 我下载了此文件,现在将其下载到本地目录中。 I think this linking of file in my project is causing problem.
我认为我项目中的文件链接导致了问题。 Can any body help me in using this file appropriately?
任何机构都可以帮助我正确使用此文件吗?
https://github.com/openlayers/ol3/blob/master/examples/data/geojson/countries.geojson is not a GeoJSON document, it's a HTML page on github about the GeoJSON document in the repo. https://github.com/openlayers/ol3/blob/master/examples/data/geojson/countries.geojson不是GeoJSON文档,它是github上关于回购中GeoJSON文档的HTML页面。 The actual GeoJSON data can be found by clicking the "Raw" link on that page: https://raw.githubusercontent.com/openlayers/ol3/master/examples/data/geojson/countries.geojson
可以通过单击该页面上的“原始”链接来找到实际的GeoJSON数据: https : //raw.githubusercontent.com/openlayers/ol3/master/examples/data/geojson/countries.geojson
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.