@amap/amap-jsapi-loader 实现高德地图中添加多边围栏,并可编辑,编辑后获得围栏各个点的经纬度

先上一张效果图 看看是不是大家想要的效果~ ❤️
希望其中的小点能帮助大家,主要看怎么绘制在地图上的代码即可
在这里插入图片描述

1.第一步要加入项目package.json中或者直接yarn install它都可以
想必大家应该都会

 "@amap/amap-jsapi-loader": "0.0.7"

2.加入项目中

import React, {
    PureComponent } from 'react';
import {
    Radio, Checkbox, Input, Button, message as AntMessage } from 'antd';
import AMapLoader from '@amap/amap-jsapi-loader';
import {
    services } from '@comall-backend-builder/core';
import './index.less';

const {
    api } = services;
type Geofence = {
   
    /**
     * 圆形围栏中心点,格式:longitude,latitude
     */
    center?: string;
    /**
     * 围栏名称
     */
    name: string;
    /**
     * 多边形围栏坐标点,格式:lon1,lat1;lon2,lat2;lon3,lat3
     */
    points: string;
    /**
     * 圆形围栏半径,单位:米。范围0~5000
     */
    radius?: number;
};
type GeofenceValue = {
   
    geofences: Array<Geofence>;
    scope: string;
    isEdit?: boolean;
};
const DEFAULTSCOPE = 'CUSTOM';
const DEFAULTNAME = '默认区域';
interface GeofencesProps {
   
    onChange: (data: GeofenceValue) => void;
    /**
     * 当前值
     */
    value: GeofenceValue;
    row: any;
}

interface GeofencesStates {
   
    /**
     * 当前地图实例
     */
    map: any;
    /**
     * 地图api
     */
    AMap: any;
    /**
     * 多边形对象集合
     */
    polygons: any;
    /**
     * 门店位置标记
     */
    marker: any;
    /**
     * 当前的门店维度
     */
    centerPosition: any;
    /**
     * 当前的门店名称
     */
    subsiteName: string;
}

export class Geofences extends PureComponent<GeofencesProps, GeofencesStates> {
   
    constructor(props: any) {
   
        super(props);

        this.state = {
   
            map: undefined,
            AMap: undefined,
            polygons: undefined,
            marker: undefined,
            centerPosition: undefined,
            subsiteName: '',
        };
    }

    componentDidMount() {
   
        this.initMap();
    }

    initMap = () => {
   
        api.get({
   }, {
    apiPath: '/admin/amap/config' }).then((result: any) => {
   
            AMapLoader.load({
   
                key: result.key, // 申请好的Web端开发者Key,首次调用 load 时必填
                version: '1.4.15', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
                plugins: ['AMap.Marker', 'AMap.Polygon', 'AMap.PolyEditor'], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
            })
                .then((AMap: any) => {
   
                    let map = new AMap.Map('mapContainer', {
   
                        zoom: 13,
                    });
                    this.initSubsiteCenterPosition(AMap, map);
                    this.setState({
    AMap
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值