-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add drag and drop support for Marker #576
Conversation
"webpack": "^2.4.0", | ||
"webpack-dev-server": "^2.4.0" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should eventually look into not having all this boilerplate for each example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should eventually look into not having all this boilerplate for each example.
It is our goal that each example folder can be independently copied out of this repo and work stand-alone, so we do want a minimal set of "boilerplate".
That said, we really want that boilerplate/configuration to be as minimal as possible.
Unfortunately the current fashion in javascript bundlers and compilers is to over-engineer for modularity and they do not seem to offer umbrella modules (not a single unneeded development plugin must installed, even if that requires the user to add 20 lines to package.json and has no effect the final bundle size :).
Two options here are probably
- move to
babel-preset-env
which should remove two lines - explore
create-react-app
, which now seems to be supported bymapbox-gl
if (eventManager && this._events) { | ||
eventManager.off(this._events); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Pessimistress Seemed like it made sense to remove events if the control is unmounted – let me know if I'm missing something.
src/components/marker.js
Outdated
pancancel: this._onDragCancel.bind(this) | ||
}; | ||
eventManager.on(this._dragEvents); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These events need to be bound to the map itself (instead of the marker), otherwise you get behavior like this when the mouse moves outside the pin:
And it makes sense to attach these events after panstart, otherwise with 1000 markers you'd have 1000 onDrag event handlers being invoked after each panmove.
result.unmount(); | ||
|
||
t.end(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was going to write more tests for draggable functionality specifically, but it seems like react test renderer doesn't really do refs
, making it difficult to test the desired behavior.
@@ -245,9 +245,6 @@ hr.short { | |||
bottom: 24px; | |||
color: $white-40; | |||
} | |||
.overlays { | |||
cursor: crosshair; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having crosshair
as the cursor across the examples & website seemed like a mistake. It overrides the default cursor behavior of the library (and doesn't look great IMO)
@@ -31,7 +31,12 @@ const propTypes = Object.assign({}, BaseControl.propTypes, { | |||
// Offset from the left |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not in love with how much code ended up being required in here, but I still think it's a manageable size and broken down into small methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not in love with how much code ended up being required in here, but I still think it's a manageable size and broken down into small methods.
How generic is this code? If another component wanted to also implement dragging would it be highly reusable. Could it make sense to organize it as
Marker
> DraggableControl
> BaseControl
It could look more appealing to have these methods in a separate class that is focused on dragging, rather than mixed with the Marker specific functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea, let me try restructuring it that way.
- `event` - The pointer event. | ||
+ `event.lngLat` - The geo coordinates of the drag event, as `[lng, lat]`. | ||
|
||
##### `onDragEnd` {Function} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a concept of DragCancel? (ESCAPE key etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So technically there is a pancancel
event in hammer which could theoretically warrant an onDragCancel call, but I couldn't figure out how to trigger it (escape, dragging outside viewport, etc didn't do anything).
We could add support for escape key, though that would require another explicit keyup handler. If we're mostly trying to stay aligned with mapbox draggable markers, they currently don't have a cancel event so it might be fine to omit for now.
"webpack": "^2.4.0", | ||
"webpack-dev-server": "^2.4.0" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should eventually look into not having all this boilerplate for each example.
It is our goal that each example folder can be independently copied out of this repo and work stand-alone, so we do want a minimal set of "boilerplate".
That said, we really want that boilerplate/configuration to be as minimal as possible.
Unfortunately the current fashion in javascript bundlers and compilers is to over-engineer for modularity and they do not seem to offer umbrella modules (not a single unneeded development plugin must installed, even if that requires the user to add 20 lines to package.json and has no effect the final bundle size :).
Two options here are probably
- move to
babel-preset-env
which should remove two lines - explore
create-react-app
, which now seems to be supported bymapbox-gl
}] | ||
}, | ||
|
||
resolve: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this resolve is no longer needed and could be removed from examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -31,7 +31,12 @@ const propTypes = Object.assign({}, BaseControl.propTypes, { | |||
// Offset from the left |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not in love with how much code ended up being required in here, but I still think it's a manageable size and broken down into small methods.
How generic is this code? If another component wanted to also implement dragging would it be highly reusable. Could it make sense to organize it as
Marker
> DraggableControl
> BaseControl
It could look more appealing to have these methods in a separate class that is focused on dragging, rather than mixed with the Marker specific functionality.
This PR adds support for drag and drop events to the
<Marker>
component.Simply add a
draggable
prop to your Marker, and subscribe to whatever events you need:This API design is intended to be similar to Mapbox's draggable markers.