我正在尝试将我的GeoJson从内联jscript移动到URL,以评估它如何提高具有大量标记(3,000+)的地图的性能。但是,我无法将我的标记显示在地图上,并且会欣赏一双新鲜的眼睛。我的测试页面的网址位于:http://webapps.fhsu.edu/ksherp/testmapbox.aspx GeoJson文件已链接
<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');
答案 0 :(得分:0)
您的测试页无效,显示Server Error in '/ksHerp' Application.
。
使用您的代码而不进行修改我没有显示标记的问题:
如果您的网页再次运行并且您仍然遇到此问题,则可以检查浏览器控制台是否由于CORS错误或使用混合内容(http / https)的某些浏览器限制而未加载您的GeoJSON文件。一些可能有用的链接: