@@ -18,7 +18,8 @@ const {
1818 DEFAULT_PROJECTION ,
1919 DEFAULT_DARK_FEATURE_COLOR ,
2020 DEFAULT_LIGHT_FEATURE_COLOR ,
21- DEFAULT_SATELLITE_FEATURE_COLOR
21+ DEFAULT_SATELLITE_FEATURE_COLOR ,
22+ DEFAULT_3D_BUILDINGS
2223} = require ( '../../constants' ) ;
2324const drawStyles = require ( '../draw/styles' ) ;
2425
@@ -362,21 +363,58 @@ module.exports = function (context, readonly) {
362363
363364 geojsonToLayer ( context , writable ) ;
364365
366+ // Initialize 3D buildings state from localStorage after style is loaded
367+ // This can't live in `ui/3d-buildings-toggle.js because we have to wait for the map style to be loaded
368+ const hasKey = context . storage . get ( '3DBuildings' ) !== undefined ;
369+ const active3DBuildings = hasKey
370+ ? context . storage . get ( '3DBuildings' )
371+ : DEFAULT_3D_BUILDINGS ;
372+ if ( context . map . getConfigProperty ) {
373+ context . map . setConfigProperty (
374+ 'basemap' ,
375+ 'show3dObjects' ,
376+ active3DBuildings
377+ ) ;
378+ }
379+ // Update the UI to reflect the active state
380+ d3 . selectAll ( '.toggle-3D button' ) . classed ( 'active' , function ( ) {
381+ const { value } = d3 . select ( this ) . datum ( ) ;
382+ return value === active3DBuildings ;
383+ } ) ;
384+
365385 context . data . set ( {
366386 mapStyleLoaded : false
367387 } ) ;
368388 }
369389 } ) ;
370390
371391 // only show projection toggle on zoom < 6
372- context . map . on ( 'zoomend' , ( ) => {
392+ // only show 3d Buildings toggle on Zoom > 14
393+ function updateTogglesByZoom ( ) {
373394 const zoom = context . map . getZoom ( ) ;
395+ const projectionSwitch = d3 . select ( '.projection-switch' ) ;
396+ const toggle3D = d3 . select ( '.toggle-3D' ) ;
397+
398+ // Get current style to check if 3D buildings should be hidden
399+ const currentStyle = context . storage . get ( 'style' ) || DEFAULT_STYLE ;
400+ const shouldHide3DForStyle =
401+ currentStyle === 'OSM' ||
402+ currentStyle === 'Outdoors' ||
403+ currentStyle === 'Standard Satellite' ;
404+
374405 if ( zoom < 6 ) {
375- d3 . select ( '.projection-switch' ) . style ( 'opacity' , 1 ) ;
406+ projectionSwitch . style ( 'opacity' , 1 ) ;
407+ toggle3D . classed ( 'hidden' , true ) ;
408+ } else if ( zoom > 6 && zoom < 14 ) {
409+ projectionSwitch . style ( 'opacity' , 0 ) ;
410+ toggle3D . classed ( 'hidden' , true ) ;
376411 } else {
377- d3 . select ( '.projection-switch' ) . style ( 'opacity' , 0 ) ;
412+ // Hide 3D toggle for OSM and Outdoors styles, regardless of zoom
413+ toggle3D . classed ( 'hidden' , shouldHide3DForStyle ) ;
378414 }
379- } ) ;
415+ }
416+ context . map . on ( 'load' , ( ) => updateTogglesByZoom ( ) ) ;
417+ context . map . on ( 'zoomend' , ( ) => updateTogglesByZoom ( ) ) ;
380418
381419 const maybeSetCursorToPointer = ( ) => {
382420 if ( context . Draw . getMode ( ) === 'simple_select' ) {
0 commit comments