file-type

使用background-map进行地图展示的简易教程

ZIP文件

下载需积分: 9 | 118KB | 更新于2025-09-11 | 138 浏览量 | 0 下载量 举报 收藏
download 立即下载
根据提供的文件信息,我们可以深入探讨与该存储库相关的知识点,主要涉及以下几个方面: ### 标题分析 **标题**: "background-map:该存储库是我的博客“黑板上地图”的一部分" 从标题中我们可以得知,存储库`background-map`是博主“黑板上地图”博客项目的一部分。这意味着存储库中可能包含了与地图展示相关的内容,或许是为了在博主的博客文章中提供交互式的地图背景。 ### 描述分析 **描述**: 描述中提到了存储库的具体用途,即在博客文章中使用`map1.html`文件。同时,给出了使用该存储库的基本步骤: 1. 使用`git clone`命令克隆存储库到本地环境。 2. 切换到克隆的存储库目录`background-map`中。 3. 运行`npm install`安装所有依赖项。 4. 执行`npm run start`启动服务。 5. 打开浏览器并访问特定的URL来查看地图。 例如,`http://0.0.0.0:8180/map1.html`可以用来查看地图。 这表明该存储库是一个Web应用程序,可能使用了Node.js环境进行服务,并且使用了npm包管理器来管理项目的依赖。 ### 标签分析 **标签**: "JavaScript" 标签显示了该存储库与JavaScript编程语言相关。考虑到该存储库是一个Web应用程序,我们可以推断JavaScript是实现其前端交互和功能的核心技术。这可能意味着存储库中包含了HTML文件、CSS样式表和JavaScript脚本,用来实现地图的展示和用户交互。 ### 文件列表分析 **压缩包子文件的文件名称列表**: background-map-master 由于提供的信息不包含实际的文件列表内容,我们无法直接从中分析出具体的知识点。然而,`background-map-master`这一名称暗示了这个存储库是一个主分支版本,通常包含所有的源代码和资源文件。 ### 综合知识点 - **Git与版本控制**: 存储库的克隆操作展示了使用Git作为版本控制系统的重要性,它能够帮助开发者管理项目的源代码,进行版本跟踪,以及协作开发。 - **Node.js**: 描述中没有直接提到Node.js,但考虑到需要运行npm命令,我们可以推断该项目可能使用Node.js作为后端服务。Node.js是基于Chrome V8引擎的JavaScript运行时环境,它让开发者可以使用JavaScript来编写服务器端的代码。 - **npm**: Node.js的包管理工具npm在安装和管理项目依赖中发挥着关键作用。通过`npm install`可以安装项目所需的所有依赖包,这些依赖包可能包括Web应用程序的前端库、工具、框架等。 - **Web开发**: 存储库包含了Web应用程序,这涉及HTML、CSS、JavaScript的使用。`map1.html`很可能是交互式地图的前端实现,这暗示了存储库中可能包含了HTML结构、CSS样式以及使用JavaScript实现的地图交互功能。 - **HTTP服务器**: 描述中提及了通过`http://0.0.0.0:8180`访问地图,这表明存储库中包含了可以启动本地HTTP服务器的脚本或配置,以便进行开发测试。 - **软件开发实践**: 该存储库的使用说明展示了标准的软件开发流程,包括代码克隆、依赖安装、服务启动以及运行测试,这些是现代Web开发中的常规实践。 总结来说,`background-map`存储库是博主博客项目的一部分,通过其提供的信息,我们了解到了一系列相关的IT和软件开发知识点。存储库涉及了Web应用程序的开发和部署,使用了现代软件开发中的技术栈,如Git、Node.js、npm以及前端技术。通过学习和理解这些知识点,开发者可以更好地构建和维护类似的应用程序。

相关推荐

filetype

<template>
坐标系: <el-radio-group v-model="coordinateSystem" size="small"> <el-radio-button label="gcj02">高德/火星坐标</el-radio-button> <el-radio-button label="bd09">百度坐标</el-radio-button> </el-radio-group>
<Search @location-selected="handleLocationSelected" /> <LocationBar v-if="loaded" :update-interval="100" :use-dms-format="useDmsFormat" /> </template> <style> /* 原有样式完全不变 */ </style> <script setup lang="ts"> // 原有导入 + 新增坐标转换工具类导入 import { computed, onUnmounted, onMounted, reactive, ref } from "vue"; import LocationBar from "./location-bar.vue"; import Search from "./search.vue"; import initMap from "./init"; import { throttle } from "lodash"; import { loadRipplePoints, createMultipleRippleCircles } from "./circle.js"; import { $ prototype } from "../../main.ts"; import markerImage from "@/assets/images/building.png"; import { imageDark } from "naive-ui/es/image/styles"; // 新增:导入坐标转换工具类 import { CoordinateTransformer } from "./coordinate-transformer"; // 修复类型定义 type Rectangle = any; // 原有状态 + 新增坐标系选择状态 const miniMapContainer = ref<HTMLElement>(); let viewIndicator: Rectangle; const currentPosition = reactive({ longitude: 113.361538, latitude: 27.339318, }); const ZHUZHOU_EXTENT = { west: 112.5, east: 114.5, south: 26.0, north: 28.0, }; const rippleEntities = ref<any[]>([]); const heightThreshold = 80000; const indicatorStyle = ref({ left: "50%", top: "50%", display: "block", }); const loaded = ref(false); const useDmsFormat = ref(false); const overviewViewer = ref(null); let currentMarker: any = null; // 新增:坐标系选择状态(默认高德GCJ-02) const coordinateSystem = ref("gcj02"); // 'gcj02' | 'bd09' // 原有方法完全不变(波纹可见性更新) const updateRippleVisibility = throttle(() => { if (!$ prototype.$ map || rippleEntities.value.length === 0) return; let shouldShow = false; const cartographic = $ prototype.$ map.camera.positionCartographic; if (cartographic) { const cameraHeight = cartographic.height; shouldShow = cameraHeight > heightThreshold; } rippleEntities.value.forEach((entity) => { entity.show = shouldShow; }); }, 200); // 原有方法完全不变(指示器位置更新) const updateIndicatorPosition = () => { if (!$ prototype.$ map) return; const camera = $ prototype.$ map.camera; const rect = camera.computeViewRectangle(); if (!rect) return; const center = Cesium.Rectangle.center(rect); const lon = Cesium.Math.toDegrees(center.longitude); const lat = Cesium.Math.toDegrees(center.latitude); const constrainedLon = Math.max( ZHUZHOU_EXTENT.west, Math.min(ZHUZHOU_EXTENT.east, lon) ); const constrainedLat = Math.max( ZHUZHOU_EXTENT.south, Math.min(ZHUZHOU_EXTENT.north, lat) ); const lonPercent = ((constrainedLon - ZHUZHOU_EXTENT.west) / (ZHUZHOU_EXTENT.east - ZHUZHOU_EXTENT.west)) * 100; const latPercent = 100 - ((constrainedLat - ZHUZHOU_EXTENT.south) / (ZHUZHOU_EXTENT.north - ZHUZHOU_EXTENT.south)) * 100; indicatorStyle.value = { left: `${lonPercent}%`, top: `${latPercent}%`, display: "block", }; }; // 原有方法完全不变(鹰眼地图更新) const updateOverview = () => { if (!$ prototype.$ map || !overviewViewer.value) return; const rectangle = $ prototype.$ map.camera.computeViewRectangle(); if (!rectangle) return; updateIndicatorPosition(); }; // 原有方法完全不变(初始化鹰眼地图) const initMiniMap = () => { Cesium.Ion.defaultAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIxMDhlNDdmYy03NzFhLTQ1ZTQtOWQ3NS1lZDAzNDc3YjE4NDYiLCJpZCI6MzAxNzQyLCJpYXQiOjE3NDcwNTMyMDN9.eaez8rQxVbPv2LKEU0sMDclPWyHKhh1tR27Vg-_rQSM"; if (!miniMapContainer.value) return; const worldProvider = new Cesium.UrlTemplateImageryProvider({ url: "https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}", minimumLevel: 0, maximumLevel: 19, tilingScheme: new Cesium.WebMercatorTilingScheme(), }); const zhuzhouProvider = new Cesium.UrlTemplateImageryProvider({ url: "http://124.232.190.30:9000/proxy/pk1725866655224/map/zzzsyx_18/{z}/{x}/{y}.png", minimumLevel: 1, maximumLevel: 17, tilingScheme: new Cesium.WebMercatorTilingScheme(), }); overviewViewer.value = new Cesium.Viewer(miniMapContainer.value, { sceneMode: Cesium.SceneMode.SCENE2D, baseLayerPicker: false, homeButton: false, timeline: false, navigationHelpButton: false, animation: false, scene3DOnly: true, selectionIndicator: false, infoBox: false, imageryProvider: worldProvider, terrainProvider: undefined, mapProjection: new Cesium.WebMercatorProjection(), skyBox: false, skyAtmosphere: false, }); const zhuzhouLayer = overviewViewer.value.imageryLayers.addImageryProvider( zhuzhouProvider ); overviewViewer.value.camera.setView({ destination: Cesium.Rectangle.fromDegrees( ZHUZHOU_EXTENT.west, ZHUZHOU_EXTENT.south, ZHUZHOU_EXTENT.east, ZHUZHOU_EXTENT.north ), }); const toolbar = overviewViewer.value.container.getElementsByClassName( "cesium-viewer-toolbar" )[0]; if (toolbar) toolbar.style.display = "none"; overviewViewer.value.cesiumWidget.creditContainer.style.display = "none"; initRectangle(); }; // 原有方法完全不变(初始化视图指示器) function initRectangle() { viewIndicator = overviewViewer.value.entities.add({ rectangle: { coordinates: Cesium.Rectangle.fromDegrees( ZHUZHOU_EXTENT.west, ZHUZHOU_EXTENT.south, ZHUZHOU_EXTENT.east, ZHUZHOU_EXTENT.north ), material: Cesium.Color.RED.withAlpha(0.3), outline: true, outlineColor: Cesium.Color.RED, outlineWidth: 2, }, }); } // 原有方法完全不变(添加演示图形) function addDemoGraphics() { const chinaBoundary = $ prototype.$ map.dataSources.add( Cesium.GeoJsonDataSource.load("/shp_zz.geojson", { stroke: Cesium.Color.WHITE, fill: false, clampToGround: true, describe: null, }) ); chinaBoundary.then((dataSource) => { const entities = dataSource.entities.values; for (let entity of entities) { if (entity.polyline) { entity.polyline.fill = false; } } }); } // 原有方法完全不变(飞行到默认位置) function flyToDes() { const center = Cesium.Cartesian3.fromDegrees(-98.0, 40.0); $ prototype.$ map.camera.flyTo({ destination: new Cesium.Cartesian3( -2432812.6687511606, 5559483.804371395, 2832009.419525571 ), orientation: { heading: 6.283185307179421, pitch: -1.0472145569408116, roll: 6.2831853071795205, }, complete: function () {}, }); } // 原有方法完全不变(监听相机变化) const setupCameraListener = () => { $ prototype.$ map.camera.changed.addEventListener(updateOverview); }; // 原有方法完全不变(鹰眼地图点击处理) const handleMiniMapClick = (event: MouseEvent) => { if (!miniMapContainer.value || !overviewViewer.value) return; const rect = miniMapContainer.value.getBoundingClientRect(); const x = event.clientX - rect.left; const y = event.clientY - rect.top; const xPercent = (x / rect.width) * 100; const yPercent = (y / rect.height) * 100; const lon = ZHUZHOU_EXTENT.west + (xPercent / 100) * (ZHUZHOU_EXTENT.east - ZHUZHOU_EXTENT.west); const lat = ZHUZHOU_EXTENT.north - (yPercent / 100) * (ZHUZHOU_EXTENT.north - ZHUZHOU_EXTENT.south); $ prototype.$ map.camera.flyTo({ destination: Cesium.Cartesian3.fromDegrees(lon, lat, 1000000), }); }; // 原有生命周期方法完全不变 onMounted(() => { initMap(); loaded.value = true; addDemoGraphics(); flyToDes(); setTimeout(() => { initMiniMap(); setupCameraListener(); updateOverview(); }, 1000); (async () => { try { const ripplePoints = await loadRipplePoints(); rippleEntities.value = createMultipleRippleCircles($ prototype.$ map, ripplePoints); $ prototype.$ map.camera.changed.addEventListener(updateRippleVisibility); updateRippleVisibility(); } catch (error) { console.error("加载波纹圆失败:", error); } })(); }); // 原有方法完全不变(创建标记) const createMarker = (location: { lng: number; lat: number; name: string }) => { if (currentMarker) { $ prototype.$ map.entities.remove(currentMarker); } console.log("标记图片加载状态:", markerImage); console.log("创建标记位置:", location); currentMarker = $ prototype.$ map.entities.add({ position: Cesium.Cartesian3.fromDegrees(location.lng, location.lat, 10), label: { text: location.name + "(标记位置)", font: "18px sans-serif", fillColor: Cesium.Color.YELLOW, outlineColor: Cesium.Color.BLACK, outlineWidth: 2, verticalOrigin: Cesium.VerticalOrigin.TOP, pixelOffset: new Cesium.Cartesian2(0, 40), heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND, show: true, }, point: { pixelSize: 15, color: Cesium.Color.RED, outlineColor: Cesium.Color.WHITE, outlineWidth: 3, heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND, show: true, }, }); console.log("标记实体已添加:", currentMarker); $ prototype.$ map.scene.requestRender(); return currentMarker; }; // 核心修改:使用工具类实现动态坐标系转换 const handleLocationSelected = (location: { lng: number; lat: number; name: string }) => { if (!$ prototype.$ map) return; // 根据选择的坐标系进行转换 let wgsLocation; if (coordinateSystem.value === "gcj02") { // 高德/火星坐标转WGS84 wgsLocation = CoordinateTransformer.gcj02ToWgs84(location.lng, location.lat); } else { // 百度坐标转WGS84 wgsLocation = CoordinateTransformer.bd09ToWgs84(location.lng, location.lat); } console.log(`转换前(${coordinateSystem.value})坐标:`, location.lng, location.lat); console.log("转换后(WGS84)坐标:", wgsLocation.lng, wgsLocation.lat); // 使用转换后的坐标执行原有逻辑 const destination = Cesium.Cartesian3.fromDegrees( wgsLocation.lng, wgsLocation.lat, 2000 ); $ prototype.$ map.camera.flyTo({ destination, orientation: { heading: Cesium.Math.toRadians(0), pitch: Cesium.Math.toRadians(-45), roll: 0, }, duration: 2, complete: () => { createMarker({ ...location, ...wgsLocation }); }, }); }; // 原有方法完全不变(组件销毁清理) onUnmounted(() => { if ($ prototype.$ map) { $ prototype.$ map.destroy(); $ prototype.$ map = null; } if ($ prototype.$ map) { $ prototype.$ map.camera.changed.removeEventListener(updateRippleVisibility); } console.log("组件销毁"); }); const emit = defineEmits(["onload", "onclick"]); const initMars3d = async (option: any) => { emit("onclick", true); emit("onload", $ prototype.$ map); }; </script> <style lang="less"> /**cesium 工具按钮栏*/ .cesium-viewer-toolbar { top: auto !important; bottom: 35px !important; left: 12px !important; right: auto !important; } .cesium-toolbar-button img { height: 100%; } .cesium-viewer-toolbar > .cesium-toolbar-button, .cesium-navigationHelpButton-wrapper, .cesium-viewer-geocoderContainer { margin-bottom: 5px; float: left; clear: both; text-align: center; } .cesium-button { background-color: rgba(23, 49, 71, 0.8); color: #e6e6e6; fill: #e6e6e6; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); line-height: 32px; } .cesium-button:hover { background: #3ea6ff; } /**cesium 底图切换面板*/ .cesium-baseLayerPicker-dropDown { bottom: 0; left: 40px; max-height: 700px; margin-bottom: 5px; background-color: rgba(23, 49, 71, 0.8); } /**cesium 帮助面板*/ .cesium-navigation-help { top: auto; bottom: 0; left: 40px; transform-origin: left bottom; background: none; background-color: rgba(23, 49, 71, 0.8); .cesium-navigation-help-instructions { background: none; } .cesium-navigation-button { background: none; } .cesium-navigation-button-selected, .cesium-navigation-button-unselected:hover { background: rgba(0, 138, 255, 0.2); } } /**cesium 二维三维切换*/ .cesium-sceneModePicker-wrapper { width: auto; } .cesium-sceneModePicker-wrapper .cesium-sceneModePicker-dropDown-icon { float: right; margin: 0 3px; } /**cesium POI查询输入框*/ .cesium-viewer-geocoderContainer .search-results { left: 0; right: 40px; width: auto; z-index: 9999; } .cesium-geocoder-searchButton { background-color: rgba(23, 49, 71, 0.8); } .cesium-viewer-geocoderContainer .cesium-geocoder-input { background-color: rgba(63, 72, 84, 0.7); } .cesium-viewer-geocoderContainer .cesium-geocoder-input:focus { background-color: rgba(63, 72, 84, 0.9); } .cesium-viewer-geocoderContainer .search-results { background-color: rgba(23, 49, 71, 0.8); } /**cesium info信息框*/ .cesium-infoBox { top: 50px; background-color: rgba(23, 49, 71, 0.8); } .cesium-infoBox-title { background-color: rgba(23, 49, 71, 0.8); } /**cesium 任务栏的FPS信息*/ .cesium-performanceDisplay-defaultContainer { top: auto; bottom: 35px; right: 50px; } .cesium-performanceDisplay-ms, .cesium-performanceDisplay-fps { color: #fff; } /**cesium tileset调试信息面板*/ .cesium-viewer-cesiumInspectorContainer { top: 10px; left: 10px; right: auto; } .cesium-cesiumInspector { background-color: rgba(23, 49, 71, 0.8); } /**覆盖mars3d内部控件的颜色等样式*/ .mars3d-compass .mars3d-compass-outer { fill: rgba(23, 49, 71, 0.8); } .mars3d-contextmenu-ul, .mars3d-sub-menu { background-color: rgba(23, 49, 71, 0.8); > li > a:hover, > li > a:focus, > li > .active { background-color: #3ea6ff; } > .active > a, > .active > a:hover, > .active > a:focus { background-color: #3ea6ff; } } /* Popup样式*/ .mars3d-popup-color { color: #ffffff; } .mars3d-popup-background { background: rgba(23, 49, 71, 0.8); } .mars3d-popup-content { margin: 15px; } .mars3d-template-content label { padding-right: 6px; } .mars3d-template-titile { border-bottom: 1px solid #3ea6ff; } .mars3d-template-titile a { font-size: 16px; } .mars3d-tooltip { background: rgba(23, 49, 71, 0.8); border: 1px solid rgba(23, 49, 71, 0.8); } .mars3d-popup-btn-custom { padding: 3px 10px; border: 1px solid #209ffd; background: #209ffd1c; } .mars-dialog .mars-dialog__content { height: 100%; width: 100%; overflow: auto; padding: 5px; } .image { border: solid 2px #fff; } .content { height: 90%; padding-top: 10px; overflow-x: auto; overflow-y: auto; } .content-text { padding: 0 10px; text-indent: 30px; font-size: 17px; } .details-video { width: 100%; height: 760px; background-color: #000; } :where(.css-lt97qq9).ant-space { display: inline-flex; } :where(.css-lt97qq9).ant-space-align-center { align-items: center; } :where(.css-lt97qq9).ant-image .ant-image-mask { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; background: rgba(0, 0, 0, 0.5); cursor: pointer; opacity: 0; transition: opacity 0.3s; } :where(.css-lt97qq9).ant-image .ant-image-mask .ant-image-mask-info { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding: 0 4px; } :where(.css-1t97qq9)[class^="ant-image"] [class^="ant-image"], :where(.css-1t97qq9)[class*=" ant-image"] [class^="ant-image"], :where(.css-1t97qq9)[class^="ant-image"] [class*=" ant-image"], :where(.css-1t97qq9)[class*=" ant-image"] [class*=" ant-image"] { box-sizing: border-box; } :where(.css-lt97qq9).ant-image .ant-image-img { width: 100%; height: auto; vertical-align: middle; } </style> <style scoped> .mini-map-container { position: relative; width: 100%; height: 100%; } .main-viewer { width: 100%; height: 100%; } .mini-map { position: absolute; right: 3vw; bottom: 6vh; width: 12vw; height: 17vh; border: 2px solid #fff; box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); z-index: 999; cursor: pointer; overflow: hidden; } .location-indicator { position: absolute; width: 19px; height: 19px; transform: translate(-50%, -50%); z-index: 100; border: 2px solid red; border-radius: 2px; } /* 原十字准星伪元素保持不变 */ .location-indicator::before, .location-indicator::after { content: ''; position: absolute; background-color: red; top: 50%; left: 50%; transform: translate(-50%, -50%); } .location-indicator::before { width: 12px; height: 2px; } .location-indicator::after { width: 2px; height: 12px; } /* 新增四条准星延伸线 */ .ext-line { position: absolute; background-color: red; } /* 顶部延伸线 - 从矩形边框向上延伸 */ .ext-line-top { top: -5px; left: 50%; transform: translateX(-50%); width: 2px; height: 5px; } /* 右侧延伸线 - 从矩形边框向右延伸 */ .ext-line-right { top: 50%; right: -5px; transform: translateY(-50%); width: 5px; height: 2px; } /* 底部延伸线 - 从矩形边框向下延伸 */ .ext-line-bottom { bottom: -5px; left: 50%; transform: translateX(-50%); width: 2px; height: 5px; } /* 左侧延伸线 - 从矩形边框向左延伸 */ .ext-line-left { top: 50%; left: -5px; transform: translateY(-50%); width: 5px; height: 2px; } .view-rectangle { position: absolute; border: 2px solid #00f2fe; z-index: 99; pointer-events: none; box-shadow: 0 0 20px rgba(0, 242, 254, 0.7); } /* 相机聚焦样式 - 四个角折角 */ .corner { position: absolute; width: 25px; height: 25px; z-index: 100; pointer-events: none; } .corner::before, .corner::after { content: ""; position: absolute; background: #00f2fe; box-shadow: 0 0 10px rgba(0, 242, 254, 0.8); } .corner-top-left { top: -2px; left: -2px; } .corner-top-left::before { top: 0; left: 0; width: 15px; height: 3px; } .corner-top-left::after { top: 0; left: 0; width: 3px; height: 15px; } .corner-top-right { top: -2px; right: -2px; } .corner-top-right::before { top: 0; right: 0; width: 15px; height: 3px; } .corner-top-right::after { top: 0; right: 0; width: 3px; height: 15px; } .corner-bottom-left { bottom: -2px; left: -2px; } .corner-bottom-left::before { bottom: 0; left: 0; width: 15px; height: 3px; } .corner-bottom-left::after { bottom: 0; left: 0; width: 3px; height: 15px; } .corner-bottom-right { bottom: -2px; right: -2px; } .corner-bottom-right::before { bottom: 0; right: 0; width: 15px; height: 3px; } .corner-bottom-right::after { bottom: 0; right: 0; width: 3px; height: 15px; } .camera-icon { position: absolute; top: 10px; right: 10px; color: #00f2fe; font-size: 24px; z-index: 100; text-shadow: 0 0 10px rgba(0, 242, 254, 0.8); } .focus-effect { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 98; border: 2px solid rgba(0, 242, 254, 0.2); border-radius: 5px; box-shadow: inset 0 0 30px rgba(0, 242, 254, 0.1); } .pulse { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 10px; height: 10px; border-radius: 50%; background: rgba(0, 242, 254, 0.7); box-shadow: 0 0 0 0 rgba(0, 242, 254, 0.7); animation: pulse 2s infinite; } ::v-deep.cesium-viewer-toolbar { display: none; } </style> 检查live-map.vue代码,其中的鹰眼地图部分代码好像存在问题如下:鹰眼联动有问题,鹰眼图不用操作,基于此你帮我检查修改一下,尽可能不更改其他任何无关代码,减少对vue文件的修改

filetype

<template>
坐标系: <el-radio-group v-model="coordinateSystem" size="small"> <el-radio-button label="gcj02">高德/火星坐标</el-radio-button> <el-radio-button label="bd09">百度坐标</el-radio-button> </el-radio-group>
<Search @location-selected="handleLocationSelected" /> <LocationBar v-if="loaded" :update-interval="100" :use-dms-format="useDmsFormat" /> </template> <style> /* 原有样式完全不变 */ </style> <script setup lang="ts"> // 原有导入 + 新增坐标转换工具类导入 import { computed, onUnmounted, onMounted, reactive, ref } from "vue"; import LocationBar from "./location-bar.vue"; import Search from "./search.vue"; import initMap from "./init"; import { throttle } from "lodash"; import { loadRipplePoints, createMultipleRippleCircles } from "./circle.js"; import { $prototype } from "../../main.ts"; import markerImage from "@/assets/images/building.png"; import { imageDark } from "naive-ui/es/image/styles"; // 新增:导入坐标转换工具类 import { CoordinateTransformer } from "./coordinate-transformer"; // 修复类型定义 type Rectangle = any; // 原有状态 + 新增坐标系选择状态 const miniMapContainer = ref<HTMLElement>(); let viewIndicator: Rectangle; const currentPosition = reactive({ longitude: 113.361538, latitude: 27.339318, }); const ZHUZHOU_EXTENT = { west: 112.5, east: 114.5, south: 26.0, north: 28.0, }; const rippleEntities = ref<any[]>([]); const heightThreshold = 80000; const indicatorStyle = ref({ left: "50%", top: "50%", display: "block", }); const loaded = ref(false); const useDmsFormat = ref(false); const overviewViewer = ref(null); let currentMarker: any = null; // 新增:坐标系选择状态(默认高德GCJ-02) const coordinateSystem = ref("gcj02"); // 'gcj02' | 'bd09' // 原有方法完全不变(波纹可见性更新) const updateRippleVisibility = throttle(() => { if (!$prototype.$map || rippleEntities.value.length === 0) return; let shouldShow = false; const cartographic = $prototype.$map.camera.positionCartographic; if (cartographic) { const cameraHeight = cartographic.height; shouldShow = cameraHeight > heightThreshold; } rippleEntities.value.forEach((entity) => { //entity.show = shouldShow; entity.show = false; }); }, 200); // 原有方法完全不变(指示器位置更新) const updateIndicatorPosition = () => { if (!$prototype.$map) return; const camera = $prototype.$map.camera; const rect = camera.computeViewRectangle(); if (!rect) return; const center = Cesium.Rectangle.center(rect); const lon = Cesium.Math.toDegrees(center.longitude); const lat = Cesium.Math.toDegrees(center.latitude); const constrainedLon = Math.max( ZHUZHOU_EXTENT.west, Math.min(ZHUZHOU_EXTENT.east, lon) ); const constrainedLat = Math.max( ZHUZHOU_EXTENT.south, Math.min(ZHUZHOU_EXTENT.north, lat) ); const lonPercent = ((constrainedLon - ZHUZHOU_EXTENT.west) / (ZHUZHOU_EXTENT.east - ZHUZHOU_EXTENT.west)) * 100; const latPercent = 100 - ((constrainedLat - ZHUZHOU_EXTENT.south) / (ZHUZHOU_EXTENT.north - ZHUZHOU_EXTENT.south)) * 100; indicatorStyle.value = { left: `${lonPercent}%`, top: `${latPercent}%`, display: "block", }; }; // 原有方法完全不变(鹰眼地图更新) const updateOverview = () => { if (!$prototype.$map || !overviewViewer.value) return; const rectangle = $prototype.$map.camera.computeViewRectangle(); if (!rectangle) return; updateIndicatorPosition(); // 添加视口矩形更新逻辑 if (viewIndicator) { viewIndicator.rectangle.coordinates = rectangle; } }; // 原有方法完全不变(初始化鹰眼地图) const initMiniMap = () => { Cesium.Ion.defaultAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIxMDhlNDdmYy03NzFhLTQ1ZTQtOWQ3NS1lZDAzNDc3YjE4NDYiLCJpZCI6MzAxNzQyLCJpYXQiOjE3NDcwNTMyMDN9.eaez8rQxVbPv2LKEU0sMDclPWyHKhh1tR27Vg-_rQSM"; if (!miniMapContainer.value) return; const worldProvider = new Cesium.UrlTemplateImageryProvider({ url: "https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}", minimumLevel: 0, maximumLevel: 19, tilingScheme: new Cesium.WebMercatorTilingScheme(), }); const zhuzhouProvider = new Cesium.UrlTemplateImageryProvider({ url: "http://124.232.190.30:9000/proxy/pk1725866655224/map/zzzsyx_18/{z}/{x}/{y}.png", minimumLevel: 1, maximumLevel: 17, tilingScheme: new Cesium.WebMercatorTilingScheme(), }); overviewViewer.value = new Cesium.Viewer(miniMapContainer.value, { sceneMode: Cesium.SceneMode.SCENE2D, baseLayerPicker: false, homeButton: false, timeline: false, navigationHelpButton: false, animation: false, scene3DOnly: true, selectionIndicator: false, infoBox: false, imageryProvider: worldProvider, terrainProvider: undefined, mapProjection: new Cesium.WebMercatorProjection(), skyBox: false, skyAtmosphere: false, }); // 禁用所有相机交互控制(新增功能代码) const cameraController = overviewViewer.value.scene.screenSpaceCameraController; cameraController.enableTranslate = false; cameraController.enableZoom = false; cameraController.enableRotate = false; cameraController.enableTilt = false; cameraController.enableLook = false; const zhuzhouLayer = overviewViewer.value.imageryLayers.addImageryProvider( zhuzhouProvider ); overviewViewer.value.camera.setView({ destination: Cesium.Rectangle.fromDegrees( ZHUZHOU_EXTENT.west, ZHUZHOU_EXTENT.south, ZHUZHOU_EXTENT.east, ZHUZHOU_EXTENT.north ), }); const toolbar = overviewViewer.value.container.getElementsByClassName( "cesium-viewer-toolbar" )[0]; if (toolbar) toolbar.style.display = "none"; overviewViewer.value.cesiumWidget.creditContainer.style.display = "none"; initRectangle(); }; // 原有方法完全不变(初始化视图指示器) function initRectangle() { viewIndicator = overviewViewer.value.entities.add({ rectangle: { coordinates: Cesium.Rectangle.fromDegrees( ZHUZHOU_EXTENT.west, ZHUZHOU_EXTENT.south, ZHUZHOU_EXTENT.east, ZHUZHOU_EXTENT.north ), material: Cesium.Color.RED.withAlpha(0.3), outline: true, outlineColor: Cesium.Color.RED, outlineWidth: 2, }, }); } // 原有方法完全不变(添加演示图形) function addDemoGraphics() { const chinaBoundary = $prototype.$map.dataSources.add( Cesium.GeoJsonDataSource.load("/shp_zz.geojson", { stroke: Cesium.Color.WHITE, fill: false, clampToGround: true, describe: null, }) ); chinaBoundary.then((dataSource) => { const entities = dataSource.entities.values; for (let entity of entities) { if (entity.polyline) { entity.polyline.fill = false; } } }); } // 原有方法完全不变(飞行到默认位置) function flyToDes() { const center = Cesium.Cartesian3.fromDegrees(-98.0, 40.0); $prototype.$map.camera.flyTo({ destination: new Cesium.Cartesian3( -2432812.6687511606, 5559483.804371395, 2832009.419525571 ), orientation: { heading: 6.283185307179421, pitch: -1.0472145569408116, roll: 6.2831853071795205, }, complete: function () {}, }); } // 原有方法完全不变(监听相机变化) const setupCameraListener = () => { $prototype.$map.camera.changed.addEventListener(updateOverview); }; // 原有方法完全不变(鹰眼地图点击处理) const handleMiniMapClick = (event: MouseEvent) => { if (!miniMapContainer.value || !overviewViewer.value) return; const rect = miniMapContainer.value.getBoundingClientRect(); const x = event.clientX - rect.left; const y = event.clientY - rect.top; const xPercent = (x / rect.width) * 100; const yPercent = (y / rect.height) * 100; const lon = ZHUZHOU_EXTENT.west + (xPercent / 100) * (ZHUZHOU_EXTENT.east - ZHUZHOU_EXTENT.west); const lat = ZHUZHOU_EXTENT.north - (yPercent / 100) * (ZHUZHOU_EXTENT.north - ZHUZHOU_EXTENT.south); $prototype.$map.camera.flyTo({ destination: Cesium.Cartesian3.fromDegrees(lon, lat, 1000000), }); }; // 原有生命周期方法完全不变 onMounted(() => { initMap(); loaded.value = true; addDemoGraphics(); flyToDes(); setTimeout(() => { initMiniMap(); setupCameraListener(); updateOverview(); }, 1000); (async () => { try { const ripplePoints = await loadRipplePoints(); rippleEntities.value = createMultipleRippleCircles($prototype.$map, ripplePoints); $prototype.$map.camera.changed.addEventListener(updateRippleVisibility); updateRippleVisibility(); } catch (error) { console.error("加载波纹圆失败:", error); } })(); }); // 原有方法完全不变(创建标记) const createMarker = (wgsLocation) => { if (currentMarker) { $prototype.$map.entities.remove(currentMarker); } console.log("标记图片加载状态:", markerImage); console.log("创建标记位置:", wgsLocation); currentMarker = $prototype.$map.entities.add({ position: Cesium.Cartesian3.fromDegrees(wgsLocation.lng, wgsLocation.lat, 10), label: { text: wgsLocation.name + "(标记位置)", font: "18px sans-serif", fillColor: Cesium.Color.YELLOW, outlineColor: Cesium.Color.BLACK, outlineWidth: 2, verticalOrigin: Cesium.VerticalOrigin.TOP, pixelOffset: new Cesium.Cartesian2(0, 20), heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND, show: true, }, // 关键:用 billboard 替换 point billboard: { image: new URL("@/assets/images/building.png", import.meta.url).href, // 本地图标 width: 32, // 图标宽度(像素) height: 32, // 图标高度(像素) verticalOrigin: Cesium.VerticalOrigin.BOTTOM, // 让图标尖点对地 heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND, scale: 1.0, }, }); console.log("标记实体已添加:", currentMarker); $prototype.$map.scene.requestRender(); return currentMarker; }; // 核心修改:使用工具类实现动态坐标系转换 const handleLocationSelected = (location: { lng: number; lat: number; name: string }) => { if (!$prototype.$map) return; // 根据选择的坐标系进行转换 let wgsLocation; if (coordinateSystem.value === "gcj02") { // 高德/火星坐标转WGS84 wgsLocation = CoordinateTransformer.gcj02ToWgs84(location.lng, location.lat); } else { // 百度坐标转WGS84 wgsLocation = CoordinateTransformer.bd09ToWgs84(location.lng, location.lat); } console.log(`转换前(${coordinateSystem.value})坐标:`, location.lng, location.lat); console.log("转换后(WGS84)坐标:", wgsLocation.lng, wgsLocation.lat); // 使用转换后的坐标执行原有逻辑 const destination = Cesium.Cartesian3.fromDegrees( wgsLocation.lng, wgsLocation.lat, 3000 ); $prototype.$map.camera.flyTo({ destination, orientation: { heading: Cesium.Math.toRadians(0), pitch: Cesium.Math.toRadians(-90), roll: 0, }, duration: 2, complete: () => { createMarker({ ...location, ...wgsLocation }); }, }); }; // 原有方法完全不变(组件销毁清理) onUnmounted(() => { if ($prototype.$map) { $prototype.$map.destroy(); $prototype.$map = null; } if ($prototype.$map) { $prototype.$map.camera.changed.removeEventListener(updateRippleVisibility); } console.log("组件销毁"); }); const emit = defineEmits(["onload", "onclick"]); const initMars3d = async (option: any) => { emit("onclick", true); emit("onload", $prototype.$map); }; </script> <style lang="less"> /**cesium 工具按钮栏*/ .cesium-viewer-toolbar { top: auto !important; bottom: 35px !important; left: 12px !important; right: auto !important; } .cesium-toolbar-button img { height: 100%; } .cesium-viewer-toolbar > .cesium-toolbar-button, .cesium-navigationHelpButton-wrapper, .cesium-viewer-geocoderContainer { margin-bottom: 5px; float: left; clear: both; text-align: center; } .cesium-button { background-color: rgba(23, 49, 71, 0.8); color: #e6e6e6; fill: #e6e6e6; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); line-height: 32px; } .cesium-button:hover { background: #3ea6ff; } /**cesium 底图切换面板*/ .cesium-baseLayerPicker-dropDown { bottom: 0; left: 40px; max-height: 700px; margin-bottom: 5px; background-color: rgba(23, 49, 71, 0.8); } /**cesium 帮助面板*/ .cesium-navigation-help { top: auto; bottom: 0; left: 40px; transform-origin: left bottom; background: none; background-color: rgba(23, 49, 71, 0.8); .cesium-navigation-help-instructions { background: none; } .cesium-navigation-button { background: none; } .cesium-navigation-button-selected, .cesium-navigation-button-unselected:hover { background: rgba(0, 138, 255, 0.2); } } /**cesium 二维三维切换*/ .cesium-sceneModePicker-wrapper { width: auto; } .cesium-sceneModePicker-wrapper .cesium-sceneModePicker-dropDown-icon { float: right; margin: 0 3px; } /**cesium POI查询输入框*/ .cesium-viewer-geocoderContainer .search-results { left: 0; right: 40px; width: auto; z-index: 9999; } .cesium-geocoder-searchButton { background-color: rgba(23, 49, 71, 0.8); } .cesium-viewer-geocoderContainer .cesium-geocoder-input { background-color: rgba(63, 72, 84, 0.7); } .cesium-viewer-geocoderContainer .cesium-geocoder-input:focus { background-color: rgba(63, 72, 84, 0.9); } .cesium-viewer-geocoderContainer .search-results { background-color: rgba(23, 49, 71, 0.8); } /**cesium info信息框*/ .cesium-infoBox { top: 50px; background-color: rgba(23, 49, 71, 0.8); } .cesium-infoBox-title { background-color: rgba(23, 49, 71, 0.8); } /**cesium 任务栏的FPS信息*/ .cesium-performanceDisplay-defaultContainer { top: auto; bottom: 35px; right: 50px; } .cesium-performanceDisplay-ms, .cesium-performanceDisplay-fps { color: #fff; } /**cesium tileset调试信息面板*/ .cesium-viewer-cesiumInspectorContainer { top: 10px; left: 10px; right: auto; } .cesium-cesiumInspector { background-color: rgba(23, 49, 71, 0.8); } /**覆盖mars3d内部控件的颜色等样式*/ .mars3d-compass .mars3d-compass-outer { fill: rgba(23, 49, 71, 0.8); } .mars3d-contextmenu-ul, .mars3d-sub-menu { background-color: rgba(23, 49, 71, 0.8); > li > a:hover, > li > a:focus, > li > .active { background-color: #3ea6ff; } > .active > a, > .active > a:hover, > .active > a:focus { background-color: #3ea6ff; } } /* Popup样式*/ .mars3d-popup-color { color: #ffffff; } .mars3d-popup-background { background: rgba(23, 49, 71, 0.8); } .mars3d-popup-content { margin: 15px; } .mars3d-template-content label { padding-right: 6px; } .mars3d-template-titile { border-bottom: 1px solid #3ea6ff; } .mars3d-template-titile a { font-size: 16px; } .mars3d-tooltip { background: rgba(23, 49, 71, 0.8); border: 1px solid rgba(23, 49, 71, 0.8); } .mars3d-popup-btn-custom { padding: 3px 10px; border: 1px solid #209ffd; background: #209ffd1c; } .mars-dialog .mars-dialog__content { height: 100%; width: 100%; overflow: auto; padding: 5px; } .image { border: solid 2px #fff; } .content { height: 90%; padding-top: 10px; overflow-x: auto; overflow-y: auto; } .content-text { padding: 0 10px; text-indent: 30px; font-size: 17px; } .details-video { width: 100%; height: 760px; background-color: #000; } :where(.css-lt97qq9).ant-space { display: inline-flex; } :where(.css-lt97qq9).ant-space-align-center { align-items: center; } :where(.css-lt97qq9).ant-image .ant-image-mask { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; background: rgba(0, 0, 0, 0.5); cursor: pointer; opacity: 0; transition: opacity 0.3s; } :where(.css-lt97qq9).ant-image .ant-image-mask .ant-image-mask-info { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding: 0 4px; } :where(.css-1t97qq9)[class^="ant-image"] [class^="ant-image"], :where(.css-1t97qq9)[class*=" ant-image"] [class^="ant-image"], :where(.css-1t97qq9)[class^="ant-image"] [class*=" ant-image"], :where(.css-1t97qq9)[class*=" ant-image"] [class*=" ant-image"] { box-sizing: border-box; } :where(.css-lt97qq9).ant-image .ant-image-img { width: 100%; height: auto; vertical-align: middle; } </style> <style scoped> .mini-map-container { position: relative; width: 100%; height: 100%; } .main-viewer { width: 100%; height: 100%; } .mini-map { position: absolute; right: 3vw; bottom: 6vh; width: 12vw; height: 17vh; border: 2px solid #fff; box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); z-index: 999; cursor: pointer; overflow: hidden; } .location-indicator { position: absolute; width: 19px; height: 19px; transform: translate(-50%, -50%); z-index: 100; /* border: 2px solid red; border-radius: 2px; */ } /* 原十字准星伪元素保持不变 */ .location-indicator::before, .location-indicator::after { content: ""; position: absolute; background-color: red; top: 50%; left: 50%; transform: translate(-50%, -50%); } .location-indicator::before { width: 14px; height: 2px; } .location-indicator::after { width: 2px; height: 14px; } .view-rectangle { position: absolute; border: 2px solid #00f2fe; z-index: 99; pointer-events: none; box-shadow: 0 0 20px rgba(0, 242, 254, 0.7); } /* 相机聚焦样式 - 四个角折角 */ .corner { position: absolute; width: 25px; height: 25px; z-index: 100; pointer-events: none; } .corner::before, .corner::after { content: ""; position: absolute; background: #00f2fe; box-shadow: 0 0 10px rgba(0, 242, 254, 0.8); } .corner-top-left { top: -2px; left: -2px; } .corner-top-left::before { top: 0; left: 0; width: 15px; height: 3px; } .corner-top-left::after { top: 0; left: 0; width: 3px; height: 15px; } .corner-top-right { top: -2px; right: -2px; } .corner-top-right::before { top: 0; right: 0; width: 15px; height: 3px; } .corner-top-right::after { top: 0; right: 0; width: 3px; height: 15px; } .corner-bottom-left { bottom: -2px; left: -2px; } .corner-bottom-left::before { bottom: 0; left: 0; width: 15px; height: 3px; } .corner-bottom-left::after { bottom: 0; left: 0; width: 3px; height: 15px; } .corner-bottom-right { bottom: -2px; right: -2px; } .corner-bottom-right::before { bottom: 0; right: 0; width: 15px; height: 3px; } .corner-bottom-right::after { bottom: 0; right: 0; width: 3px; height: 15px; } .camera-icon { position: absolute; top: 10px; right: 10px; color: #00f2fe; font-size: 24px; z-index: 100; text-shadow: 0 0 10px rgba(0, 242, 254, 0.8); } .focus-effect { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 98; border: 2px solid rgba(0, 242, 254, 0.2); border-radius: 5px; box-shadow: inset 0 0 30px rgba(0, 242, 254, 0.1); } .pulse { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 10px; height: 10px; border-radius: 50%; background: rgba(0, 242, 254, 0.7); box-shadow: 0 0 0 0 rgba(0, 242, 254, 0.7); animation: pulse 2s infinite; } ::v-deep.cesium-viewer-toolbar { display: none; } </style> 检查live-map代码,其中为什么这个红色十字定位位置会不对,会呆在左上方,虽然移动后会变正确,但是刷新页面显示时就是有时候会不对,会影响观感,你阅读live-map.vue代码中鹰眼地图部分代码,尝试寻找原因修改,然后尽可能不更改其他任何无关代码,减少对代码的修改

filetype

<template>
<button class="status-button" :class="{ active: activeDeviceType === 'all' }" @click="switchDeviceType('all')"> 总设备数 </button> 8000
<button class="status-button" :class="{ active: activeDeviceType === 'online' }" @click="switchDeviceType('online')"> 在线设备 </button> 4
<button class="status-button" :class="{ active: activeDeviceType === 'offline' }" @click="switchDeviceType('offline')"> 离线设备 </button> 2
<button class="status-button" :class="{ active: activeDeviceType === 'inactive' }" @click="switchDeviceType('inactive')"> 未激活 </button> 1
<button class="status-button" :class="{ active: activeDeviceType === 'warning' }" @click="switchDeviceType('warning')"> 今日险情预警 </button> 1
</template> <style> /* 全局样式 */ * { margin: 0; padding: 0; box-sizing: border-box; } .boox { width: 100%; height: 92.7vh; box-sizing: border-box; padding: 0.5vw; background-color: rgb(205, 205, 205); position: relative; } #map-container { width: 100%; height: 100%; border-radius: 20px; overflow: hidden; } /* 地图类型切换控件样式 */ /*.map-type-control { position: absolute; top: 2vw; right: 5vw; z-index: 1000; display: flex; background: white; border-radius: 6px; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); overflow: hidden; } .map-type-control button { border: none; padding: 8px 12px; font-size: 14px; cursor: pointer; background: white; transition: background 0.3s; } .map-type-control button:hover { background: #f0f0f0; } .map-type-control button.active { background: #3f9dfd; color: white; } .map-type-control button:first-child { border-right: 1px solid #ddd; }*/ .SwitchGroups { position: absolute; top: 2.5vw; left: 50%; transform: translate(-50%, -50%); display: flex; z-index: 1000; } .device-status-item { display: flex; align-items: center; gap: 8px; margin-right: 16px; position: relative; } .status-button { padding: 6px 12px; background-color: #ffffff; border: 0px solid #00c6ff; color: rgba(0, 0, 0, 0.8); border-radius: 4px; font-size: 14px; cursor: pointer; transition: background-color 0.3s; } .status-button.active, .status-button:hover { background-color: rgb(63, 157, 253); color: rgb(255, 255, 255); } .status-count { position: absolute; top: -10px; right: -10px; min-width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: bold; padding: 0 4px; background-color: #41d2ff; color: white; } </style> <script> export default { data() { return { map: null, currentMapType: 'normal', activeDeviceType: 'all', // 当前激活的设备类型 centerPoint: { lng: 108.3665, lat: 22.8170 }, // 设备数据示例 devices: { all: [ { id: 1, name: "设备1", lng: 108.2865, lat: 22.7870, status: "online"}, { id: 2, name: "设备2", lng: 108.3465, lat: 22.8370, status: "online"}, { id: 3, name: "设备3", lng: 108.3165, lat: 22.8170, status: "online"}, { id: 4, name: "设备4", lng: 108.3765, lat: 22.7970, status: "online"}, { id: 5, name: "设备5", lng: 108.4065, lat: 22.8270, status: "offline"}, { id: 6, name: "设备6", lng: 108.2665, lat: 22.7570, status: "offline"}, { id: 7, name: "设备7", lng: 108.3365, lat: 22.7670, status: "inactive"}, { id: 8, name: "设备8", lng: 108.3965, lat: 22.8470, status: "warning"} ], online: [], offline: [], inactive: [], warning: [] }, markers: [], // 存储地图标记 }; }, mounted() { this.loadBaiduMapScript(); }, methods: { loadBaiduMapScript() { const script = document.createElement('script'); script.src = 'https://api.map.baidu.com/api?v=3.0&ak=FZX9w4i9N5zOy1yDFTc2XnkbVz5uyzHB&callback=initMap'; script.type = 'text/javascript'; document.body.appendChild(script); window.initMap = this.initMap; }, initMap() { this.map = new BMap.Map("map-container"); const point = new BMap.Point(this.centerPoint.lng, this.centerPoint.lat); this.map.centerAndZoom(point, 12); this.map.enableScrollWheelZoom(true); this.map.addControl(new BMap.MapTypeControl({ mapTypes: [BMAP_NORMAL_MAP, BMAP_SATELLITE_MAP, BMAP_HYBRID_MAP] })); this.map.setMapType(BMAP_NORMAL_MAP); // 初始化设备数据 this.initDeviceData(); // 显示所有设备 this.showDevices('all'); }, // 初始化设备数据 initDeviceData() { // 根据总设备列表分类 this.devices.all.forEach(device => { if (device.status === 'online') { this.devices.online.push(device); } else if (device.status === 'offline') { this.devices.offline.push(device); } else if (device.status === 'inactive') { this.devices.inactive.push(device); } else if (device.status === 'warning') { this.devices.warning.push(device); } }); }, // 切换设备类型 switchDeviceType(type) { this.activeDeviceType = type; this.showDevices(type); }, // 显示指定类型的设备 showDevices(type) { // 清除现有标记 this.clearMarkers(); // 获取对应类型的设备 const devicesToShow = this.devices[type] || this.devices.all; // 在地图上添加标记 devicesToShow.forEach(device => { const point = new BMap.Point(device.lng, device.lat); const marker = new BMap.Marker(point); this.map.addOverlay(marker); this.markers.push(marker); // 可以添加信息窗口 const infoWindow = new BMap.InfoWindow(`设备名称: ${device.name}
状态: ${device.status}`); marker.addEventListener("click", function() { this.openInfoWindow(infoWindow); }); }); // 如果有设备,调整地图视野 if (devicesToShow.length > 0) { const points = devicesToShow.map(device => new BMap.Point(device.lng, device.lat)); this.map.setViewport(points); } }, // 清除地图标记 clearMarkers() { this.markers.forEach(marker => { this.map.removeOverlay(marker); }); this.markers = []; }, switchMapType(type) { if (!this.map) return; this.currentMapType = type; if (type === 'normal') { this.map.setMapType(BMAP_NORMAL_MAP); } else if (type === 'satellite') { this.map.setMapType(BMAP_HYBRID_MAP); } } } }; </script> 这代码是在ruoyi-ui的vue页面 在上面代码中添加百度地图的默认点聚合功能

filetype

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>百度地图导航 - 王胜(22016020242)</title> <script type="text/javascript" src="https://api.map.baidu.com/api?v=3.0&ak=nhLolWSYNOZrhP1mAmZM7Hkj1WKr6kiW"></script> <style> body, html { width: 100%; height: 100%; margin: 0; padding: 0; font-family: "Microsoft YaHei", sans-serif; } #map-container { width: 100%; height: 100%; } #control-panel { position: absolute; top: 10px; left: 10px; z-index: 1000; background: white; padding: 15px; border-radius: 8px; box-shadow: 0 0 15px rgba(0,0,0,0.2); width: 320px; max-height: 90%; overflow-y: auto; } #search-input { width: 200px; padding: 8px; margin-right: 5px; border: 1px solid #ddd; border-radius: 4px; } #search-btn, #locate-btn, #start-navi-btn { padding: 8px 15px; cursor: pointer; color: white; border: none; border-radius: 4px; margin-top: 5px; } #search-btn, #locate-btn { background-color: #3388ff; } #search-btn:hover, #locate-btn:hover { background-color: #2a6fcc; } #start-navi-btn { background-color: #4CAF50; display: none; width: 100%; font-weight: bold; } #start-navi-btn:hover { background-color: #45a049; } .info { margin-bottom: 15px; padding-bottom: 15px; border-bottom: 1px solid #eee; } .location-details { margin-top: 15px; font-size: 14px; line-height: 1.6; } .coordinate { font-family: monospace; background-color: #f5f5f5; padding: 2px 5px; border-radius: 3px; } .search-results { margin-top: 10px; max-height: 200px; overflow-y: auto; border: 1px solid #eee; border-radius: 4px; padding: 5px; } .search-result-item { padding: 8px; border-bottom: 1px solid #eee; cursor: pointer; } .search-result-item:hover { background-color: #f5f5f5; } .search-result-item:last-child { border-bottom: none; } .search-result-title { font-weight: bold; margin-bottom: 3px; } .search-result-address { color: #666; font-size: 12px; } .navi-panel { margin-top: 15px; padding: 10px; background-color: #f0f8ff; border-radius: 5px; border: 1px solid #d0e3ff; display: none; } .navi-info { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid #d0e3ff; } .navi-steps { max-height: 300px; overflow-y: auto; } .navi-step { margin-bottom: 8px; padding-left: 20px; position: relative; } .navi-step:before { content: "•"; position: absolute; left: 5px; color: #3388ff; font-weight: bold; } .arrival-message { color: #4CAF50; font-weight: bold; padding: 10px; background-color: #f8fff8; border: 1px solid #4CAF50; border-radius: 4px; margin-top: 10px; } .route-instruction { margin-top: 5px; padding: 5px; background-color: #f9f9f9; border-radius: 3px; font-size: 13px; } </style> </head> <body>

个人信息

姓名:王胜

学号:22016020242

<input id="search-input" type="text" placeholder="输入目的地"> <button id="search-btn">搜索</button> <button id="locate-btn">定位</button>

导航信息

起点:正在获取当前位置...

终点:

距离:

预计时间:

<button id="start-navi-btn">开始导航</button>
<script type="text/javascript"> // 初始化地图 var map = new BMap.Map("map-container"); var geoc = new BMap.Geocoder(); // 地理编码器 var localSearch = new BMap.LocalSearch(map, { renderOptions: {map: map, panel: "search-results"}, onSearchComplete: function(results){ if (localSearch.getStatus() == BMAP_STATUS_SUCCESS){ document.getElementById("search-results").style.display = "block"; } } }); // 本地搜索 var walkingRoute = new BMap.WalkingRoute(map); // 步行导航 var currentPosition = null; // 存储当前位置 var destination = null; // 存储目的地 var naviMarker = null; // 导航标记 var naviPolyline = null; // 导航路线 // 添加地图控件 map.addControl(new BMap.NavigationControl()); map.addControl(new BMap.ScaleControl()); map.enableScrollWheelZoom(); // 启用滚轮缩放 // 默认定位到北京 map.centerAndZoom(new BMap.Point(116.404, 39.915), 15); // 定位当前位置并显示详细信息 function locate() { var geolocation = new BMap.Geolocation(); geolocation.enableSDKLocation(); // 启用SDK辅助定位 geolocation.getCurrentPosition(function(r) { if(this.getStatus() == BMAP_STATUS_SUCCESS) { currentPosition = r.point; map.panTo(currentPosition); map.setZoom(17); // 设置更合适的缩放级别 // 清除之前的标记 map.clearOverlays(); // 添加定位标记(使用更明显的图标) var marker = new BMap.Marker(currentPosition, { icon: new BMap.Icon("http://api.map.baidu.com/images/markers.png", new BMap.Size(23, 25), { offset: new BMap.Size(10, 25), imageOffset: new BMap.Size(0, 0) }) }); map.addOverlay(marker); // 获取更详细的地址信息 geoc.getLocation(currentPosition, function(rs) { var addComp = rs.addressComponents; var address = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber; var detailInfo = rs.surroundingPois ? rs.surroundingPois[0] : null; // 构建更详细的定位信息 var locationHTML = '

当前位置详情

' + '

经纬度:' + currentPosition.lng.toFixed(6) + ', ' + currentPosition.lat.toFixed(6) + '

' + '

详细地址:' + address + '

' + '

行政区:' + addComp.province + ' ' + addComp.city + ' ' + addComp.district + '

'; if(detailInfo) { locationHTML += '

附近:' + detailInfo.title + '(约' + Math.round(detailInfo._distance) + '米)

'; } // 添加精度信息 if(r.accuracy) { locationHTML += '

定位精度:' + Math.round(r.accuracy) + '米

'; } document.getElementById("location-details").innerHTML = locationHTML; document.getElementById("navi-start").textContent = addComp.street + addComp.streetNumber; // 更新标记标签 var label = new BMap.Label("我的位置: " + addComp.street + addComp.streetNumber, { offset: new BMap.Size(20, -10), position: currentPosition }); label.setStyle({ color: "#333", fontSize: "14px", backgroundColor: "white", padding: "5px 10px", border: "1px solid #ccc", borderRadius: "4px" }); marker.setLabel(label); }); } else { alert('定位失败: ' + this.getStatus()); document.getElementById("location-details").innerHTML = '

定位失败,请确保已授权地理位置权限

'; } }, {enableHighAccuracy: true}); // 启用高精度模式 } // 搜索地点 function search() { var keyword = document.getElementById("search-input").value; if(!keyword) { alert("请输入搜索关键词"); return; } localSearch.search(keyword); } // 计算步行路线 function calculateRoute(endPoint, endTitle) { if (!currentPosition) { alert("请先获取当前位置"); return; } destination = endPoint; walkingRoute.setSearchCompleteCallback(function(routeResult) { var plan = routeResult.getPlan(0); // 显示导航信息 document.getElementById("navi-end").textContent = endTitle || "目的地"; document.getElementById("navi-distance").textContent = plan.getDistance(true); document.getElementById("navi-duration").textContent = plan.getDuration(true); // 显示导航步骤 var stepsHTML = ""; var route = plan.getRoute(0); for(var i = 0; i < route.getNumSteps(); i++) { var step = route.getStep(i); stepsHTML += '<div class="navi-step">' + step.getDescription(true) + '
'; } document.getElementById("navi-steps").innerHTML = stepsHTML; // 显示导航面板和开始导航按钮 document.getElementById("navi-panel").style.display = "block"; document.getElementById("start-navi-btn").style.display = "block"; // 绘制路线 map.clearOverlays(); // 起点标记 var startMarker = new BMap.Marker(plan.getStart().point, { icon: new BMap.Icon("http://api.map.baidu.com/images/markers.png", new BMap.Size(23, 25), { offset: new BMap.Size(10, 25), imageOffset: new BMap.Size(0, 0) }) }); map.addOverlay(startMarker); // 终点标记 var endMarker = new BMap.Marker(plan.getEnd().point, { icon: new BMap.Icon("http://api.map.baidu.com/images/markers.png", new BMap.Size(23, 25), { offset: new BMap.Size(10, 25), imageOffset: new BMap.Size(0, -250) }) }); map.addOverlay(endMarker); // 绘制路线(更明显的样式) var path = []; for(var i = 0; i < route.getNumSteps(); i++) { var step = route.getStep(i); path = path.concat(step.getPath()); } naviPolyline = new BMap.Polyline(path, { strokeColor: "#3388ff", strokeWeight: 6, strokeOpacity: 0.8 }); map.addOverlay(naviPolyline); // 调整视图显示整个路线 map.setViewport([plan.getStart().point, plan.getEnd().point]); }); walkingRoute.search(currentPosition, endPoint); } // 开始导航 function startNavigation() { if (!currentPosition || !destination) { alert("无法开始导航,请先设置起点和目的地"); return; } // 清除之前的导航标记和到达信息 if (naviMarker) { map.removeOverlay(naviMarker); } var arrivalMsg = document.querySelector(".arrival-message"); if (arrivalMsg) { arrivalMsg.remove(); } // 创建导航标记 naviMarker = new BMap.Marker(currentPosition, { icon: new BMap.Icon("http://api.map.baidu.com/images/markers.png", new BMap.Size(23, 25), { offset: new BMap.Size(10, 25), imageOffset: new BMap.Size(0, 0) }) }); map.addOverlay(naviMarker); // 开始实时定位 var geolocation = new BMap.Geolocation(); geolocation.enableSDKLocation(); // 实时更新位置 var watchId = geolocation.watchPosition(function(r) { if (this.getStatus() == BMAP_STATUS_SUCCESS) { currentPosition = r.point; naviMarker.setPosition(currentPosition); // 计算到目的地的距离 var distance = map.getDistance(currentPosition, destination); if (distance < 20) { // 距离小于20米认为到达目的地 geolocation.clearWatch(watchId); var naviPanel = document.getElementById("navi-panel"); var arrivalDiv = document.createElement("div"); arrivalDiv.className = "arrival-message"; arrivalDiv.textContent = "您已到达目的地附近!"; naviPanel.appendChild(arrivalDiv); } } else { alert('定位失败: ' + this.getStatus()); geolocation.clearWatch(watchId); } }, {enableHighAccuracy: true, maximumAge: 1000}); alert("导航已开始!请按照路线指引前往目的地。"); } // 绑定按钮事件 document.getElementById("locate-btn").onclick = locate; document.getElementById("search-btn").onclick = search; document.getElementById("start-navi-btn").onclick = startNavigation; // 点击搜索结果项时计算路线 document.getElementById("search-results").addEventListener("click", function(e) { var item = e.target.closest(".search-result-item"); if(item) { var index = Array.from(item.parentNode.children).indexOf(item); var poi = localSearch.getResults().getPoi(index); map.panTo(poi.point); calculateRoute(poi.point, poi.title + "(" + poi.address + ")"); document.getElementById("search-results").style.display = "none"; } }); // 初始定位 locate(); </script> </body> </html>优化代码
蜜蜜蜜蜜糖
  • 粉丝: 24
上传资源 快速赚钱