如何向地图区域添加填充?
正如您在屏幕截图中看到的那样,div
顶部覆盖了一个黄色,并且弹出窗口出现在其下方,所以我想给地图区域 100px 的顶部填充,以便弹出窗口下降到一边。提前致谢。
下面的代码:
<div id="map" class="map"></div>
<script>
mapboxgl.accessToken = 'pk.xxxxxx';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/xxxxxx/cj5jggnud0m5g2soxqalq8z3n',
zoom: 3,
center: [50.075,26.136]
});
var geojson = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: xx.xxxxx,xx.xxxxxx }}]
},
properties: {
title: 'Egypt',
description: 'Item One Item Two Item Three'
}
}
]
};
// add markers to map
geojson.features.forEach(function(marker) {
// create a HTML element for each feature
var el = document.createElement('div');
el.className = 'marker';
// make a marker for each feature and add to the map
new mapboxgl.Marker(el, { offset: [-50 / 2, -50 / 2] })
.setLngLat(marker.geometry.coordinates)
.setPopup(new mapboxgl.Popup({ offset: 25 }) // add popups
.setHTML('<div class="map-marker"><h3>' + marker.properties.title + '</h3><p>' + marker.properties.description + '</p></div>'))
.addTo(map);
});
// disable map zoom when using scroll
map.scrollZoom.disable();
// Add zoom and rotation controls to the map.
var nav = new mapboxgl.NavigationControl();
map.addControl(nav, 'bottom-right');
</script>