当缩放比例增加到一定水平时,我想隐藏地图的标签。
对于此示例,我想在缩放级别5之后隐藏与collection1
相关的所有标签:
https://codepen.io/ollazarev/pen/XBWEEq
let viewer = new Cesium.Viewer('cesiumContainer', {
animation: false,
baseLayerPicker: false,
fullscreenButton: false,
geocoder: false,
homeButton: false,
infoBox: false,
sceneModePicker: false,
timeline: false,
navigationHelpButton: false,
navigationInstructionsInitiallyVisible: false,
});
let collection1 = new Cesium.LabelCollection();
collection1.add({
position: Cesium.Cartesian3.fromDegrees(-101.678, 57.7833),
text: 'Canada',
});
collection1.add({
position : Cesium.Cartesian3.fromDegrees(-75.1641667, 39.9522222),
text: 'Philadelphia',
});
viewer.scene.primitives.add(collection1);
let collection2 = new Cesium.LabelCollection();
collection2.add({
position: Cesium.Cartesian3.fromDegrees(-74.0059728, 40.7127753),
text: 'New York',
});
collection2.add({
position : Cesium.Cartesian3.fromDegrees(-79.38318429999998, 43.653226),
text: 'Toronto',
});
viewer.scene.primitives.add(collection2);
答案 0 :(得分:1)
Cesium的3D相机并没有意识到“缩放级别”,但是您可以使用translucencyByDistance
在距离一定距离后关闭标签。
例如,这是您的演示,其中在每个标签上都添加了translucencyByDistance
:
let viewer = new Cesium.Viewer('cesiumContainer', {
animation: false,
baseLayerPicker: false,
fullscreenButton: false,
geocoder: false,
homeButton: false,
infoBox: false,
sceneModePicker: false,
timeline: false,
navigationHelpButton: false,
navigationInstructionsInitiallyVisible: false,
});
let collection1 = new Cesium.LabelCollection();
collection1.add({
position: Cesium.Cartesian3.fromDegrees(-101.678, 57.7833),
text: 'Canada',
translucencyByDistance : new Cesium.NearFarScalar(6.0e7, 1.0, 7.0e7, 0.0)
});
collection1.add({
position : Cesium.Cartesian3.fromDegrees(-75.1641667, 39.9522222),
text: 'Philadelphia',
translucencyByDistance : new Cesium.NearFarScalar(4.0e7, 1.0, 7.0e7, 0.0)
});
viewer.scene.primitives.add(collection1);
let collection2 = new Cesium.LabelCollection();
collection2.add({
position: Cesium.Cartesian3.fromDegrees(-74.0059728, 40.7127753),
text: 'New York',
translucencyByDistance : new Cesium.NearFarScalar(1.0e7, 1.0, 3.0e7, 0.0)
});
collection2.add({
position : Cesium.Cartesian3.fromDegrees(-79.38318429999998, 43.653226),
text: 'Toronto',
translucencyByDistance : new Cesium.NearFarScalar(3.0e7, 1.0, 5.0e7, 0.0)
});
viewer.scene.primitives.add(collection2);