diff --git a/.gitignore b/.gitignore index 585d73f..1ba80ad 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ node_modules target dist .env +.env* +!.env.example .vite-ssg-temp \ No newline at end of file diff --git a/src/assets/colorbar.png b/src/assets/colorbar.png index 48a44fb..34184ac 100644 Binary files a/src/assets/colorbar.png and b/src/assets/colorbar.png differ diff --git a/src/components.d.ts b/src/components.d.ts index 70e1b69..391c904 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -56,6 +56,7 @@ declare module 'vue' { SelectSeparator: typeof import('./components/ui/select/SelectSeparator.vue')['default'] SelectTrigger: typeof import('./components/ui/select/SelectTrigger.vue')['default'] SelectValue: typeof import('./components/ui/select/SelectValue.vue')['default'] + Switch: typeof import('./components/ui/switch/Switch.vue')['default'] Table: typeof import('./components/ui/table/Table.vue')['default'] TableBody: typeof import('./components/ui/table/TableBody.vue')['default'] TableCaption: typeof import('./components/ui/table/TableCaption.vue')['default'] diff --git a/src/components/AMapClient.vue b/src/components/AMapClient.vue index 9a6714c..3a3b5d8 100644 --- a/src/components/AMapClient.vue +++ b/src/components/AMapClient.vue @@ -7,11 +7,11 @@ import { useOptions } from '@/composables/dateOpt' import '@amap/amap-jsapi-types' -const amapInstance = ref(null) -const map = ref(null) -const previousLayer = ref(null) +let amapInstance: null | typeof AMap = null +let map: null | AMap.Map = null +let previousLayer: null | AMap.ImageLayer = null -const FORCE_MODE_OVERRIDE = 'image' as 'image' | 'heatmap' | null +const FORCE_MODE_OVERRIDE = null as 'image' | 'heatmap' | null function getPostionText(position: [number, number]) { const [x, y] = position @@ -33,7 +33,7 @@ const apiKey = import.meta.env.VITE_AMAP_API_KEY const { options, currentFocus, getImageUrl, getHeatPoints } = useOptions() watch(options, async () => { - if (!map.value || !amapInstance.value) { + if (!map || !amapInstance) { return } if (options.castBeginDate === '' || options.castDayNo === -1) { @@ -56,24 +56,26 @@ watch(currentFocus, (newFocus) => { } const [lat, lon] = newFocus() // debugger - map.value?.setCenter([lat, lon]) - map.value?.setZoom(4) + if (map) { + map.setCenter([lat, lon]) + map.setZoom(4) + } }) const isDark = useDark() watch(isDark, (newValue) => { - map.value?.setMapStyle(newValue ? 'amap://styles/darkblue' : 'amap://styles/whitesmoke') + map?.setMapStyle(newValue ? 'amap://styles/darkblue' : 'amap://styles/whitesmoke') }) async function updateMapImage() { - if (!map.value || !amapInstance.value) { + if (!map || !amapInstance) { return } const url = await getImageUrl() - const image = new amapInstance.value.ImageLayer({ + const image = new amapInstance.ImageLayer({ url, // @ts-expect-error AMap messed up their definition bounds: new AMap.Bounds([-180, -35], [180, 35]), @@ -82,36 +84,38 @@ async function updateMapImage() { opacity: 1, // zooms: [15, 20], }) - map.value.add(image) + map.add(image) image.on('complete', () => { - previousLayer.value?.hide() - previousLayer.value = image + previousLayer?.hide() + previousLayer = image }) } async function updateMapHeatpoints() { - if (!map.value || !amapInstance.value) { + if (!map || !amapInstance) { return } - + previousLayer?.hide() const data = await getHeatPoints() let heatMap: any - const _map = map.value // @ts-expect-error Amap not providing heatmap types - _map.plugin(['AMap.Heatmap'], () => { + map.plugin(['AMap.HeatMap'], () => { // @ts-expect-error Amap not providing heatmap types - heatMap = new amapInstance.value.HeatMap(_map, { + heatMap = new amapInstance.HeatMap(map, { - radius: 100, // 给定半径 + radius: 25, // 给定半径 opacity: [0, 0.8], - + gradient: { + 0.0: 'red', + 1.0: 'red', + }, }) heatMap.setDataSet({ data, max: 1000, }) - heatMap.show() + previousLayer = heatMap }) } @@ -123,9 +127,9 @@ onMounted(async () => { version: '2.0', plugins: [], }) - amapInstance.value = _AMap + amapInstance = _AMap - map.value = new _AMap.Map('amap-container', { + map = new _AMap.Map('amap-container', { zoom: 5, center: [130, 17], zooms: [4, 20], @@ -136,13 +140,13 @@ onMounted(async () => { // ], }) - map.value.setBounds(new AMap.Bounds([-180, -35], [180, 35])) - map.value.setLimitBounds(new AMap.Bounds([-180, -35], [180, 35])) - map.value.setZoom(5) + map.setBounds(new AMap.Bounds([-180, -35], [180, 35])) + map.setLimitBounds(new AMap.Bounds([-180, -35], [180, 35])) + map.setZoom(5) - map.value.on('click', (e) => { + map.on('click', (e) => { const position = [e.lnglat.lng, e.lnglat.lat] as [number, number] - const infoWindow = new amapInstance.value!.InfoWindow({ + const infoWindow = new amapInstance!.InfoWindow({ content: `
${getPostionText(position).getX()} @@ -151,7 +155,7 @@ onMounted(async () => {
`, }) - infoWindow.open(map.value!, e.lnglat) + infoWindow.open(map!, e.lnglat) }) } }) diff --git a/src/components/PosForm.vue b/src/components/PosForm.vue index a153f42..20fab51 100644 --- a/src/components/PosForm.vue +++ b/src/components/PosForm.vue @@ -42,8 +42,8 @@ function getPostionText(position: [number, number]) { - {{ getPostionText(postion).getX() }} {{ getPostionText(postion).getY() }} + {{ getPostionText(postion).getX() }}