I am attempting to move my GeoJson from inline jscript to a URL to evaluate how it improves performance for maps with a lot of markers (3,000+). However, I have been unable to get my markers to display on the map, and would appreciate a fresh set of eyes. The url to my test page is here: http://webapps.fhsu.edu/ksherp/testmapbox.aspx The GeoJson file is linked
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoidHRhZ2dhcnQiLCJhIjoiY2lwZmp0emR2MDA1YnRhbmQ2aW8xdm9wZCJ9.XMq3bMhOjRit7wR3q7oIgQ';
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/ttaggart/cj3ohbccw00192rlrtj18zdmv', //stylesheet location
center: [-98.328809, 38.5], // starting position
zoom: 5 // starting zoom
// , maxZoom: 8 // limit max zoom extent
});
var url = 'http://webapps.fhsu.edu/ksherp/geojson/3.geojson';
map.on('load', function () {
window.setInterval(function () {
map.getSource('markers').setData(url);
}, 2000);
map.addSource('markers', { type: 'geojson', data: url });
map.addLayer({
"id": "markers",
"type": "symbol",
"source": "markers",
"layout": {
"icon-image": "{marker-symbol}-11"
}
});
});
// When a click event occurs near a marker icon, open a popup at the location of
// the feature, with description HTML from its properties.
map.on('click', function (e) {
var features = map.queryRenderedFeatures(e.point, { layers: ['markers'] });
if (!features.length) {
return;
}
var feature = features[0];
// Populate the popup and set its coordinates
// based on the feature found.
var popup = new mapboxgl.Popup()
.setLngLat(feature.geometry.coordinates)
.setHTML(feature.properties.description)
.addTo(map);
});
// Use the same approach as above to indicate that the symbols are clickable
// by changing the cursor style to 'pointer'.
map.on('mousemove', function (e) {
var features = map.queryRenderedFeatures(e.point, { layers: ['markers'] });
map.getCanvas().style.cursor = (features.length) ? 'pointer' : '';
});
map.addControl(new mapboxgl.NavigationControl());
map.addControl(nav, 'top-right');
Your test page is not working, it shows Server Error in '/ksHerp' Application.
.
Using your code without modification I had no issues displaying the markers:
If your page is working again and you're still having this issue, you could check the browser console if your GeoJSON file is not loaded because of a CORS error or some browser restrictions using mixed-content (http/https). Some links which might be helpful: