Skip to content

Commit da196bb

Browse files
authored
Leaflet-Geoman now consistently uses crosshair as the cursor while drawing (#1410) (patch)
* Add CSS Cursor class geoman-draw-cursor * Add default draw cursor to Marker and CircleMarker
1 parent de3631b commit da196bb

13 files changed

+50
-10
lines changed

cypress/integration/circle.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ describe('Draw Circle', () => {
77
.closest('.button-container')
88
.should('have.class', 'active');
99

10+
cy.get(mapSelector).should('have.class', 'geoman-draw-cursor');
11+
1012
cy.get(mapSelector).click(200, 200).click(250, 250);
1113

14+
cy.get(mapSelector).should('not.have.class', 'geoman-draw-cursor');
15+
1216
cy.toolbarButton('edit')
1317
.click()
1418
.closest('.button-container')

cypress/integration/circlemarker.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,12 @@ describe('Draw Circle Marker', () => {
124124
.closest('.button-container')
125125
.should('have.class', 'active');
126126

127+
cy.get(mapSelector).should('have.class', 'geoman-draw-cursor');
128+
127129
cy.get(mapSelector).click(200, 200).click(250, 250);
128130

131+
cy.get(mapSelector).should('not.have.class', 'geoman-draw-cursor');
132+
129133
cy.hasCircleLayers(1);
130134

131135
cy.toolbarButton('edit')

cypress/integration/line.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ describe('Draw & Edit Line', () => {
117117
.closest('.button-container')
118118
.should('have.class', 'active');
119119

120+
cy.get(mapSelector).should('have.class', 'geoman-draw-cursor');
121+
120122
// draw a line
121123
cy.get(mapSelector)
122124
.click(150, 250)
@@ -125,6 +127,8 @@ describe('Draw & Edit Line', () => {
125127
.click(250, 250)
126128
.click(250, 250);
127129

130+
cy.get(mapSelector).should('not.have.class', 'geoman-draw-cursor');
131+
128132
// button should be disabled after successful draw
129133
cy.toolbarButton('polyline')
130134
.closest('.button-container')

cypress/integration/polygon.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ describe('Draw & Edit Poly', () => {
44
it('drages shared vertices when pinned', () => {
55
cy.toolbarButton('polygon').click();
66

7+
cy.get(mapSelector).should('have.class', 'geoman-draw-cursor');
8+
79
cy.get(mapSelector)
810
.click(120, 150)
911
.click(120, 100)
1012
.click(300, 100)
1113
.click(300, 200)
1214
.click(120, 150);
1315

16+
cy.get(mapSelector).should('not.have.class', 'geoman-draw-cursor');
17+
1418
cy.toolbarButton('marker').click();
1519

1620
cy.get(mapSelector).click(300, 100);

cypress/integration/rectangle.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ describe('Draw Rectangle', () => {
77
.closest('.button-container')
88
.should('have.class', 'active');
99

10+
cy.get(mapSelector).should('have.class', 'geoman-draw-cursor');
11+
1012
cy.get(mapSelector).click(200, 200).click(400, 350);
1113

14+
cy.get(mapSelector).should('not.have.class', 'geoman-draw-cursor');
15+
1216
cy.toolbarButton('edit')
1317
.click()
1418
.closest('.button-container')

cypress/integration/text.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ describe('Text Layer', () => {
6363
.closest('.button-container')
6464
.should('have.class', 'active');
6565

66+
cy.get(mapSelector).should('have.class', 'geoman-draw-cursor');
67+
6668
cy.get(mapSelector).click(90, 250);
6769

70+
cy.get(mapSelector).should('not.have.class', 'geoman-draw-cursor');
71+
6872
let textArea;
6973
cy.window().then(({ map }) => {
7074
expect(1).to.eq(map.pm.getGeomanDrawLayers().length);

src/css/layers.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
opacity: 1 !important;
3333
}
3434

35+
.geoman-draw-cursor {
36+
cursor: crosshair;
37+
}
38+
3539
.leaflet-pm-invalid {
3640
stroke: red;
3741
transition: fill ease 0s, stroke ease 0s;

src/js/Draw/L.PM.Draw.Circle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Draw.Circle = Draw.extend({
7272
this._layerGroup.addLayer(this._hintline);
7373

7474
// change map cursor
75-
this._map._container.style.cursor = 'crosshair';
75+
this._map.getContainer().classList.add('geoman-draw-cursor');
7676

7777
// create a polygon-point on click
7878
this._map.on('click', this._placeCenterMarker, this);
@@ -102,7 +102,7 @@ Draw.Circle = Draw.extend({
102102
this._enabled = false;
103103

104104
// reset cursor
105-
this._map._container.style.cursor = '';
105+
this._map.getContainer().classList.remove('geoman-draw-cursor');
106106

107107
// unbind listeners
108108
this._map.off('click', this._finishShape, this);

src/js/Draw/L.PM.Draw.CircleMarker.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ Draw.CircleMarker = Draw.Marker.extend({
2020
// toggle the draw button of the Toolbar in case drawing mode got enabled without the button
2121
this._map.pm.Toolbar.toggleButton(this.toolbarButtonName, true);
2222

23+
// change map cursor
24+
this._map.getContainer().classList.add('geoman-draw-cursor');
25+
2326
// Draw the CircleMarker like a Circle
2427
if (this.options.editable) {
2528
// we need to set the radius to 0 without overwriting the CircleMarker style
@@ -80,8 +83,6 @@ Draw.CircleMarker = Draw.Marker.extend({
8083
this._layerGroup.addLayer(this._hintline);
8184
// create a polygon-point on click
8285
this._map.on('click', this._placeCenterMarker, this);
83-
// change map cursor
84-
this._map._container.style.cursor = 'crosshair';
8586
} else {
8687
// create a marker on click on the map
8788
this._map.on('click', this._createMarker, this);
@@ -137,10 +138,11 @@ Draw.CircleMarker = Draw.Marker.extend({
137138
// change enabled state
138139
this._enabled = false;
139140

141+
// reset cursor
142+
this._map.getContainer().classList.remove('geoman-draw-cursor');
143+
140144
// disable when drawing like a Circle
141145
if (this.options.editable) {
142-
// reset cursor
143-
this._map._container.style.cursor = '';
144146

145147
// unbind listeners
146148
this._map.off('click', this._finishShape, this);

src/js/Draw/L.PM.Draw.Line.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Draw.Line = Draw.extend({
6767
}
6868

6969
// change map cursor
70-
this._map._container.style.cursor = 'crosshair';
70+
this._map.getContainer().classList.add('geoman-draw-cursor');
7171

7272
// create a polygon-point on click
7373
this._map.on('click', this._createVertex, this);
@@ -115,7 +115,7 @@ Draw.Line = Draw.extend({
115115
this._enabled = false;
116116

117117
// reset cursor
118-
this._map._container.style.cursor = '';
118+
this._map.getContainer().classList.remove('geoman-draw-cursor');
119119

120120
// unbind listeners
121121
this._map.off('click', this._createVertex, this);

src/js/Draw/L.PM.Draw.Marker.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Draw.Marker = Draw.extend({
1515
// change enabled state
1616
this._enabled = true;
1717

18+
// change map cursor
19+
this._map.getContainer().classList.add('geoman-draw-cursor');
20+
1821
// create a marker on click on the map
1922
this._map.on('click', this._createMarker, this);
2023

@@ -71,6 +74,9 @@ Draw.Marker = Draw.extend({
7174
// change enabled state
7275
this._enabled = false;
7376

77+
// reset cursor
78+
this._map.getContainer().classList.remove('geoman-draw-cursor');
79+
7480
// undbind click event, don't create a marker on click anymore
7581
this._map.off('click', this._createMarker, this);
7682

src/js/Draw/L.PM.Draw.Rectangle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Draw.Rectangle = Draw.extend({
9090
}
9191

9292
// change map cursor
93-
this._map._container.style.cursor = 'crosshair';
93+
this._map.getContainer().classList.add('geoman-draw-cursor');
9494

9595
// create a polygon-point on click
9696
this._map.on('click', this._placeStartingMarkers, this);
@@ -120,7 +120,7 @@ Draw.Rectangle = Draw.extend({
120120
this._enabled = false;
121121

122122
// reset cursor
123-
this._map._container.style.cursor = '';
123+
this._map.getContainer().classList.remove('geoman-draw-cursor');
124124

125125
// unbind listeners
126126
this._map.off('click', this._finishShape, this);

src/js/Draw/L.PM.Draw.Text.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ Draw.Text = Draw.extend({
5555
// sync hint marker with mouse cursor
5656
this._map.on('mousemove', this._syncHintMarker, this);
5757

58+
this._map.getContainer().classList.add('geoman-draw-cursor');
59+
5860
// fire drawstart event
5961
this._fireDrawStart();
6062
this._setGlobalDrawMode();
@@ -74,6 +76,8 @@ Draw.Text = Draw.extend({
7476
// remove hint marker
7577
this._hintMarker.remove();
7678

79+
this._map.getContainer().classList.remove('geoman-draw-cursor');
80+
7781
// remove event listener to sync hint marker
7882
this._map.off('mousemove', this._syncHintMarker, this);
7983

0 commit comments

Comments
 (0)