Skip to content

Commit d9926d6

Browse files
authored
Path edit center vertex ignore collision (#2403)
* Path edit center vertex ignore collision * map typing * updates * spec * update sepc
1 parent 59bc607 commit d9926d6

File tree

5 files changed

+62
-4
lines changed

5 files changed

+62
-4
lines changed

src/geometry/editor/GeometryEditor.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ class GeometryEditor extends Eventable(Class) {
339339
let shadow;
340340
const cointainerPoint = map.coordToContainerPoint(this._geometry.getCenter());
341341
const handle = this.createHandle(cointainerPoint, {
342+
ignoreCollision: true,
342343
'symbol': symbol,
343344
'cursor': 'move',
344345
onDown: (): void => {
@@ -373,7 +374,8 @@ class GeometryEditor extends Eventable(Class) {
373374
}
374375

375376
//@internal
376-
_createHandleInstance(containerPoint: any, opts: any): EditHandle {
377+
_createHandleInstance(containerPoint: Point, opts: GeometryEditOptionsType): EditHandle {
378+
opts = opts || {};
377379
const map = this.getMap();
378380
const symbol = loadFunctionTypes(opts['symbol'], (): any => {
379381
return [
@@ -386,7 +388,7 @@ class GeometryEditor extends Eventable(Class) {
386388
];
387389
});
388390
const removeVertexOn = this.options['removeVertexOn'];
389-
const handle = new EditHandle(this, map, { symbol, cursor: opts['cursor'], events: removeVertexOn as any });
391+
const handle = new EditHandle(this, map, { symbol, cursor: opts['cursor'], events: removeVertexOn as any, ignoreCollision: (opts as any).ignoreCollision });
390392
handle.setContainerPoint(containerPoint);
391393
return handle;
392394
}
@@ -967,6 +969,7 @@ class GeometryEditor extends Eventable(Class) {
967969
}
968970
const isEnd = (geoToEdit instanceof LineString) && (index === 0 || index === prjCoordinates.length - 1);
969971
prjCoordinates.splice(index, 1);
972+
970973
if (ringIndex > 0) {
971974
//update hole prj
972975
geoToEdit._prjHoles[ringIndex - 1] = prjCoordinates;
@@ -997,7 +1000,8 @@ class GeometryEditor extends Eventable(Class) {
9971000
//fix hole Vertex delete
9981001
const ring = coordiantes[ringIndex];
9991002
if (ring && Array.isArray(ring) && ring.length > 1) {
1000-
ring.splice(index, 1);
1003+
//上面投影坐标里已经处理过了
1004+
// ring.splice(index, 1);
10011005
//update shadow coordinates
10021006
if (geoToEdit !== this._geometry) {
10031007
geoToEdit.setCoordinates(coordiantes);

src/map/Map.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2703,6 +2703,8 @@ export default Map;
27032703
export type MapOptionsType = {
27042704
// center: Array<number> | Coordinate;
27052705
// zoom: number;
2706+
pitch?: number;
2707+
bearing?: number;
27062708
baseLayer?: Layer;
27072709
layers?: Array<Layer>;
27082710
draggable?: boolean;

src/renderer/edit/EditHandle.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface EditHandleOptions {
2121
events: string[];
2222
cursor: string;
2323
zIndex?: number;
24+
ignoreCollision?: boolean
2425
}
2526

2627
export default class EditHandle extends Eventable<any>(Class) {
@@ -231,6 +232,9 @@ export default class EditHandle extends Eventable<any>(Class) {
231232

232233
needCollision(): boolean {
233234
const { target } = this;
235+
if (this.options.ignoreCollision) {
236+
return false;
237+
}
234238
return target && target.options && target.options.collision;
235239
}
236240

test/geometry/edit/GeometryEditSpec.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,5 +436,53 @@ describe('Geometry.Edit', function () {
436436
test();
437437
});
438438

439+
it('#2401 vertex remove bug', function (done) {
440+
const polygon = new maptalks.Polygon(
441+
[
442+
[
443+
[-0.131049, 51.498568],
444+
[-0.107049, 51.498568],
445+
[-0.107049, 51.493568],
446+
[-0.131049, 51.493568],
447+
[-0.131049, 51.498568]
448+
],
449+
[
450+
[-0.121049, 51.497568],
451+
[-0.117049, 51.497568],
452+
[-0.117049, 51.494568],
453+
[-0.121049, 51.494568],
454+
[-0.121049, 51.497568]
455+
]
456+
],
457+
{
458+
symbol: {
459+
polygonFill: "rgb(135,196,240)",
460+
polygonOpacity: 1,
461+
lineColor: "#1bbc9b",
462+
lineWidth: 2
463+
}
464+
}
465+
).addTo(layer);
466+
467+
map.setCenter(polygon.getCenter());
468+
setTimeout(() => {
469+
polygon.startEdit({
470+
'removeVertexOn': 'contextmenu'
471+
});
472+
const coordinate = new maptalks.Coordinate([-0.117049, 51.497568]);
473+
const point = map.coordinateToContainerPoint(coordinate);
474+
var domPosition = GET_PAGE_POSITION(container);
475+
point._add(domPosition);
476+
happen.once(eventContainer, {
477+
'type': 'contextmenu',
478+
'clientX': point.x,
479+
'clientY': point.y
480+
});
481+
polygon.endEdit();
482+
expect(polygon.getCoordinates()[1].length).to.be(4);
483+
done();
484+
}, 100);
485+
});
486+
439487

440488
});

test/geometry/event/GeometryEventSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ describe('Geometry.Events', function () {
322322
markerHeight: 40
323323
},
324324
{
325-
markerFile: 'resources/infownd-close-hover.png',
325+
markerFile: 'resources/2.png',
326326
markerWidth: 40,
327327
markerHeight: 40
328328
},

0 commit comments

Comments
 (0)