Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
aae816e
Merge branch 'release/1.6.1' into develop
mblomdahl Oct 28, 2017
eea3a72
SPFAM-1430: It is possible to drag circles over markers.
carlba Nov 24, 2017
2c1d6be
SPFAM-1430: Added a reference marker to the example index.
carlba Nov 24, 2017
f46edeb
SPFAM-1430: Removed linebreak
carlba Nov 24, 2017
154fe4f
Fix review comments
mblomdahl Nov 26, 2017
27da9e6
Bump patch version to 1.6.2
mblomdahl Nov 26, 2017
cb7d59c
SPFAM-1430: Switched to simpler way of detecting if above a marker.
carlba Nov 29, 2017
2b3cd40
SPFAM-1430: Removed no longer needed function
carlba Nov 29, 2017
af014ba
SPFAM-1430: Updated MapboxGL version
carlba Nov 29, 2017
d6d31d3
SPFAM-1430: Markers where not properly detected on Safepath map.
carlba Nov 30, 2017
5999426
SPFAM-1430: Removed the static url from the sample file.
carlba Nov 30, 2017
3f27a34
Merge pull request #5 in ~MBLOMDAHL/mapbox-gl-circle from bugfix/SPFA…
Nov 30, 2017
c559004
SPFAM-1430: Re factored slightly
carlba Nov 30, 2017
9aa5493
SPFAM-1420: Use Mutationobserver to detect map removal.
carlba Dec 1, 2017
ad43420
Revert "SPFAM-1430: Updated MapboxGL version"
mblomdahl Dec 2, 2017
c2c76b3
Revert "SPFAM-1430: Removed the static url from the sample file."
mblomdahl Dec 2, 2017
624a732
Properly handle center/radius drag interactions over Mapbox GL markers
mblomdahl Dec 2, 2017
553b220
Merge branch 'release/1.6.2' into bugfix/SPFAM-1420-remove-on-map-des…
mblomdahl Dec 3, 2017
7a3eea6
Fix code style
mblomdahl Dec 3, 2017
a8a373c
Add changelog entry for SPFAM-1420
mblomdahl Dec 3, 2017
b4f79a0
Merge pull request #6 in ~MBLOMDAHL/mapbox-gl-circle from bugfix/SPFA…
mblomdahl Dec 3, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ Returns **{sw: {lat: [number](https://developer.mozilla.org/en-US/docs/Web/JavaS

## Changelog

### v. 1.6.2

- Handle center/radius drag interactions over Mapbox GL markers
- Watch for removal of map container and handle removal

### v. 1.6.1

- Improved move animation ([#55](https://github.com/mblomdahl/mapbox-gl-circle/issues/55))
Expand Down
12 changes: 12 additions & 0 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ const map = new mapboxgl.Map({
zoom: 14
});

window.map = map;

const markerElement = document.createElement('div');
markerElement.style.backgroundImage = 'url(https://placekitten.com/g/50/)';
markerElement.style.width = '50px';
markerElement.style.height = '50px';
markerElement.style.borderRadius = '50%';
window.marker1 = new mapboxgl.Marker(markerElement)
.setLngLat([center.lng, center.lat])
.addTo(map);

// MapboxCircle Setup

const editableOpts = {
Expand Down Expand Up @@ -158,3 +169,4 @@ window.editableCircle3
// eslint-disable-next-line
console.log('editableCircle3/contextmenu', mouseEvent);
});

45 changes: 45 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,19 @@ class MapboxCircle {
* @private
*/
_onCenterHandleMouseUpOrMapMouseOut(event) {
if (event.type === 'mouseout') {
const toMarker = event.originalEvent.toElement.classList.contains('mapboxgl-marker');
const fromCanvas = event.originalEvent.fromElement.classList.contains('mapboxgl-canvas');

const toCanvas = event.originalEvent.toElement.classList.contains('mapboxgl-canvas');
const fromMarker = event.originalEvent.fromElement.classList.contains('mapboxgl-marker');

if ((fromCanvas && toMarker) || (fromMarker && toCanvas)) {
this.map.once('mouseout', this._onCenterHandleMouseUpOrMapMouseOut); // Add back 'once' handler.
return;
}
}

const newCenter = this.center;
this._centerDragActive = false;
this.map.off('mousemove', this._onCenterHandleMouseMove);
Expand Down Expand Up @@ -618,6 +631,19 @@ class MapboxCircle {
* @private
*/
_onRadiusHandlesMouseUpOrMapMouseOut(event) {
if (event.type === 'mouseout') {
const toMarker = event.originalEvent.toElement.classList.contains('mapboxgl-marker');
const fromCanvas = event.originalEvent.fromElement.classList.contains('mapboxgl-canvas');

const toCanvas = event.originalEvent.toElement.classList.contains('mapboxgl-canvas');
const fromMarker = event.originalEvent.fromElement.classList.contains('mapboxgl-marker');

if ((fromCanvas && toMarker) || (fromMarker && toCanvas)) {
this.map.once('mouseout', this._onRadiusHandlesMouseUpOrMapMouseOut); // Add back 'once' handler.
return;
}
}

const newRadius = this.radius;
this._radiusDragActive = false;
this.map.off('mousemove', this._onRadiusHandlesMouseMove);
Expand Down Expand Up @@ -1133,6 +1159,23 @@ class MapboxCircle {

map.on('styledataloading', this._onMapStyleDataLoading);

const target = map.getContainer();
this.observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
const removedNodes = Array.from(mutation.removedNodes);
const directMatch = removedNodes.indexOf(target) > -1;
const parentMatch = removedNodes.some((parent) => parent.contains(target));
if (directMatch || parentMatch) {
this.remove();
}
});
});

let config = {
subtree: true,
childList: true
};
this.observer.observe(document.body, config);
this.map = map;
this.zoom = map.getZoom();
this._eventEmitter.emit('rendered', this);
Expand Down Expand Up @@ -1160,6 +1203,8 @@ class MapboxCircle {
remove() {
this.map.off('styledataloading', this._onMapStyleDataLoading);

this.observer.disconnect();

if (this.options.editable) {
this._unbindBroadcastListeners();
MapboxCircle._removeActiveEditableCircle(this);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mapbox-gl-circle",
"version": "1.6.1",
"version": "1.6.2",
"author": "Smith Micro Software, Inc.",
"license": "ISC",
"description": "A google.maps.Circle replacement for Mapbox GL JS API",
Expand Down