![](/img/trans.png)
[英]How to solve Uncaught SyntaxError: Unexpected token < in JSON at position 0 console error?
[英]How to solve “Uncaught SyntaxError: Unexpected token <” error
我正在研究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的新手,所以請任何人指導我解決此問題。
在此先感謝您的寶貴時間。
更新:
瀏覽器的“網絡”欄向我顯示了這一點:
“ 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上關於回購中GeoJSON文檔的HTML頁面。 可以通過單擊該頁面上的“原始”鏈接來找到實際的GeoJSON數據: https : //raw.githubusercontent.com/openlayers/ol3/master/examples/data/geojson/countries.geojson
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.