From ae5db17a57b0b76542ca8a8dd828c3fa5fb2d552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?junh=5Feee=28=EC=9D=B4=EC=A4=80=ED=9D=AC=29?= Date: Wed, 4 Oct 2023 16:37:13 +0900 Subject: [PATCH] =?UTF-8?q?mapbox=202d=20=EC=A7=80=EB=8F=84=EC=9D=BC=20?= =?UTF-8?q?=EB=95=8C=203d-buildings=20=EB=A0=88=EC=9D=B4=EC=96=B4=20?= =?UTF-8?q?=EC=97=86=EC=96=B4=EC=84=9C=20=EC=83=9D=EA=B8=B0=EB=8A=94=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../map/mapbox/feature/FeatureAirZone.js | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/components/map/mapbox/feature/FeatureAirZone.js b/src/components/map/mapbox/feature/FeatureAirZone.js index 9f256c4..3cf029c 100644 --- a/src/components/map/mapbox/feature/FeatureAirZone.js +++ b/src/components/map/mapbox/feature/FeatureAirZone.js @@ -109,24 +109,27 @@ export const FeatureAirZone = props => { } }); - props.map.on('click', e => { - // 클릭한 지점의 피처들을 얻어옵니다. - const features = props.map.queryRenderedFeatures(e.point, { - layers: ['add-3d-buildings'] // 빌딩 레이어의 ID를 지정합니다. - }); + const buildingsLayer = props.map.getLayer('add-3d-buildings'); + if (buildingsLayer) { + props.map.on('click', e => { + // 클릭한 지점의 피처들을 얻어옵니다. + const features = props.map.queryRenderedFeatures(e.point, { + layers: ['add-3d-buildings'] // 빌딩 레이어의 ID를 지정합니다. + }); - // 빌딩 피처가 있는 경우 - if (features.length > 0) { - // 첫 번째 빌딩 피처의 높이 값을 얻어옵니다. - const height = features[0].properties.height; + // 빌딩 피처가 있는 경우 + if (features.length > 0) { + // 첫 번째 빌딩 피처의 높이 값을 얻어옵니다. + const height = features[0].properties.height; - // 팝업을 생성하고 지도에 추가합니다. - new props.mapboxgl.Popup() - .setLngLat(e.lngLat) - .setHTML(`Building height: ${height}m`) - .addTo(props.map); - } - }); + // 팝업을 생성하고 지도에 추가합니다. + new props.mapboxgl.Popup() + .setLngLat(e.lngLat) + .setHTML(`Building height: ${height}m`) + .addTo(props.map); + } + }); + } }; // 공역 생성 함수