Coder Social home page Coder Social logo

l7draw's Introduction

L7Draw

基于 L7 封装的地理绘制库,支持在地图上通过单击、拖拽等方式绘制点、线、面的 GeoJSON 的数据

npm Version npm Download

文档 · 示例

🔨 工具

基于 L7Draw 的面向 GeoJSON 编辑工具 L7Editor 已上线,欢迎尝鲜~。

📦 安装

npm install -S @antv/l7-draw

🔨 使用

通过 NPM 引入

// ----js-----
import { GaodeMap, Scene } from '@antv/l7';
import { DrawEvent, DrawPoint } from '@antv/l7-draw';

const scene = new Scene({
  id: 'map',
  map: new GaodeMap({}),
});

scene.on('loaded', () => {
  // 实例化 Draw
  const draw = new DrawPoint(scene, {
    editable: false,
    // Draw 配置
  });

  // 调用 Draw 上的方法
  draw.enable();

  // 监听 Draw 的事件
  draw.on(DrawEvent.Add, (newPoint) => {
    console.log(newPoint);
  });
});

// ----html----
<div id="map"></div>;

通过 CDN 引入

<!-- 引入依赖包 -->
<script src="https://unpkg.com/@antv/l7"></script>
<script src="https://unpkg.com/@antv/l7-draw"></script>

<script>
  const scene = new L7.Scene({
    id: 'map',
    map: new L7.GaodeMap({
      style: 'dark',
      center: [104.288144, 31.239692],
      zoom: 4.4,
    }),
  });
  scene.on('loaded', () => {
    // 通过 L7.Draw.*** 访问
    const draw = new L7.Draw.DrawPoint(scene, {});
    draw.enable();
  });
</script>

⌨️ 本地开发

# 安装依赖
npm install

# 运行页面
npm run start

# 打包
npm run build

💬 答疑

在使用 L7Draw 过程中,若有疑惑无法在文档中解决的可以扫码加入 L7 官方答疑群。

📋 待办

  • 新增 Marker 绘制类型
  • 新增 文本 绘制类型
  • 新增支持编辑挖孔 Polygon
  • 新增 两个 Polygon 交/并/异或/差集(合并/挖孔/切割)
  • 优化 DrawControl Icon

🤝 如何贡献

如果您在使用的过程中碰到问题,可以先通过 issues 看看有没有类似的 bug 或者建议。

📖 许可证

MIT@AntV.

l7draw's People

Contributors

heiyexing avatar lzxue avatar richard-choooou avatar serializedowen avatar websybin avatar yanyu510 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

l7draw's Issues

🥰 [FEATURE] 限制绘制半径

💻 Features description [Please make everyone to understand it]

2024-04-01 17 37 24

🏞 What problem does this feature solve

🧐 What does the proposed API look like

🚑 Any additional [like screenshots]

🐛 [BUG] DrawPoint 图片显示异常

🐛 Bug description [Please make everyone to understand it]

Please provide a link by forking these links L7 Draw or GitHub repo, a minimal reproduction.

  • Required Link to minimal reproduction:

📷 Step to reproduce

把官方例子 docs/example/point/image.tsx 中的图片链接替换为其他图片,如 https://gw.alipayobjects.com/zos/antfincdn/tWx6gaMr9P/zhongguoyinhang.png
绘制出来的点显示异常

image

🏞 Expected result

🚑 Any additional [like screenshots]

  • L7Draw Version:
  • Platform:

🥰 [FEATURE] 在实例化之后通过函数设置是否允许二次编辑

💻 Features description [Please make everyone to understand it]

提供在实例化之后设置是否允许二次编辑的方法

🏞 What problem does this feature solve

目前只能在初始化的时候用 editable 参数设置是否允许二次编辑的方法,如果用户要在允许编辑和不允许编辑中切换需要重新实例化

🧐 What does the proposed API look like

拓展 enable 函数,类似 allowCreate 参数增加 allowEdit 参数控制是否允许二次编辑

🚑 Any additional [like screenshots]

🐛 [BUG]leaflet的地图缩放后,绘制异常

代码:https://codesandbox.io/s/priceless-cache-sc6w8j?file=/index.js
leaflet的地图缩放后,拖拽顶点,顶点和鼠标的位置不一致

🐛 Bug description [Please make everyone to understand it]

Please provide a link by forking these links L7 Draw or GitHub repo, a minimal reproduction.

  • Required Link to minimal reproduction:

📷 Step to reproduce

🏞 Expected result

🚑 Any additional [like screenshots]

  • L7Draw Version:3.0.14
  • Platform:chrome117

sceneContainer.get is not a function

          const drawControl = new DrawControl(s, {
              position: 'topright',
              layout: 'horizontal', // horizontal vertical
              controls: {
                polygon: {
                  selectEnable: true,
                  showFeature: true,
                  data: polygonData,
                },
                delete: true,
              },
            }); 
          s.addControl(drawControl);

image
地图用的是 "@antv/l7-react": "2.3.9",里面的AMapSceneV2
之前一直没问题,重装依赖就不行了,是版本问题?

🐛 [BUG]使用L7集成threejs,使用gltf作为layer,出现图层崩溃的bug

🐛 Bug description [Please make everyone to understand it]

Please provide a link by forking these links L7 Draw or GitHub repo, a minimal reproduction.
这个bug比较隐蔽,具体是webgl崩溃引起的,代码太多不好提供。

  • Required Link to minimal reproduction:

📷 Step to reproduce

1,使用L7的RasterLayer加载本地xyz瓦片。
2,使用scene addImage 加载本地图片资源。
3,集成threejs,并且加载gltf图层。
4,使用L7Darw画图形的时候,整个RasterLayer会被 addImage使用的资源覆盖。
5,控制台中,显示WebGL: INVALID_ENUM: activeTexture: texture unit out of range

🏞 Expected result

🚑 Any additional [like screenshots]

image

  • L7Draw Version:
  • Platform:

绘制的面是如何放在其他图层上的

🐛 Question description [Please make everyone to understand it]

💻 Link to minimal reproduction

Please provide a link by forking these links L7 Draw or GitHub repo. What is a minimal reproduction, and why is it required?

🏞 Expected result

🚑 Any additional [like screenshots]

  • L7Draw Version:
  • Platform:

如何禁用绘制面时鼠标按住的拖拽

如何禁用绘制面时鼠标按住的拖拽?
当设置editable: false, // 禁用编辑时 确实可以禁用拖拽,但我想保留快捷操作(回退,重做,删除)。
scene.on('loaded', () => {
const drawer = new DrawPolygon(scene, {
distanceOptions: {},
areaOptions: {},
liveUpdate: true,
});
drawer.enable();
});

🥰 [FEATURE] 希望官方可以给出vue的demo示例

💻 Features description [Please make everyone to understand it]

🏞 What problem does this feature solve

🧐 What does the proposed API look like

🚑 Any additional [like screenshots]

希望官方可以给出vue的demo示例

DrawCircle 和 DrawRect 提供指定初始数据的功能

文档中提到:

配置项 DrawOption

  • data `geojson' 初始化数据仅支持 Polygon, Line, Point, 不支持MultPolygon,Circle 可用编辑现有数据

请问能否支持 Circle 和 Rect 指定初始数据?

或者有什么其他方法能够实现保存的绘制数据能够回显出来?

增加一个可绘制的 marker

💻 Features description

增加一个可绘制的 l7中的 marker 标注(可自定义点内容)

🏞 What problem does this feature solve

针对自定义点内容较强的场景

🧐 What does the proposed API look like

类似 l7 中的marker 增加一个element 属性
initData 中的 Geojson 感觉可以在类型 point 上做一些 properties 的扩展来识别是marker

怎么设置初始绘图数据?

即: 在新建控件时带上初始的数据?
另: 怎样通过程序的方法控制绘图?
调用 绘图控件的 protected drawLayer 和 drawVertexLayer 可以显示,有更正常的方法?

关于绘制过程中,卡顿的情况

L7Draw这个插件效果非常漂亮,我使用的过程中遇到一个问题,比如绘制一个矩形,鼠标点了第一个点,拖动的过程中,形状没有很跟随鼠标,感觉又点卡卡的。但是看官方react版本的示例[https://l7draw.antv.vision/example/map/gaode],却没有这种情况,绘制的过程鼠标拖动绘制很流畅,这是为啥?有大佬可以指点一下我吗?我是遗漏了什么细节吗?我代码是这样子:

<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>l7-draw</title>
    <script src="https://unpkg.com/@antv/l7"></script>
    <script src="https://unpkg.com/@antv/l7-draw"></script>
    <style>
      * {
        padding: 0;
        margin: 0;
      }
      html,
      body,
      #map {
        width: 100%;
        height: 100%;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script>
      const scene = new L7.Scene({
        id: "map",
        map: new L7.GaodeMap({
          center: [120.151634, 30.244831],
          pitch: 0,
          style: "dark",
          zoom: 10,
        }),
      });
      scene.on("loaded", () => {
        const drawControl = new L7.Draw.DrawControl(scene, {
          defaultActiveType: "rect",
        });

        scene.addControl(drawControl);
      });
    </script>
  </body>
</html>

DrawLine完成折线绘制后报错

您好,最近在我自己的项目中使用DrawLine在地图上绘制折线,在点击最后一个点来完成绘制时会有(regl) invalid buffer data以及(uncatch in Promise)nvalid buffer data 的报错,一直没能解决,前来请教。我在codesandbox里运行如下代码:

import { AMapScene, LineLayer } from '@antv/l7-react';
import * as React from 'react';
import { Scene } from '@antv/l7';
import { DrawCircle,DrawLine } from '@antv/l7-draw';
import ReactDOM from 'react-dom';
import { Button } from 'antd';
import { GaodeMap } from "@antv/l7-maps";

const scene = new Scene({
  id: "map",
  map: new GaodeMap({
    pitch: 0,
    style: "light",
    center: [113.775374, 28.31067],
    zoom: 12
  })
});

const MapScene = React.memo(function Map() {
  
  function handlescene (scene){
    scene.on('mouseover',()=>{
    const drawLine = new DrawLine(scene,{editEnable:false,selectEnable:false,style:{
      normal: {
        line: {
          type: 'LineLayer',
          shape: 'line',
          size: 0,
          color: '#fff',
          style: {
            opacity: 0,
            stroke: '#fff',
            strokeWidth: 0
          },
        },     
      },
    }});
    try{
      drawLine.enable();
    }catch(e){}
    
  });
  };
  
  return (
    <React.Fragment>  
    <AMapScene
      map={{
        center: [ 110.19382669582967, 50.258134 ],
        pitch: 0,
        style: 'dark',
        zoom: 1,
      }}
      style={{
        position: 'absolute',
        top: 0,
        left: 0,
        right: 0,
        bottom: 0
      }}
      onSceneLoaded={scene => {
            handlescene(scene);
          }}
    />
    <Button >aa</Button>
    </React.Fragment>
  );
});


ReactDOM.render(<MapScene/>, document.getElementById('map'));

这样,在图上任意一处完成绘制后,就会得到如下报错
err

希望移动端支持移动绘制区域

🐛 Bug description [Please make everyone to understand it]

Please provide a link by forking these links L7 Draw or GitHub repo, a minimal reproduction.

  • Required Link to minimal reproduction:

📷 Step to reproduce

🏞 Expected result

🚑 Any additional [like screenshots]

主要是给一些 win平板带触摸屏使用, 这种平板没有鼠标

  • L7Draw Version:
  • Platform:

Macos 12.5 Monterey
MacBook Air (M1, 2020)

"dependencies": {
"@antv/l7": "latest",
"@antv/l7-draw": "latest",
"@antv/l7-maps": "latest"
},

移动端 无法移动绘制区域

codesandbox
测试链接 : https://codesandbox.io/s/elegant-germain-z2dvrm?file=/package.json:3-113

🥰 [FEATURE]DrawLine

目前画线只有计算距离,能否加上角度,或者在配置的format参数中加上计算出该距离的两点经纬度。

🐛 [BUG] 关闭圆绘制时导致mapbox的双击放大打开

🐛 Bug description [Please make everyone to understand it]

📷 Step to reproduce

// 控制台调用
window._circle.disable()

🏞 Expected result

正常关闭圆形绘制或无任何反馈

🚑 Any additional [like screenshots]

当我调用此方法会导致mapbox的双击方法开启
image

  • L7Draw Version: "@antv/l7-draw": "^3.0.34",
  • Platform: macos(14.1 (23B74)), chrome(118.0.5993.117)

🥰 [FEATURE] 多种类型的图形无法同时编辑,期望能够同时编辑

💻 Features description [Please make everyone to understand it]

目前的DrawControl支持在地图上绘制多种图形,但是必须选中某一种类型,才可以编辑那一类下的所有图形。
image

🏞 What problem does this feature solve

期望能够有一个配置项,能够在一个draw里面编辑多种绘制类型。

🧐 What does the proposed API look like

🚑 Any additional [like screenshots]

🐛 [BUG] multiple:false 在设置 initialData 后表现错误

🐛 Bug description [Please make everyone to understand it]

初始化DrawPolygon类时,设置 multiple:falseinitialData,此时,地图展示initialData对应的图形,同时仍然可以进行新多边形的绘制,此时进行绘制,会继续增加一个多边形,然后无法新创建多边形。

Please provide a link by forking these links L7 Draw or GitHub repo, a minimal reproduction.

  • Required Link to minimal reproduction:

https://codesandbox.io/embed/upbeat-tharp-5dzmml?fontsize=14&hidenavigation=1&theme=dark&view=preview

📷 Step to reproduce

参考codesandbox,只要设置 multiple:falseinitialData即可重现

🏞 Expected result

当设置 multiple:falseinitialData时,默认应该只允许编辑已有图形。

🚑 Any additional [like screenshots]

  • L7Draw Version: 3.0.25
  • Platform: Mac

DrawControl中initialData报错 🐛 [BUG]

const drawControl = new DrawControl(scene, {
        defaultActiveType: "point",
        drawConfig: {
          point: true,
          line: true
          polygon: true,
          rect: false,
          circle: false,
        },
        commonDrawOptions: {
          multiple: true,
          initialData,
        },
      });
      scene.addControl(drawControl);

当 drawConfig中polygon为true时,如果commonDrawOptions中指定了initialData,那么就会报错:

TypeError: Cannot read properties of undefined (reading 'geometry')
at http://localhost:5173/node_modules/.vite/deps/chunk-22O55J6X.js?v=cf20a5eb:45921:147
at Array.map ()
at PolygonDrawer2.setData4 (http://localhost:5173/node_modules/.vite/deps/chunk-22O55J6X.js?v=cf20a5eb:45909:54)
at new BaseMode2 (http://localhost:5173/node_modules/.vite/deps/chunk-22O55J6X.js?v=cf20a5eb:41062:13)
at _callSuper11 (http://localhost:5173/node_modules/.vite/deps/chunk-22O55J6X.js?v=cf20a5eb:41665:108)
at new PointMode2 (http://localhost:5173/node_modules/.vite/deps/chunk-22O55J6X.js?v=cf20a5eb:41717:12)
at _callSuper12 (http://localhost:5173/node_modules/.vite/deps/chunk-22O55J6X.js?v=cf20a5eb:42094:108)
at new MidPointMode2 (http://localhost:5173/node_modules/.vite/deps/chunk-22O55J6X.js?v=cf20a5eb:42171:12)
at _callSuper13 (http://localhost:5173/node_modules/.vite/deps/chunk-22O55J6X.js?v=cf20a5eb:42419:108)
at new LineMode2 (http://localhost:5173/node_modules/.vite/deps/chunk-22O55J6X.js?v=cf20a5eb:42500:13)

🐛 Bug description [Please make everyone to understand it]

Please provide a link by forking these links L7 Draw or GitHub repo, a minimal reproduction.

  • Required Link to minimal reproduction:

📷 Step to reproduce

🏞 Expected result

🚑 Any additional [like screenshots]

  • L7Draw Version:
  • Platform:

DrawLine

问题描述

目前画线只有计算距离,能否加上角度,或者在配置的format参数中加上计算出该距离的两点经纬度。

重现链接

No response

重现步骤

No response

预期行为

No response

平台

  • 操作系统: [macOS, Windows, Linux, React Native ...]
  • 网页浏览器: [Google Chrome, Safari, Firefox]

屏幕截图或视频(可选)

No response

补充说明(可选)

No response

🐛 [BUG]使用L7集成L7Draw,发现无效图层的bug

🐛 Bug description [Please make everyone to understand it]

Please provide a link by forking these links L7 Draw or GitHub repo, a minimal reproduction.

drawControl() {
const drawControl = new DrawControl(this.scene, {
position: 'topright',
drawConfig: {
point: {
autoActive: false,
editable: false
},
line: {
autoActive: false,
editable: false
},
polygon: {
autoActive: false,
editable: false
},
rect: {
autoActive: false,
editable: false
},
circle: {
autoActive: false,
editable: false
},
clear: {
autoActive: false,
editable: false
},
}
});
// drawControl.on(ControlEvent.DrawChange, (changeType) => {
// console.log(changeType);
// });
// drawControl.on(ControlEvent.DataChange, (val) => {
// console.log(val);
// })
// drawControl.on(ControlEvent.DrawSelect, (val) => {
// console.log(val);
// });
// drawControl.on(ControlEvent.DrawClear, (val) => {
// console.log(val);
// })
return drawControl;
}

  • Required Link to minimal reproduction:

📷 Step to reproduce

使用L7作为地图的前端显示引擎,在使用scene.getLayers()方的时候,发现有20多个无效图层。

🏞 Expected result

如何关闭L7Draw的无效图层,或者能精准的过滤掉无效图层。

🚑 Any additional [like screenshots]

image

  • L7Draw Version:
  • Platform:

🥰 [FEATURE]环形多边形绘制

💻 Features description [Please make everyone to understand it]

在渲染环形多边形时,L7的图层渲染是正确格式,如果采用L7draw进行绘制,则内部环装无法闭合。

环形多边形渲染

  • L7Draw的渲染结果
    image
  • 高德datav的渲染结果
    image

🥰 [FEATURE] 关于吸附功能对GeoJSON数据多段线格式的支持

在地图中配置的 adsorbOptions.data 只支持单一的GeoJSON数据格式的问题, 希望能对GeoJSON 能支持的所有格式都兼容. 毕竟在业务中应用场景很常见, 并且我的面,线,点,是应该能够支持相互都可以吸附的, 而目前咱们仅支持的单一点,线,面的GeoJSON格式属于功能缺失,且不同类型之间还不可以吸附, 期待更新, 变大变强!!!~~~

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.