diff --git a/packages/core/src/services/interaction/InteractionService.ts b/packages/core/src/services/interaction/InteractionService.ts index cb52841a9e..f25cfd29e8 100644 --- a/packages/core/src/services/interaction/InteractionService.ts +++ b/packages/core/src/services/interaction/InteractionService.ts @@ -72,7 +72,7 @@ export default class InteractionService } private addEventListenerOnMap() { - const $containter = this.mapService.getMapContainer(); + const $containter = (this.mapService.getMapCanvasContainer && this.mapService.getMapCanvasContainer()) || this.mapService.getMapContainer(); if ($containter) { if (isMini) { $window.document.addEventListener( diff --git a/packages/core/src/services/map/IMapService.ts b/packages/core/src/services/map/IMapService.ts index 6da3cb0ef7..87df08080d 100644 --- a/packages/core/src/services/map/IMapService.ts +++ b/packages/core/src/services/map/IMapService.ts @@ -84,7 +84,7 @@ export interface IMapService { getRotation(): number; getBounds(): Bounds; getMapContainer(): HTMLElement | null; - getMapCanvasContainer(): HTMLElement; + getMapCanvasContainer(): HTMLElement | null; getMapStyleConfig(): MapStyleConfig; // 获取当前地图类型默认的样式配置 getMapStyleValue(name: MapStyleName): string | any; // 获取当前地图类型key值对应的样式 value,可能为字符串,也可能为对象 getMapStyle(): MapStyleName | any; // 获取当期地图 diff --git a/packages/maps/src/mapbox/map.ts b/packages/maps/src/mapbox/map.ts index 5e6e8c13d6..ff03c74b1c 100644 --- a/packages/maps/src/mapbox/map.ts +++ b/packages/maps/src/mapbox/map.ts @@ -165,6 +165,13 @@ export default class MapboxService extends BaseMapService< return this.$mapContainer; } + public getMapCanvasContainer() { + if (this.$mapContainer) { + return this.$mapContainer.getElementsByClassName('mapboxgl-canvas-container')[0] + } + return this.$mapContainer; + } + public meterToCoord(center: [number, number], outer: [number, number]) { // 统一根据经纬度来转化 // Tip: 实际米距离 unit meter