Skip to content

Commit

Permalink
Merge branch 'release/1.5.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
mblomdahl committed Oct 8, 2017
2 parents acdb583 + 3a97507 commit 22256f3
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ Returns **{sw: {lat: [number](https://developer.mozilla.org/en-US/docs/Web/JavaS

## Changelog

### v. 1.5.2

- Fix bug where the circle would always show a horizontal resize cursor on radius handles,
irrespective of position (top/bottom/right/left)

### v. 1.5.1

- Bug fixes with respect to cursor style when hovering over editable-and-clickable circles
Expand Down
34 changes: 30 additions & 4 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const turfBboxPoly = require('@turf/bbox-polygon');
const turfTruncate = require('@turf/truncate');
const turfDestination = require('@turf/destination');
const turfDistance = require('@turf/distance');
const turfBearing = require('@turf/bearing');
const turfHelpers = require('@turf/helpers');

if (window && typeof window.MapboxCircle === 'function') {
Expand Down Expand Up @@ -448,12 +449,36 @@ class MapboxCircle {
}
}

/**
* Return vertical or horizontal resize arrow depending on if mouse is at left-right or top-bottom edit handles.
* @param {MapMouseEvent} event
* @return {string} 'ew-resize' or 'ns-resize'
* @private
*/
_getRadiusHandleCursorStyle(event) {
const bearing = turfBearing(event.lngLat.toArray(), this._currentCenterLngLat, true);

if (bearing > 270+45 || bearing <= 45) { // South.
return 'ns-resize';
}
if (bearing > 45 && bearing <= 90+45) { // West.
return 'ew-resize';
}
if (bearing > 90+45 && bearing <= 180+45) { // North.
return 'ns-resize';
}
if (bearing > 270-45 && bearing <= 270+45) { // East.
return 'ew-resize';
}
}

/**
* Highlight radius handles and disable panning.
* @param {MapMouseEvent} event
* @private
*/
_onRadiusHandlesMouseEnter() {
this._highlightHandles(this._circleRadiusHandlesId, 'ew-resize');
_onRadiusHandlesMouseEnter(event) {
this._highlightHandles(this._circleRadiusHandlesId, this._getRadiusHandleCursorStyle(event));
}

/**
Expand Down Expand Up @@ -482,15 +507,16 @@ class MapboxCircle {

/**
* Highlight radius handles, disable panning and add mouse-move listener (emulating drag until mouse-up event).
* @param {MapMouseEvent} event
* @private
*/
_onRadiusHandlesMouseDown() {
_onRadiusHandlesMouseDown(event) {
this._radiusDragActive = true;
this.map.on('mousemove', this._onRadiusHandlesMouseMove);
this._suspendHandleListeners('radius');
this.map.once('mouseup', this._onRadiusHandlesMouseUpOrMapMouseOut);
this.map.once('mouseout', this._onRadiusHandlesMouseUpOrMapMouseOut); // Deactivate drag if mouse leaves canvas.
this._highlightHandles(this._circleRadiusHandlesId, 'ew-resize');
this._highlightHandles(this._circleRadiusHandlesId, this._getRadiusHandleCursorStyle(event));
}

/**
Expand Down
17 changes: 16 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mapbox-gl-circle",
"version": "1.5.1",
"version": "1.5.2",
"author": "Smith Micro Software, Inc.",
"license": "ISC",
"description": "A google.maps.Circle replacement for Mapbox GL JS API",
Expand Down Expand Up @@ -86,6 +86,7 @@
"@turf/bbox-polygon": "^4.5.2",
"@turf/circle": "^4.5.2",
"@turf/destination": "^4.5.2",
"@turf/bearing": "^4.5.2",
"@turf/distance": "^4.5.2",
"@turf/helpers": "^4.5.2",
"@turf/truncate": "^4.5.2",
Expand Down

0 comments on commit 22256f3

Please sign in to comment.