Skip to content

Commit acdb583

Browse files
committed
Merge branch 'release/1.5.1'
2 parents 673e423 + 76a1299 commit acdb583

4 files changed

Lines changed: 115 additions & 31 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ Returns **{sw: {lat: [number](https://developer.mozilla.org/en-US/docs/Web/JavaS
184184

185185
## Changelog
186186

187+
### v. 1.5.1
188+
189+
- Bug fixes with respect to cursor style when hovering over editable-and-clickable circles
190+
[SPFAM-1293](https://projects.smithmicro.net/browse/SPFAM-1293)
191+
187192
### v. 1.5.0
188193

189194
- Added support for passing `minRadius` and `maxRadius` options to _MapboxCircle_ constructor

lib/main.js

Lines changed: 108 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -197,25 +197,29 @@ class MapboxCircle {
197197
/** @const {boolean} */ this._radiusDragActive = false;
198198

199199
[ // Bind all event handlers.
200+
'_onZoomEnd',
200201
'_onCenterHandleMouseEnter',
201-
'_onRadiusHandlesMouseEnter',
202+
'_onCenterHandleResumeEvents',
202203
'_onCenterHandleSuspendEvents',
204+
'_onCenterHandleMouseDown',
205+
'_onCenterHandleMouseMove',
206+
'_onCenterHandleMouseUpOrMapMouseOut',
207+
'_onCenterChanged',
208+
'_onCenterHandleMouseLeave',
209+
'_onRadiusHandlesMouseEnter',
203210
'_onRadiusHandlesSuspendEvents',
204-
'_onCenterHandleResumeEvents',
205211
'_onRadiusHandlesResumeEvents',
206-
'_onCenterHandleMouseDown',
207212
'_onRadiusHandlesMouseDown',
208-
'_onCenterHandleMouseMove',
209213
'_onRadiusHandlesMouseMove',
210-
'_onCenterHandleMouseUpOrMapMouseOut',
211214
'_onRadiusHandlesMouseUpOrMapMouseOut',
212-
'_onCenterChanged',
213215
'_onRadiusChanged',
214216
'_onRadiusHandlesMouseLeave',
215-
'_onCenterHandleMouseLeave',
217+
'_onCircleFillMouseMove',
218+
'_onCircleFillSuspendEvents',
219+
'_onCircleFillResumeEvents',
216220
'_onCircleFillContextMenu',
217221
'_onCircleFillClick',
218-
'_onZoomEnd',
222+
'_onCircleFillMouseLeave',
219223
'_onMapStyleDataLoading'
220224
].forEach((eventHandler) => {
221225
this[eventHandler] = this[eventHandler].bind(this);
@@ -270,6 +274,20 @@ class MapboxCircle {
270274
this._map.getSource(this._circleSourceId).setData(this._asGeoJSON());
271275
}
272276

277+
/**
278+
* Returns true if cursor point is on a center/radius edit handle.
279+
* @param {{x: number, y: number}} point
280+
* @return {boolean}
281+
* @private
282+
*/
283+
_pointOnHandle(point) {
284+
return !MapboxCircle.__MONOSTATE.activeEditableCircles.every((circleWithHandles) => {
285+
const handleLayersAtCursor = this.map.queryRenderedFeatures(
286+
point, {layers: [circleWithHandles._circleCenterHandleId, circleWithHandles._circleRadiusHandlesId]});
287+
return handleLayersAtCursor.length === 0;
288+
});
289+
}
290+
273291
/**
274292
* Return GeoJSON for circle and handles.
275293
* @private
@@ -288,6 +306,7 @@ class MapboxCircle {
288306
_suspendHandleListeners(typeOfHandle) {
289307
MapboxCircle.__MONOSTATE.broadcast.emit('suspendCenterHandleListeners', this._instanceId, typeOfHandle);
290308
MapboxCircle.__MONOSTATE.broadcast.emit('suspendRadiusHandlesListeners', this._instanceId, typeOfHandle);
309+
MapboxCircle.__MONOSTATE.broadcast.emit('suspendCircleFillListeners', this._instanceId, typeOfHandle);
291310
}
292311

293312
/**
@@ -298,17 +317,19 @@ class MapboxCircle {
298317
_resumeHandleListeners(typeOfHandle) {
299318
MapboxCircle.__MONOSTATE.broadcast.emit('resumeCenterHandleListeners', this._instanceId, typeOfHandle);
300319
MapboxCircle.__MONOSTATE.broadcast.emit('resumeRadiusHandlesListeners', this._instanceId, typeOfHandle);
320+
MapboxCircle.__MONOSTATE.broadcast.emit('resumeCircleFillListeners', this._instanceId, typeOfHandle);
301321
}
302322

303323
/**
304-
* Disable map panning, 'click' cursor and highlight handle with new fill color.
324+
* Disable map panning, set cursor style and highlight handle with new fill color.
305325
* @param {string} layerId
326+
* @param {string} cursor
306327
* @private
307328
*/
308-
_highlightHandles(layerId) {
329+
_highlightHandles(layerId, cursor) {
309330
this.map.dragPan.disable();
310331
this.map.setPaintProperty(layerId, 'circle-color', this.options.fillColor);
311-
this.map.getCanvas().style.cursor = 'pointer';
332+
this.map.getCanvas().style.cursor = cursor;
312333
}
313334

314335
/**
@@ -335,7 +356,7 @@ class MapboxCircle {
335356
* @private
336357
*/
337358
_onCenterHandleMouseEnter() {
338-
this._highlightHandles(this._circleCenterHandleId);
359+
this._highlightHandles(this._circleCenterHandleId, 'move');
339360
}
340361

341362
/**
@@ -372,7 +393,7 @@ class MapboxCircle {
372393
this._suspendHandleListeners('center');
373394
this.map.once('mouseup', this._onCenterHandleMouseUpOrMapMouseOut);
374395
this.map.once('mouseout', this._onCenterHandleMouseUpOrMapMouseOut); // Deactivate drag if mouse leaves canvas.
375-
this._highlightHandles(this._circleCenterHandleId);
396+
this._highlightHandles(this._circleCenterHandleId, 'move');
376397
}
377398

378399
/**
@@ -404,6 +425,15 @@ class MapboxCircle {
404425
}
405426
}
406427

428+
/**
429+
* Update _lastCenterLngLat on `centerchanged` event.
430+
* @private
431+
*/
432+
_onCenterChanged() {
433+
this._lastCenterLngLat[0] = this.center[0];
434+
this._lastCenterLngLat[1] = this.center[1];
435+
}
436+
407437
/**
408438
* Reset center handle and re-enable panning, unless actively dragging.
409439
* @private
@@ -418,21 +448,12 @@ class MapboxCircle {
418448
}
419449
}
420450

421-
/**
422-
* Update _lastCenterLngLat on `centerchanged` event.
423-
* @private
424-
*/
425-
_onCenterChanged() {
426-
this._lastCenterLngLat[0] = this.center[0];
427-
this._lastCenterLngLat[1] = this.center[1];
428-
}
429-
430451
/**
431452
* Highlight radius handles and disable panning.
432453
* @private
433454
*/
434455
_onRadiusHandlesMouseEnter() {
435-
this._highlightHandles(this._circleRadiusHandlesId);
456+
this._highlightHandles(this._circleRadiusHandlesId, 'ew-resize');
436457
}
437458

438459
/**
@@ -469,7 +490,7 @@ class MapboxCircle {
469490
this._suspendHandleListeners('radius');
470491
this.map.once('mouseup', this._onRadiusHandlesMouseUpOrMapMouseOut);
471492
this.map.once('mouseout', this._onRadiusHandlesMouseUpOrMapMouseOut); // Deactivate drag if mouse leaves canvas.
472-
this._highlightHandles(this._circleRadiusHandlesId);
493+
this._highlightHandles(this._circleRadiusHandlesId, 'ew-resize');
473494
}
474495

475496
/**
@@ -501,6 +522,14 @@ class MapboxCircle {
501522
}
502523
}
503524

525+
/**
526+
* Update _lastRadius on `radiuschanged` event.
527+
* @private
528+
*/
529+
_onRadiusChanged() {
530+
this._lastRadius = this.radius;
531+
}
532+
504533
/**
505534
* Reset radius handles and re-enable panning, unless actively dragging.
506535
* @private
@@ -516,11 +545,30 @@ class MapboxCircle {
516545
}
517546

518547
/**
519-
* Update _lastRadius on `radiuschanged` event.
548+
* Set pointer cursor when moving over circle fill, and it's clickable.
549+
* @param {MapMouseEvent} event
520550
* @private
521551
*/
522-
_onRadiusChanged() {
523-
this._lastRadius = this.radius;
552+
_onCircleFillMouseMove(event) {
553+
if (this._eventEmitter.listeners('click').length > 0 && !this._pointOnHandle(event.point)) {
554+
event.target.getCanvas().style.cursor = 'pointer';
555+
}
556+
}
557+
558+
/**
559+
* Stop listening to circle fill events.
560+
* @private
561+
*/
562+
_onCircleFillSuspendEvents() {
563+
this._unbindCircleFillListeners();
564+
}
565+
566+
/**
567+
* Start listening to circle fill events again.
568+
* @private
569+
*/
570+
_onCircleFillResumeEvents() {
571+
this._bindCircleFillListeners();
524572
}
525573

526574
/**
@@ -529,6 +577,10 @@ class MapboxCircle {
529577
* @private
530578
*/
531579
_onCircleFillContextMenu(event) {
580+
if (this._pointOnHandle(event.point)) {
581+
/* No click events while on a center/radius edit handle. */ return;
582+
}
583+
532584
if (event.originalEvent.ctrlKey && MapboxCircle._checkIfBrowserIsSafari()) {
533585
// This hack comes from SPFAM-1090, aimed towards eliminating the extra 'click' event that's
534586
// emitted by Safari when performing a right-click by holding the ctrl button.
@@ -544,6 +596,10 @@ class MapboxCircle {
544596
* @private
545597
*/
546598
_onCircleFillClick(event) {
599+
if (this._pointOnHandle(event.point)) {
600+
/* No click events while on a center/radius edit handle. */ return;
601+
}
602+
547603
if (!this.__safariContextMenuEventHackEnabled) {
548604
this._eventEmitter.emit('click', event);
549605
} else {
@@ -552,6 +608,17 @@ class MapboxCircle {
552608
}
553609
}
554610

611+
/**
612+
* Remove pointer cursor when leaving circle fill.
613+
* @param {MapMouseEvent} event
614+
* @private
615+
*/
616+
_onCircleFillMouseLeave(event) {
617+
if (this._eventEmitter.listeners('click').length > 0 && !this._pointOnHandle(event.point)) {
618+
event.target.getCanvas().style.cursor = '';
619+
}
620+
}
621+
555622
/**
556623
* When map style is changed, remove circle assets from map and add it back on next MapboxGL 'styledata' event.
557624
* @param {MapDataEvent} event
@@ -628,6 +695,8 @@ class MapboxCircle {
628695
const layerId = this._circleFillId;
629696
map.on('click', layerId, this._onCircleFillClick);
630697
map.on('contextmenu', layerId, this._onCircleFillContextMenu);
698+
map.on('mousemove', layerId, this._onCircleFillMouseMove);
699+
map.on('mouseleave', layerId, this._onCircleFillMouseLeave);
631700
}
632701

633702
/**
@@ -640,6 +709,8 @@ class MapboxCircle {
640709
const layerId = this._circleFillId;
641710
map.off('click', layerId, this._onCircleFillClick);
642711
map.off('contextmenu', layerId, this._onCircleFillContextMenu);
712+
map.off('mousemove', layerId, this._onCircleFillMouseMove);
713+
map.off('mouseleave', layerId, this._onCircleFillMouseLeave);
643714
}
644715

645716
/**
@@ -652,6 +723,9 @@ class MapboxCircle {
652723

653724
MapboxCircle.__MONOSTATE.broadcast.on('suspendRadiusHandlesListeners', this._onRadiusHandlesSuspendEvents);
654725
MapboxCircle.__MONOSTATE.broadcast.on('resumeRadiusHandlesListeners', this._onRadiusHandlesResumeEvents);
726+
727+
MapboxCircle.__MONOSTATE.broadcast.on('suspendCircleFillListeners', this._onCircleFillSuspendEvents);
728+
MapboxCircle.__MONOSTATE.broadcast.on('resumeCircleFillListeners', this._onCircleFillResumeEvents);
655729
}
656730

657731
/**
@@ -666,8 +740,13 @@ class MapboxCircle {
666740

667741
MapboxCircle.__MONOSTATE.broadcast.removeListener(
668742
'suspendRadiusHandlesListeners', this._onRadiusHandlesSuspendEvents);
669-
MapboxCircle.__MONOSTATE.broadcast.removeListener('resumeRadiusHandlesListeners',
670-
this._onRadiusHandlesResumeEvents);
743+
MapboxCircle.__MONOSTATE.broadcast.removeListener(
744+
'resumeRadiusHandlesListeners', this._onRadiusHandlesResumeEvents);
745+
746+
MapboxCircle.__MONOSTATE.broadcast.removeListener(
747+
'suspendCircleFillListeners', this._onCircleFillSuspendEvents);
748+
MapboxCircle.__MONOSTATE.broadcast.removeListener(
749+
'resumeCircleFillListeners', this._onCircleFillResumeEvents);
671750
}
672751

673752
/**

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mapbox-gl-circle",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"author": "Smith Micro Software, Inc.",
55
"license": "ISC",
66
"description": "A google.maps.Circle replacement for Mapbox GL JS API",

0 commit comments

Comments
 (0)