Skip to content

Commit ceb4bff

Browse files
committed
fix: add new option cursorStyleHandler to change cursor style value
1 parent 027b52b commit ceb4bff

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/control/modify.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ModifyControl extends Control {
2424
* @param {Object} [options.modifyInteractionOptions] Options for the modify interaction.
2525
* @param {Object} [options.deleteInteractionOptions] Options for the delete interaction.
2626
* @param {Object} [options.deselectInteractionOptions] Options for the deselect interaction. Default: features are deselected on click on map.
27+
* @param {Function} [options.cursorStyleHandler] Options to override default cursor styling behavior.
2728
*/
2829
constructor(options = {}) {
2930
super({
@@ -68,6 +69,8 @@ class ModifyControl extends Control {
6869
this.previousCursor = null;
6970
this.cursorTimeout = null;
7071
this.cursorHandler = this.cursorHandler.bind(this);
72+
this.cursorStyleHandler =
73+
options?.cursorStyleHandler || ((cursorStyle) => cursorStyle);
7174

7275
/* Interactions */
7376
this.createSelectMoveInteraction(options.selectMoveOptions);
@@ -355,12 +358,16 @@ class ModifyControl extends Control {
355358
if (!this.getActive()) {
356359
return;
357360
}
361+
const newCursor = this.cursorStyleHandler(cursor);
358362
const element = this.map.getTargetElement();
359-
if ((element.style.cursor || cursor) && element.style.cursor !== cursor) {
363+
if (
364+
(element.style.cursor || newCursor) &&
365+
element.style.cursor !== newCursor
366+
) {
360367
if (this.previousCursor === null) {
361368
this.previousCursor = element.style.cursor;
362369
}
363-
element.style.cursor = cursor;
370+
element.style.cursor = newCursor;
364371
}
365372
}
366373

0 commit comments

Comments
 (0)