| | |
| | | import WMTS from 'ol/source/WMTS'; |
| | | import WMTSTileGrid from 'ol/tilegrid/WMTS'; |
| | | import type { ViewOptions } from 'ol/View'; |
| | | |
| | | import MVT from 'ol/format/MVT.js'; |
| | | import VectorTileLayer from 'ol/layer/VectorTile'; |
| | | import VectorTileSource from 'ol/source/VectorTile'; |
| | | import { defaults as olDefaults } from 'ol/interaction'; |
| | | import type { Ref } from 'vue'; |
| | | import { ref } from 'vue'; |
| | | import { MarkerOverlay } from './overlay/marker'; |
| | | import { TileGrid } from 'ol/tilegrid'; |
| | | import Style from 'ol/style/Style'; |
| | | import Fill from 'ol/style/Fill'; |
| | | import Stroke from 'ol/style/Stroke'; |
| | | import Circle from 'ol/style/Circle'; |
| | | |
| | | export type LangType = 'zh_cn' | 'en'; |
| | | export const enum GaoDeSourceType { |
| | | /** @description 默认地图 */ |
| | |
| | | |
| | | view?: ViewOptions; |
| | | } & MapConfig; |
| | | |
| | | const resolutions = []; |
| | | for (let i = 0; i <= 8; ++i) { |
| | | resolutions.push(156543.03392804097 / Math.pow(2, i * 2)); |
| | | } |
| | | export class OLMap { |
| | | map: OpenLayerMap; |
| | | source: XYZ; |
| | | private eventMap: Map<OLEventType, Function[]>; |
| | | |
| | | activeSourceType: Ref<GaoDeSourceType> = ref(GaoDeSourceType.Vector); |
| | | markerIsVisible: Ref<boolean> = ref(true); |
| | | private emit(eventName: OLEventType, ...args: any[]) { |
| | |
| | | target: container, // 绑定 DOM 容器 |
| | | layers: [layer], // 添加图层 |
| | | view: new View(view), |
| | | interactions: olDefaults({ doubleClickZoom: false }), |
| | | }); |
| | | this.activeSourceType.value = sourceType; |
| | | this.markerIsVisible.value = markerIsVisible; |
| | |
| | | view.setZoom(zoom - 1); |
| | | } |
| | | |
| | | private tileUrlFunction(url) { |
| | | return (tileCoord) => |
| | | url |
| | | .replace('{z}', String(tileCoord[0] * 2 - 1)) |
| | | .replace('{x}', String(tileCoord[1])) |
| | | .replace('{y}', String(tileCoord[2])) |
| | | .replace('{a-d}', 'abcd'.substr(((tileCoord[1] << tileCoord[0]) + tileCoord[2]) % 4, 1)); |
| | | } |
| | | |
| | | addCustomLayer(url: string, style?: any) { |
| | | const vectorTileExtent = [13270414.528705932, 2994644.904997596, 13295641.139349712, 3018305.0256410106]; |
| | | |
| | | const vectorTileLayer = new VectorTileLayer({ |
| | | source: new VectorTileSource({ |
| | | format: new MVT(), |
| | | url: url, |
| | | }), |
| | | extent: vectorTileExtent, |
| | | style: style |
| | | }); |
| | | this.map.addLayer(vectorTileLayer); |
| | | return vectorTileLayer; |
| | | } |
| | | |
| | | getWMTS = () => { |
| | | const projection = getProjection('EPSG:3857'); |
| | | const projectionExtent = projection.getExtent(); |