forked from gzzfw/frontEnd/gzDyh

zhangyongtian
2024-08-23 ed5aa7574929c135f1a35000f83c25a1a9f9bb97
gz-customerSystem/src/views/register/visit/component/map.jsx
@@ -2,7 +2,7 @@
 * @Author: dminyi 1301963064@qq.com
 * @Date: 2024-08-17 14:41:57
 * @LastEditors: dminyi 1301963064@qq.com
 * @LastEditTime: 2024-08-19 15:06:35
 * @LastEditTime: 2024-08-23 15:17:06
 * @FilePath: \gzDyh\gz-customerSystem\src\views\register\visit\component\map.jsx
 * @Description: 地图
 */
@@ -49,6 +49,7 @@
            if (point) {
              mapRef.current.map.centerAndZoom(point, 15);
              mapRef.current.map.addOverlay(new window.BMapGL.Marker(point, { title: values.name }))
              handleAnalysis(point, values.name); // 添加地点名称
            } else {
              Message.warning('您输入的地址没有解析到结果!');
            }
@@ -59,16 +60,21 @@
  }
  //解析地址为中文
  const handleAnalysis = (pt) => {
  const handleAnalysis = (pt,name) => {
    let geoc = new window.BMapGL.Geocoder();
    geoc.getLocation(pt, function (rs) {
      let addComp = rs.addressComponents;
      let addName = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber
      if (name) {
        addName += ` ${name}`; // 添加地点名称
      }
      mapRef.current.map.centerAndZoom(pt, 15);
      mapRef.current.map.addOverlay(new window.BMapGL.Marker(pt, { title: addName }))
      setAddressList([addName])
    })
  }
  console.log(addressList,'addressList')
  return (
    <div>
@@ -84,7 +90,7 @@
              label='查询位置:'
              field='name'
            >
              <Input placeholder='请输入' style={{ width: '515px' }} />
              <Input placeholder='请输入' style={{ width: '522px' }} />
            </FormItem>
            <Button style={{ marginRight: '20px' }}>
              重置
@@ -102,7 +108,7 @@
            enableScrollWheelZoom
            onClick={(e) => {
              let pt = e.latlng;
              handleAnalysis(pt)
              handleAnalysis(pt,null)
            }}
          >
          </Map>