Skip to content

Commit

Permalink
Add onVertexClick to Rectangle, Circle and CircleMarker (#1367)
Browse files Browse the repository at this point in the history
  • Loading branch information
Falke-Design authored Nov 21, 2023
1 parent f3f9343 commit cd22a48
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 0 deletions.
27 changes: 27 additions & 0 deletions cypress/integration/circle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,31 @@ describe('Draw Circle', () => {
expect(layer.options.color).to.eql('red');
});
});

it('on vertex click', (done) => {
cy.toolbarButton('circle')
.click()
.closest('.button-container')
.should('have.class', 'active');

cy.get(mapSelector).click(200, 200);
cy.get(mapSelector).click(300, 200);

cy.window().then(({ map }) => {
let count = 0;
const layer = map.pm.getGeomanDrawLayers()[0];
layer.on('pm:vertexclick', ()=>{
count += 1;
if(count >= 2) {
expect(count).to.eql(2);
setTimeout(done, 100)
}
})
});

cy.toolbarButton('edit').click();
cy.get(mapSelector).click(200, 200);
cy.get(mapSelector).click(300, 200);

});
});
31 changes: 31 additions & 0 deletions cypress/integration/circlemarker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,4 +578,35 @@ describe('Draw Circle Marker', () => {

cy.hasVertexMarkers(2);
});

it('on vertex click - editable', (done) => {
cy.window().then(({ map }) => {
map.pm.setGlobalOptions({ editable: true });
});

cy.toolbarButton('circle-marker')
.click()
.closest('.button-container')
.should('have.class', 'active');

cy.get(mapSelector).click(200, 200);
cy.get(mapSelector).click(300, 200);

cy.window().then(({ map }) => {
let count = 0;
const layer = map.pm.getGeomanDrawLayers()[0];
layer.on('pm:vertexclick', ()=>{
count += 1;
if(count >= 2) {
expect(count).to.eql(2);
setTimeout(done, 100)
}
})
});

cy.toolbarButton('edit').click();
cy.get(mapSelector).click(200, 200);
cy.get(mapSelector).click(300, 200);

});
});
27 changes: 27 additions & 0 deletions cypress/integration/rectangle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -952,4 +952,31 @@ describe('Draw Rectangle', () => {
expect(px).to.eql(expected);
});
});

it('on vertex click', (done) => {
cy.toolbarButton('rectangle')
.click()
.closest('.button-container')
.should('have.class', 'active');

cy.get(mapSelector).click(200, 200);
cy.get(mapSelector).click(300, 300);

cy.window().then(({ map }) => {
let count = 0;
const layer = map.pm.getGeomanDrawLayers()[0];
layer.on('pm:vertexclick', ()=>{
count += 1;
if(count >= 2) {
expect(count).to.eql(2);
setTimeout(done, 100)
}
})
});

cy.toolbarButton('edit').click();
cy.get(mapSelector).click(200, 200);
cy.get(mapSelector).click(300, 300);

});
});
8 changes: 8 additions & 0 deletions src/js/Edit/L.PM.Edit.Circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@ Edit.Circle = Edit.CircleMarker.extend({
_getMaxDistanceInMeter(){
return this.options[this._maxRadiusOption]
},
_onVertexClick(e) {
const vertex = e.target;
if (vertex._dragging) {
return;
}

this._fireVertexClick(e, undefined);
},
});
9 changes: 9 additions & 0 deletions src/js/Edit/L.PM.Edit.CircleMarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ Edit.CircleMarker = Edit.extend({
marker.on('dragstart', this._onMarkerDragStart, this);
marker.on('drag', this._onMarkerDrag, this);
marker.on('dragend', this._onMarkerDragEnd, this);
marker.on('click', this._onVertexClick, this);

this._helperLayers.addLayer(marker);

Expand Down Expand Up @@ -454,4 +455,12 @@ Edit.CircleMarker = Edit.extend({
_getMaxDistanceInMeter(latlng){
return L.PM.Utils.pxRadiusToMeterRadius(this.options[this._maxRadiusOption], this._map, latlng)
},
_onVertexClick(e) {
const vertex = e.target;
if (vertex._dragging) {
return;
}

this._fireVertexClick(e, undefined);
},
});
2 changes: 2 additions & 0 deletions src/js/Edit/L.PM.Edit.Rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Edit.Rectangle = Edit.Polygon.extend({
marker._index = index;
marker._pmTempLayer = true;

marker.on('click', this._onVertexClick, this);

this._markerGroup.addLayer(marker);

return marker;
Expand Down

0 comments on commit cd22a48

Please sign in to comment.