Skip to content

Commit

Permalink
Path edit center vertex ignore collision (#2403)
Browse files Browse the repository at this point in the history
* Path edit center vertex ignore collision

* map typing

* updates

* spec

* update sepc
  • Loading branch information
deyihu authored Aug 22, 2024
1 parent 59bc607 commit d9926d6
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/geometry/editor/GeometryEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ class GeometryEditor extends Eventable(Class) {
let shadow;
const cointainerPoint = map.coordToContainerPoint(this._geometry.getCenter());
const handle = this.createHandle(cointainerPoint, {
ignoreCollision: true,
'symbol': symbol,
'cursor': 'move',
onDown: (): void => {
Expand Down Expand Up @@ -373,7 +374,8 @@ class GeometryEditor extends Eventable(Class) {
}

//@internal
_createHandleInstance(containerPoint: any, opts: any): EditHandle {
_createHandleInstance(containerPoint: Point, opts: GeometryEditOptionsType): EditHandle {
opts = opts || {};
const map = this.getMap();
const symbol = loadFunctionTypes(opts['symbol'], (): any => {
return [
Expand All @@ -386,7 +388,7 @@ class GeometryEditor extends Eventable(Class) {
];
});
const removeVertexOn = this.options['removeVertexOn'];
const handle = new EditHandle(this, map, { symbol, cursor: opts['cursor'], events: removeVertexOn as any });
const handle = new EditHandle(this, map, { symbol, cursor: opts['cursor'], events: removeVertexOn as any, ignoreCollision: (opts as any).ignoreCollision });
handle.setContainerPoint(containerPoint);
return handle;
}
Expand Down Expand Up @@ -967,6 +969,7 @@ class GeometryEditor extends Eventable(Class) {
}
const isEnd = (geoToEdit instanceof LineString) && (index === 0 || index === prjCoordinates.length - 1);
prjCoordinates.splice(index, 1);

if (ringIndex > 0) {
//update hole prj
geoToEdit._prjHoles[ringIndex - 1] = prjCoordinates;
Expand Down Expand Up @@ -997,7 +1000,8 @@ class GeometryEditor extends Eventable(Class) {
//fix hole Vertex delete
const ring = coordiantes[ringIndex];
if (ring && Array.isArray(ring) && ring.length > 1) {
ring.splice(index, 1);
//上面投影坐标里已经处理过了
// ring.splice(index, 1);
//update shadow coordinates
if (geoToEdit !== this._geometry) {
geoToEdit.setCoordinates(coordiantes);
Expand Down
2 changes: 2 additions & 0 deletions src/map/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2703,6 +2703,8 @@ export default Map;
export type MapOptionsType = {
// center: Array<number> | Coordinate;
// zoom: number;
pitch?: number;
bearing?: number;
baseLayer?: Layer;
layers?: Array<Layer>;
draggable?: boolean;
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/edit/EditHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface EditHandleOptions {
events: string[];
cursor: string;
zIndex?: number;
ignoreCollision?: boolean
}

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

needCollision(): boolean {
const { target } = this;
if (this.options.ignoreCollision) {
return false;
}
return target && target.options && target.options.collision;
}

Expand Down
48 changes: 48 additions & 0 deletions test/geometry/edit/GeometryEditSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,5 +436,53 @@ describe('Geometry.Edit', function () {
test();
});

it('#2401 vertex remove bug', function (done) {
const polygon = new maptalks.Polygon(
[
[
[-0.131049, 51.498568],
[-0.107049, 51.498568],
[-0.107049, 51.493568],
[-0.131049, 51.493568],
[-0.131049, 51.498568]
],
[
[-0.121049, 51.497568],
[-0.117049, 51.497568],
[-0.117049, 51.494568],
[-0.121049, 51.494568],
[-0.121049, 51.497568]
]
],
{
symbol: {
polygonFill: "rgb(135,196,240)",
polygonOpacity: 1,
lineColor: "#1bbc9b",
lineWidth: 2
}
}
).addTo(layer);

map.setCenter(polygon.getCenter());
setTimeout(() => {
polygon.startEdit({
'removeVertexOn': 'contextmenu'
});
const coordinate = new maptalks.Coordinate([-0.117049, 51.497568]);
const point = map.coordinateToContainerPoint(coordinate);
var domPosition = GET_PAGE_POSITION(container);
point._add(domPosition);
happen.once(eventContainer, {
'type': 'contextmenu',
'clientX': point.x,
'clientY': point.y
});
polygon.endEdit();
expect(polygon.getCoordinates()[1].length).to.be(4);
done();
}, 100);
});


});
2 changes: 1 addition & 1 deletion test/geometry/event/GeometryEventSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ describe('Geometry.Events', function () {
markerHeight: 40
},
{
markerFile: 'resources/infownd-close-hover.png',
markerFile: 'resources/2.png',
markerWidth: 40,
markerHeight: 40
},
Expand Down

0 comments on commit d9926d6

Please sign in to comment.