| | |
| | | import { defaultsDeep } from 'lodash-es'; |
| | | import type { Overlay } from 'ol'; |
| | | import { Map as OpenLayerMap, View } from 'ol'; |
| | | import { ZoomSlider } from 'ol/control'; |
| | | import type { Extent } from 'ol/extent'; |
| | | import { getTopLeft, getWidth } from 'ol/extent'; |
| | | import Tile from 'ol/layer/Tile'; |
| | |
| | | export const MARKER_OVERLAY_CLASS_NAME = 'marker-overlay'; |
| | | |
| | | export const gaoDeSourceTypeMap = { |
| | | [GaoDeSourceType.Default]: '默认地图', |
| | | [GaoDeSourceType.Satellite]: '影像地图', |
| | | [GaoDeSourceType.Vector]: '矢量地图', |
| | | [GaoDeSourceType.SatelliteRoad]: '影像路网', |
| | | // [GaoDeSourceType.Default]: '默认地图', |
| | | [GaoDeSourceType.Vector]: '标准地图', |
| | | |
| | | [GaoDeSourceType.Satellite]: '卫星地图', |
| | | [GaoDeSourceType.SatelliteRoad]: '路网地图', |
| | | }; |
| | | |
| | | export const getGaoDeSourceUrl = (type: GaoDeSourceType, lang: LangType = 'zh_cn') => { |
| | |
| | | }); |
| | | this.activeSourceType.value = sourceType; |
| | | this.markerIsVisible.value = markerIsVisible; |
| | | this.setSourceUrl(this.activeSourceType.value); |
| | | this.applySourceType(this.activeSourceType.value); |
| | | this.listenMapClick(); |
| | | this.addBasicControl(); |
| | | } |
| | | |
| | | setSourceUrl(type: GaoDeSourceType = GaoDeSourceType.Vector) { |
| | | applySourceType(type: GaoDeSourceType = GaoDeSourceType.Vector) { |
| | | const url = getGaoDeSourceUrl(type); |
| | | this.source.setUrl(url); |
| | | } |
| | | |
| | | setSourceType(type: GaoDeSourceType = GaoDeSourceType.Vector) { |
| | | this.activeSourceType.value = type; |
| | | this.applySourceType(type); |
| | | } |
| | | addMarkerLayer(dataList: any[], options: any) { |
| | | const { markerOpt } = options; |
| | |
| | | return overlay; |
| | | } |
| | | |
| | | adjustViewToMarkers() { |
| | | const overlays = this.map.getOverlays().getArray(); |
| | | |
| | | const filteredOverlays = overlays.filter((overlay) => { |
| | | const type = overlay.get('type'); |
| | | return type === OverlayType.Marker; |
| | | }); |
| | | this.adjustViewToOverlays(filteredOverlays); |
| | | } |
| | | |
| | | adjustViewToOverlays(overlays: Overlay[]) { |
| | | if (overlays.length === 0) return; |
| | | const extent = overlays.reduce<number[] | null>((ext, item) => { |
| | |
| | | setConfig(config: MapConfig) { |
| | | this.activeSourceType.value = config.sourceType; |
| | | this.markerIsVisible.value = config.markerIsVisible; |
| | | this.setSourceUrl(this.activeSourceType.value); |
| | | this.applySourceType(this.activeSourceType.value); |
| | | this.toggleMarkerOverlayVisible(this.markerIsVisible.value); |
| | | } |
| | | |
| | |
| | | olZoom.style.display = 'none'; |
| | | } |
| | | |
| | | /** |
| | | * 放大地图 |
| | | */ |
| | | zoomIn() { |
| | | const view = this.map.getView(); |
| | | const zoom = view.getZoom(); |
| | | view.setZoom(zoom + 1); |
| | | } |
| | | |
| | | /** |
| | | * 缩小地图 |
| | | */ |
| | | zoomOut() { |
| | | const view = this.map.getView(); |
| | | const zoom = view.getZoom(); |
| | | view.setZoom(zoom - 1); |
| | | } |
| | | |
| | | getWMTS = () => { |
| | | const projection = getProjection('EPSG:3857'); |
| | | const projectionExtent = projection.getExtent(); |