Skip to content

Commit 22256f3

Browse files
committed
Merge branch 'release/1.5.2'
2 parents acdb583 + 3a97507 commit 22256f3

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

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.2
188+
189+
- Fix bug where the circle would always show a horizontal resize cursor on radius handles,
190+
irrespective of position (top/bottom/right/left)
191+
187192
### v. 1.5.1
188193

189194
- Bug fixes with respect to cursor style when hovering over editable-and-clickable circles

lib/main.js

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const turfBboxPoly = require('@turf/bbox-polygon');
99
const turfTruncate = require('@turf/truncate');
1010
const turfDestination = require('@turf/destination');
1111
const turfDistance = require('@turf/distance');
12+
const turfBearing = require('@turf/bearing');
1213
const turfHelpers = require('@turf/helpers');
1314

1415
if (window && typeof window.MapboxCircle === 'function') {
@@ -448,12 +449,36 @@ class MapboxCircle {
448449
}
449450
}
450451

452+
/**
453+
* Return vertical or horizontal resize arrow depending on if mouse is at left-right or top-bottom edit handles.
454+
* @param {MapMouseEvent} event
455+
* @return {string} 'ew-resize' or 'ns-resize'
456+
* @private
457+
*/
458+
_getRadiusHandleCursorStyle(event) {
459+
const bearing = turfBearing(event.lngLat.toArray(), this._currentCenterLngLat, true);
460+
461+
if (bearing > 270+45 || bearing <= 45) { // South.
462+
return 'ns-resize';
463+
}
464+
if (bearing > 45 && bearing <= 90+45) { // West.
465+
return 'ew-resize';
466+
}
467+
if (bearing > 90+45 && bearing <= 180+45) { // North.
468+
return 'ns-resize';
469+
}
470+
if (bearing > 270-45 && bearing <= 270+45) { // East.
471+
return 'ew-resize';
472+
}
473+
}
474+
451475
/**
452476
* Highlight radius handles and disable panning.
477+
* @param {MapMouseEvent} event
453478
* @private
454479
*/
455-
_onRadiusHandlesMouseEnter() {
456-
this._highlightHandles(this._circleRadiusHandlesId, 'ew-resize');
480+
_onRadiusHandlesMouseEnter(event) {
481+
this._highlightHandles(this._circleRadiusHandlesId, this._getRadiusHandleCursorStyle(event));
457482
}
458483

459484
/**
@@ -482,15 +507,16 @@ class MapboxCircle {
482507

483508
/**
484509
* Highlight radius handles, disable panning and add mouse-move listener (emulating drag until mouse-up event).
510+
* @param {MapMouseEvent} event
485511
* @private
486512
*/
487-
_onRadiusHandlesMouseDown() {
513+
_onRadiusHandlesMouseDown(event) {
488514
this._radiusDragActive = true;
489515
this.map.on('mousemove', this._onRadiusHandlesMouseMove);
490516
this._suspendHandleListeners('radius');
491517
this.map.once('mouseup', this._onRadiusHandlesMouseUpOrMapMouseOut);
492518
this.map.once('mouseout', this._onRadiusHandlesMouseUpOrMapMouseOut); // Deactivate drag if mouse leaves canvas.
493-
this._highlightHandles(this._circleRadiusHandlesId, 'ew-resize');
519+
this._highlightHandles(this._circleRadiusHandlesId, this._getRadiusHandleCursorStyle(event));
494520
}
495521

496522
/**

package-lock.json

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mapbox-gl-circle",
3-
"version": "1.5.1",
3+
"version": "1.5.2",
44
"author": "Smith Micro Software, Inc.",
55
"license": "ISC",
66
"description": "A google.maps.Circle replacement for Mapbox GL JS API",
@@ -86,6 +86,7 @@
8686
"@turf/bbox-polygon": "^4.5.2",
8787
"@turf/circle": "^4.5.2",
8888
"@turf/destination": "^4.5.2",
89+
"@turf/bearing": "^4.5.2",
8990
"@turf/distance": "^4.5.2",
9091
"@turf/helpers": "^4.5.2",
9192
"@turf/truncate": "^4.5.2",

0 commit comments

Comments
 (0)