When referencing geojson, the browser reports an error as follows
JavaScript
x
2
1
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:
2
My JS code is as follows
JavaScript
1
19
19
1
map.on('load', function () {
2
3
map.addSource('places', {
4
'type': 'geojson',
5
'data': 'https://domain/json/point.geojson'
6
});
7
8
map.addLayer({
9
'id': 'places',
10
'type': 'circle',
11
'source': 'places',
12
'paint': {
13
'circle-color': '#FF6464',
14
'circle-radius': 5,
15
'circle-stroke-width': 0.8,
16
'circle-stroke-color': '#ffffff'
17
}
18
});
19
The geojson data is as follows
JavaScript
1
30
30
1
{
2
"type": "FeatureCollection",
3
"features": [
4
{
5
"type": "Feature",
6
"properties": {
7
"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">"
8
},
9
"geometry": {
10
"type": "Point",
11
"coordinates": [
12
103.93,
13
33.26
14
]
15
}
16
},
17
{
18
"type": "Feature",
19
"properties": {
20
"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">"
21
},
22
"geometry": {
23
"type": "Point",
24
"coordinates": [
25
116.46,
26
39.92
27
]
28
}
29
},
30
I checked the official examples and the sample geojson data, and also verified the correctness of the genjson data
Advertisement
Answer
It’s pretty straightforward: you’re getting a 404 error (file not found) accessing https://domain/resource/point.geojson. That URL (or whatever the real one is) is not correct.