Skip to content

Commit 074f272

Browse files
committed
reset vertexes in DistanceTool._addVertexMarker, fix #1249
1 parent 17c6066 commit 074f272

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed

src/map/tool/DistanceTool.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,10 @@ class DistanceTool extends DrawTool {
295295
if (!this._vertexes) {
296296
this._vertexes = [];
297297
}
298-
this._vertexes.push({ label: vertexLabel, marker });
299-
if (this._historyPointer !== undefined) {
300-
this._vertexes.length = this._historyPointer;
298+
if (this._historyPointer !== undefined && this._vertexes.length > this._historyPointer - 1) {
299+
this._vertexes.length = this._historyPointer - 1;
301300
}
301+
this._vertexes.push({ label: vertexLabel, marker });
302302
this._measureMarkerLayer.addGeometry(marker);
303303
if (vertexLabel) {
304304
this._measureMarkerLayer.addGeometry(vertexLabel);

test/map/tools/MeasureToolSpec.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,83 @@ describe('DistanceTool and AreaTool', function () {
303303
tool.endDraw();
304304
expect(tool.getLastMeasure()).to.be.above(0);
305305
});
306+
307+
//#1249
308+
it('undo for multiple times', function () {
309+
var tool = new maptalks.AreaTool().addTo(map);
310+
var center = map.getCenter();
311+
312+
var domPosition = GET_PAGE_POSITION(container);
313+
var point = map.coordinateToContainerPoint(center).add(domPosition);
314+
315+
var measure = 0;
316+
happen.mousedown(eventContainer, {
317+
'clientX':point.x,
318+
'clientY':point.y
319+
});
320+
happen.click(eventContainer, {
321+
'clientX':point.x,
322+
'clientY':point.y
323+
});
324+
var i;
325+
for (i = 1; i < 10; i++) {
326+
happen.mousemove(eventContainer, {
327+
'clientX':point.x + i,
328+
'clientY':point.y
329+
});
330+
}
331+
332+
happen.mousedown(eventContainer, {
333+
'clientX':point.x + 10,
334+
'clientY':point.y
335+
});
336+
happen.click(eventContainer, {
337+
'clientX':point.x + 10,
338+
'clientY':point.y
339+
});
340+
happen.mousedown(eventContainer, {
341+
'clientX':point.x + 20,
342+
'clientY':point.y
343+
});
344+
happen.click(eventContainer, {
345+
'clientX':point.x + 20,
346+
'clientY':point.y
347+
});
348+
349+
tool.undo();
350+
tool.undo();
351+
happen.click(eventContainer, {
352+
'clientX':point.x,
353+
'clientY':point.y
354+
});
355+
var i;
356+
for (i = 1; i < 10; i++) {
357+
happen.mousemove(eventContainer, {
358+
'clientX':point.x + i,
359+
'clientY':point.y
360+
});
361+
}
362+
363+
happen.mousedown(eventContainer, {
364+
'clientX':point.x + 10,
365+
'clientY':point.y
366+
});
367+
happen.click(eventContainer, {
368+
'clientX':point.x + 10,
369+
'clientY':point.y
370+
});
371+
tool.undo();
372+
tool.undo();
373+
374+
var layers = tool.getMeasureLayers();
375+
for (var i = 0; i < layers.length; i++){
376+
if (layers[i].getCount() > 0) {
377+
expect(layers[i].getCount()).to.be.eql(2);
378+
}
379+
}
380+
tool.disable();
381+
382+
});
306383
});
307384

308385

0 commit comments

Comments
 (0)