diff --git a/ruoyi-admin/src/main/resources/templates/operation/store/add.html b/ruoyi-admin/src/main/resources/templates/operation/store/add.html index 4af52fb..5d0716e 100644 --- a/ruoyi-admin/src/main/resources/templates/operation/store/add.html +++ b/ruoyi-admin/src/main/resources/templates/operation/store/add.html @@ -318,21 +318,44 @@ function initMap() { // var position = document.getElementById("position"); - var center = new TMap.LatLng(28.228302,112.938901);//设置中心点坐标 + var center = new TMap.LatLng(28.228302, 112.938901); //设置中心点坐标 //初始化地图 - var map = new TMap.Map("mapContainer", { + map = new TMap.Map("mapContainer", { center: center }); - //绑定点击事件 - map.on("click",function(evt){ + // 创建标记图层 + markerLayer = new TMap.MultiMarker({ + map: map, + styles: { + // 定义标记样式 + "myMarker": new TMap.MarkerStyle({ + width: 32, + height: 32, + src: "https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/marker-default.png" // 使用你的自定义图标 + }) + }, + geometries: [] + }); + + // 绑定点击事件 + map.on("click", function(evt) { var lat = evt.latLng.getLat().toFixed(6); var lng = evt.latLng.getLng().toFixed(6); - // position.innerHTML = lat + "," + lng; $("#latitude").val(lat); $("#longitude").val(lng); - }) + + // 使用updateGeometries替换所有标记,确保只显示一个标记 + markerLayer.updateGeometries([ + { + id: "clickMarker", + styleId: "myMarker", + position: evt.latLng + } + ]); + + }); } // 初始化地图 diff --git a/ruoyi-admin/src/main/resources/templates/operation/store/edit.html b/ruoyi-admin/src/main/resources/templates/operation/store/edit.html index dcba225..eef9df3 100644 --- a/ruoyi-admin/src/main/resources/templates/operation/store/edit.html +++ b/ruoyi-admin/src/main/resources/templates/operation/store/edit.html @@ -342,10 +342,24 @@ var center = new TMap.LatLng(28.228302,112.938901);//设置中心点坐标 //初始化地图 - var map = new TMap.Map("mapContainer", { + map = new TMap.Map("mapContainer", { center: center }); + // 创建标记图层 + markerLayer = new TMap.MultiMarker({ + map: map, + styles: { + // 定义标记样式 + "myMarker": new TMap.MarkerStyle({ + width: 32, + height: 32, + src: "https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/marker-default.png" // 使用你的自定义图标 + }) + }, + geometries: [] + }); + //绑定点击事件 map.on("click",function(evt){ var lat = evt.latLng.getLat().toFixed(6); @@ -354,6 +368,15 @@ $("#latitude").val(lat); $("#longitude").val(lng); + + // 使用updateGeometries替换所有标记,确保只显示一个标记 + markerLayer.updateGeometries([ + { + id: "clickMarker", + styleId: "myMarker", + position: evt.latLng + } + ]); }) }