javascript - 浏览器在引用geojson文件时报错
问题描述
引用geojson时,浏览器报错如下
Error {status: 404, url: 'https://domain/resource/point.geojson', name: 'e', message: 'Not Found'}message: "Not Found"name: "e"status: 404url: "https://domain/resource/point.geojson"[[Prototype]]: Objectcause: undefinedconstructor: ƒ Error()stackTraceLimit: 10arguments: (...)caller: (...)captureStackTrace:
我的JS代码如下
map.on('load', function () {
map.addSource('places', {
'type': 'geojson',
'data': 'https://domain/json/point.geojson'
});
map.addLayer({
'id': 'places',
'type': 'circle',
'source': 'places',
'paint': {
'circle-color': '#FF6464',
'circle-radius': 5,
'circle-stroke-width': 0.8,
'circle-stroke-color': '#ffffff'
}
});
geojson数据如下
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"description": "<strong>test1</strong><p>2015,2016<br><a href=\"https://domain/77.html\" target=\"_blank\" title=\"Opens in a new window\">test</a></p><img src=\"https://domain/img/2019/04/25/816202630847470.jpeg\" alt=\"test\" width=\"220\" height=\"139\">"
},
"geometry": {
"type": "Point",
"coordinates": [
103.93,
33.26
]
}
},
{
"type": "Feature",
"properties": {
"description": "<strong>test2</strong><p>2007~2015,2016,2017,2018<br></p><img src=\"https://domain/img/2019/04/25/816202630847470.jpeg\" alt=\"test\" width=\"220\" height=\"139\">"
},
"geometry": {
"type": "Point",
"coordinates": [
116.46,
39.92
]
}
},
我查看了官方的例子和示例geojson数据,也验证了genjson数据的正确性
解决方案
这非常简单:您在访问 https://domain/resource/point.geojson 时遇到 404 错误(未找到文件)。该 URL(或任何真实的 URL)不正确。
推荐阅读
- mysql - 使用 Group By 和 Union All 计算多列?
- android - 如果 Activity 已经打开,请避免再次打开 Activity
- vba - 需要跳过包含文本 Word Macro 的行
- java - 冒泡一个异常:Java
- android - 如何确保所有 firebase SDK 都是兼容版本?
- grails - 访问 Grails 全局变量时是否需要使用互斥锁?
- php - 如何在 CodeIgniter 中使用单个帐户仅限制 3 次登录?
- c# - 在 DataTemplate 中查找视图模型 DataContext
- php - Laravel 多语言路由前缀
- java - EasyMock/PowerMock - 模拟静态方法抛出错误:没有可用的模拟的最后一次调用