Skip to content

Commit

Permalink
EditOutline.options null defense (#2453)
Browse files Browse the repository at this point in the history
* EditOutline.options null defense

* spec
  • Loading branch information
deyihu authored Oct 31, 2024
1 parent 1397ab2 commit ff2cd3c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/renderer/edit/EditHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class EditHandle extends Eventable<any>(Class) {
paramOptions: Record<string, any>;

constructor(target: GeometryEditor, map: Map, options: EditHandleOptions) {
super(options);
super(options || {});
this.target = target;
target.once('remove', this.delete, this);
const symbol = this.options['symbol'];
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/edit/EditOutline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class EditOutline {
this.target = target;
target.once('remove', this.delete, this);
this.map = map;
this.options = options;
this.options = options || {};
this.addTo(map);
}

Expand Down
4 changes: 2 additions & 2 deletions src/renderer/map/MapCanvasRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1144,8 +1144,8 @@ class MapCanvasRenderer extends MapRenderer {

sortTopElements() {
this._tops = this._tops.sort((top1, top2) => {
const zIndex1 = top1.options.zIndex || 0;
const zIndex2 = top2.options.zIndex || 0;
const zIndex1 = (top1.options || {}).zIndex || 0;
const zIndex2 = (top2.options || {}).zIndex || 0;
return zIndex2 - zIndex1;
});
}
Expand Down
24 changes: 24 additions & 0 deletions test/geometry/edit/GeometryEditSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,5 +533,29 @@ describe('Geometry.Edit', function () {

});

it('#2452 EditOutline.options null defense', function (done) {

const point = new maptalks.Marker([-0.131049, 51.498568, 10]).addTo(layer);

const line = new maptalks.LineString(
[
[-0.131049, 51.498568, 10],
[-0.107049, 51.498568, 20],
[-0.107049, 51.493568, 49],
[-0.131049, 51.493568, 22],
[-0.131049, 51.498568, 0]
]
).addTo(layer);

map.setCenter(point.getCenter());

point.startEdit({});
line.startEdit({});

done();


});


});

0 comments on commit ff2cd3c

Please sign in to comment.