caner 11 months ago
parent
commit
0172af1521
1 changed files with 34 additions and 0 deletions
  1. 34 0
      src/pages/leaflet/index.vue

+ 34 - 0
src/pages/leaflet/index.vue

@@ -429,6 +429,40 @@ async function bindMarker(mapId: string) {
   // } while (page <= pages)
   // } while (page <= pages)
 }
 }
 
 
+// 自定义marker
+function drawMarker(item: { latLng: number[], icon: string, children: any, label: string }) {
+  if (!Map.value) return console.log('Map未初始化')
+  if (!item.latLng || !item.latLng.length) return console.log('缺少参数')
+  // 自定义图标
+  const img = `<div class="newMark" style="background-image:url(${item.icon})">${item.label}</div>`
+  const ICON = L.divIcon({
+    iconSize: [ 100, 28 ],
+    html: img,
+    iconAnchor: [ -5, 14 ]
+  })
+  const marker = L.marker(item.latLng as LatLngExpression, {
+    title: item.children[0],
+    icon: ICON,
+    draggable: false,
+    riseOnHover: true // 该标记将位于其他标记的顶部
+  })
+  marker.addTo(Map.value)
+  marker.addEventListener('click', (event) => {
+    console.log('marker点击', event)
+    const { options: { title } } = event.target
+    const path = userData.getUserData().permission.find((el: { url: string }) => el.url === '/objHome')
+    if (path) {
+      store.setCurrentTunnel({ ...title })
+      store.setCurrentUuid(null)
+      localStorage.setItem('currentTunnel', JSON.stringify({ ...title }))
+      router.push('/objHome')
+    } else {
+      window.$notification.warning({ title: '你没有权限,请联系管理员!', duration: 2000 })
+    }
+  })
+  return marker
+}
+
 // 切换底图
 // 切换底图
 async function changeMap(_: string, option: BaseMap) {
 async function changeMap(_: string, option: BaseMap) {
   console.log('切换底图', option)
   console.log('切换底图', option)