Browse Source

feat: 地图添加 marker

王晓东 3 ngày trước cách đây
mục cha
commit
d328e788bf
1 tập tin đã thay đổi với 17 bổ sung1 xóa
  1. 17 1
      src/components/widgets/widget-map/index.tsx

+ 17 - 1
src/components/widgets/widget-map/index.tsx

@@ -1,7 +1,8 @@
 import { View, Map } from '@tarojs/components'
 import style from './index.module.less'
-
+import avatarDefault from "@/images/avatar-default.png";
 import Taro from '@tarojs/taro';
+import { useState } from 'react';
 interface Props {
   children?: React.ReactChild |  React.ReactChild[];
   longitude: number
@@ -19,6 +20,20 @@ const Index: React.FC<Props> = ({children, latitude, longitude, name = '', addre
     console.log(e)
   }
 
+   // 标记点配置
+   const [markers] = useState([
+    {
+      id: 1, // 必须唯一
+      latitude: latitude,  // 纬度
+      longitude: longitude, // 经度
+      iconPath: avatarDefault, // 本地图标路径
+      width: 30,  // 图标宽度(像素)
+      height: 30, // 图标高度
+      title: name, // 点击时显示的标题
+    }
+  ])
+
+
   // const handleClick = () => {
   //   Taro.openLocation({
   //     latitude,
@@ -41,6 +56,7 @@ const Index: React.FC<Props> = ({children, latitude, longitude, name = '', addre
             onError={onError}
             longitude={longitude}
             latitude={latitude}
+            markers={markers}
             enableZoom={enableZoom}
             enableScroll={enableScroll}