メインコンテンツまでスキップ

Display icons above 3D buildings

This example uses a symbol-z-elevate property to display a symbol layer above fill extrusions and models.

Performance caveats of the property

To have minimal impact on performance, this is supported only when fill-extrusion-height is not zoom-dependent and remains unchanged. For more details about symbol-z-elevate follow the link.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Display icons above 3D buildings</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<link href="https://api.mapbox.com/mapbox-gl-js/v3.7.0/mapbox-gl.css" rel="stylesheet">
<script src="https://api.mapbox.com/mapbox-gl-js/v3.7.0/mapbox-gl.js"></script>
<style>
body { margin: 0; padding: 0; }
#map { position: absolute; top: 0; bottom: 0; width: 100%; }
</style>
</head>
<body>
<div id="map"></div>
<script>
// TO MAKE THE MAP APPEAR YOU MUST
// ADD YOUR ACCESS TOKEN FROM
// https://account.mapbox.com
mapboxgl.accessToken = 'YOUR_MAPBOX_ACCESS_TOKEN';
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/standard',
center: [-74.010499, 40.705441],
zoom: 15.1,
pitch: 60
});

map.once('style.load', () => {
map.setConfigProperty('basemap', 'showPointOfInterestLabels', false);
map.setConfigProperty('basemap', 'showPlaceLabels', false);
map.setConfigProperty('basemap', 'showRoadLabels', false);
map.setConfigProperty('basemap', 'showTransitLabels', false);
});

map.once('load', () => {
map.loadImage(
'https://docs.mapbox.com/mapbox-gl-js/assets/cat.png',
(error, image) => {
map.addImage('cat', image);
map.addSource('buildings', {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [
-74.00923587095748, 40.70294276920271
]
}
}
]
}
});
map.addLayer({
id: 'cat-on-building',
source: 'buildings',
slot: 'top',
type: 'symbol',
'layout': {
'icon-image': 'cat',
'icon-size': 0.1,
'symbol-placement': 'point',
'symbol-z-elevate': true
}
});
}
);
});
</script>

</body>
</html>
このコードスニペットは、YOUR_MAPBOX_ACCESS_TOKENあなたのMapboxアカウントのアクセストークンに置き換えるまで、期待通りに動作しません。
このexampleは役に立ちましたか?