Skip to content

Commit

Permalink
feat: DrawingManager添加autoViewport配置
Browse files Browse the repository at this point in the history
  • Loading branch information
L-hikari committed Sep 13, 2024
1 parent 6b251b2 commit 41caea0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
11 changes: 11 additions & 0 deletions DrawingManager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
|------|--------|-------------|
| isOpen | `Boolean` | 是否开启绘制模式 |
| confirmVisible | `Boolean` | 绘制完成后是否显示确认框,默认值为true,若设置为false则limit相关限制将失效。可以通过监听`overlaycomplete`事件,通过`e.calculate`判断是否超出限制 |
| autoViewport | `Boolean` | 是否自动调整地图视野,默认值为true |
| enableSorption | `Boolean` | 是否开启吸附功能,默认值为false |
| sorptiondistance | `Number` | 吸附的像素距离,默认值为20 |
| enableCalculate | `Boolean` | 是否开启面积计算功能,默认值为false,依赖BMapGLLib.GeoUtils |
Expand Down Expand Up @@ -62,6 +63,7 @@
| disableSorption | none | 关闭吸附功能 | none |
| getOverlays | none | 获取绘制的所有覆盖物 | `Overlay[]` |
| clearOverlays | none | 清除所有绘制的覆盖物 | none |
| clearOverlay | overlay | 清除指定的覆盖物 | none |
| addEventListener | event, handler | 添加事件监听函数 | none |
| removeEventListener | event, handler | 删除事件监听函数 | none |

Expand All @@ -79,3 +81,12 @@
| calculate | `string` | 开启`enableCalculate`后生效,值为绘制后的overlay面积或长度 |
| overlay | `Overlay` | 绘制完成的覆盖物 |
| drawingMode | `string` | 绘制类型,参考drawingToolOptions.drawingModes |

# DrawingMode
| Name | Description | value |
|------|-------------|-----|
| BMAP_DRAWING_MARKER | 绘制点 | `marker` |
| BMAP_DRAWING_CIRCLE | 绘制圆 | `circle` |
| BMAP_DRAWING_POLYLINE | 绘制折线 | `polyline` |
| BMAP_DRAWING_POLYGON | 绘制多边形 | `polygon` |
| BMAP_DRAWING_RECTANGLE | 绘制矩形 | `rectangle` |
13 changes: 10 additions & 3 deletions DrawingManager/src/DrawingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,7 @@ var BMAP_DRAWING_MARKER = "marker", // 鼠标画点模式
*/
this._opts = opts;
this._opts.confirmVisible = opts.confirmVisible === false ? false : true;
this._opts.autoViewport = opts.autoViewport === false ? false : true;

/**
* 当前的绘制模式, 默认是绘制点
Expand Down Expand Up @@ -1258,7 +1259,9 @@ var BMAP_DRAWING_MARKER = "marker", // 鼠标画点模式
var endAction = function (e) {
var cz = map.getViewport(circle.getBounds());
cz.zoom -= 1;
map.setViewport(cz);
if (me._opts.autoViewport) {
map.setViewport(cz);
}
map.removeOverlay(tip_label);

var endPoint = new BMapGL.Point(circle.getBounds().getNorthEast().lng, centerPoint.lat);
Expand Down Expand Up @@ -1576,7 +1579,9 @@ var BMAP_DRAWING_MARKER = "marker", // 鼠标画点模式
overlay.setPath(points);
var cz = map.getViewport(points);
cz.zoom -= 1;
map.setViewport(cz);
if (me._opts.autoViewport) {
map.setViewport(cz);
}

overlay.enableEditing();
var limit = null;
Expand Down Expand Up @@ -1757,7 +1762,9 @@ var BMAP_DRAWING_MARKER = "marker", // 鼠标画点模式
var operateWindow;
var confirmVisible = me._opts.confirmVisible;
cz.zoom -= 1;
map.setViewport(cz);
if (me._opts.autoViewport) {
map.setViewport(cz);
}
map.removeOverlay(tip_label);

var width = me._map.getDistance(startPoint, points[2]).toFixed(0);
Expand Down
2 changes: 1 addition & 1 deletion DrawingManager/src/DrawingManager.min.js

Large diffs are not rendered by default.

0 comments on commit 41caea0

Please sign in to comment.