Skip to content
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 FeatureSelection tool #271

Merged
merged 28 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
aa1e751
extend EditableGeoJsonLayer to allow send an eventManager as a prop
padawannn Jan 11, 2022
2ac4f1d
minor changes
padawannn Jan 12, 2022
e340c32
bug fix
padawannn Jan 12, 2022
5f55f19
finish google maps compatibility and added the mask extension (#278)
padawannn Jan 24, 2022
04f1f9f
Merge branch 'master' into drawingTool-googleMaps-compatibility
padawannn Jan 24, 2022
224154a
refactor
padawannn Jan 24, 2022
6ee1a40
wip
padawannn Jan 24, 2022
e73fd6f
wip
padawannn Jan 24, 2022
74b97fd
test
padawannn Jan 25, 2022
cbafc72
wip
padawannn Jan 25, 2022
0b13376
add google map effect
padawannn Jan 25, 2022
3052490
wip
padawannn Jan 25, 2022
1cef257
new refactor
padawannn Jan 27, 2022
d745cc0
conflicts
padawannn Jan 27, 2022
f0bbb9a
changelog
padawannn Jan 27, 2022
aafbac8
mask layer
padawannn Jan 27, 2022
cd4c0ef
remove unused imports
padawannn Jan 27, 2022
2f5354e
Update FeatureSelectionLayer.js
padawannn Jan 28, 2022
fab0cf7
update deck gl version
padawannn Feb 1, 2022
30e7c45
change log
padawannn Feb 1, 2022
70056a0
Merge branch 'drawingTool-googleMaps-compatibility' of github.com:Car…
padawannn Feb 1, 2022
1c7484f
Update CHANGELOG.md
padawannn Feb 1, 2022
2f414d1
change log
padawannn Feb 1, 2022
396562c
change log
padawannn Feb 1, 2022
a5cfaab
update deck version in all packages
padawannn Feb 1, 2022
e7be25b
Modify changelog entries
VictorVelarde Feb 1, 2022
af39813
Add changelog entry
VictorVelarde Feb 1, 2022
52b48a7
Bump internal dependencies among packages
VictorVelarde Feb 1, 2022
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
2 changes: 2 additions & 0 deletions packages/react-redux/src/slices/cartoSlice.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,5 @@ export function setDrawingToolEnabled(enabled: boolean): {
};

export function selectSpatialFilter(state: any, sourceId?: string): object | null;

export function selectDrawingToolMode(state: any): string | false;
Copy link
Contributor

@VictorVelarde VictorVelarde Jan 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If 'false' is equivalent to 'None', I think it could be better to add that option to an enum or type. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selectDrawingToolMode is a selector that return false if the spatialFilter is null in the store (the default state). I think that creating another enum type could be over-engineering

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just see there are other options without adding boolean to the mix:

  • a) just an enum / type: DrawingToolMode.Type1, DrawingToolMode.Type2,... + DrawingToolMode.None, or more simple
  • b) just respecting the null for 'None'.

"selectDrawingToolMode" doesn't sound like a boolean to me, but a value from a predefined list. If required, we can later do in code something like this

const noFilter = selectDrawingToolMode === null
if (noFilter) ...

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done the b option

4 changes: 2 additions & 2 deletions packages/react-redux/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Credentials } from '@carto/react-api';
import { OauthApp } from '@carto/react-auth';
import { CartoBasemapsNames } from '@carto/react-basemaps';
import { DRAW_MODES, Viewport } from '@carto/react-core';
import { Viewport } from '@carto/react-core';
import { Geometry } from 'geojson';

export type ViewState = {
Expand Down Expand Up @@ -45,7 +45,7 @@ export type CartoState = {
spatialFilter: Geometry,
featuresReady: { [key: string]: boolean },
drawingToolEnabled: boolean,
drawingToolMode: typeof DRAW_MODES
drawingToolMode: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why such change here? isn't it better to use a more restricted type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because typeof DRAW_MODES doesn't work when I integrate it in typescript project. I accept suggestions

} & InitialCartoState;

export type InitialOauthState = {
Expand Down
6 changes: 4 additions & 2 deletions packages/react-widgets/src/layers/DrawingToolLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import { useDispatch, useSelector } from 'react-redux';
import { EDIT_MODES } from '@carto/react-core';
import { hexToRgb, useTheme } from '@material-ui/core';
import { useEffect, useMemo, useState } from 'react';
import EditableCartoGeoJsonLayer from './EditableCartoGeoJsonLayer';

const { ViewMode, TranslateMode, ModifyMode, CompositeMode } = nebulaModes;

const EditMode = new CompositeMode([new TranslateMode(), new ModifyMode()]);

export default function DrawingToolLayer() {
export default function DrawingToolLayer({ eventManager }) {
const dispatch = useDispatch();
const theme = useTheme();
const [selectedFeatureIndex, setSelectedFeatureIndex] = useState(null);
Expand Down Expand Up @@ -50,7 +51,8 @@ export default function DrawingToolLayer() {

const mainColor = hasGeometry && !isSelected ? secondaryAsRgba : primaryAsRgba;

return new EditableGeoJsonLayer({
return new EditableCartoGeoJsonLayer({
eventManager,
id: 'DrawingToolLayer',
pickable: !!selectedMode,
data: {
Expand Down
30 changes: 30 additions & 0 deletions packages/react-widgets/src/layers/EditableCartoGeoJsonLayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { EditableGeoJsonLayer } from '@nebula.gl/layers';

const EVENT_TYPES = ['anyclick', 'pointermove', 'panstart', 'panmove', 'panend', 'keyup'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a comment with a bit of explanation on this would be really useful, about how this should be better a mechanism in nebula itself, with probably a PR on that in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I'm going to add a link to the original code and write a small explanation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


export default class EditableCartoGeoJsonLayer extends EditableGeoJsonLayer {
_addEventHandlers() {
const eventManager = this._getEventManager();
const { eventHandler } = this.state._editableLayerState;

for (const eventType of EVENT_TYPES) {
eventManager.on(eventType, eventHandler, {
// give nebula a higher priority so that it can stop propagation to deck.gl's map panning handlers
priority: 100
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is 100 the "top priority" or how does is work? I mean, is it an arbitrary number?.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't know XD. This code has been copied from the original nebula code
https://github.com/uber/nebula.gl/blob/master/modules/layers/src/layers/editable-layer.ts#L83

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XD, ok then add this link to code...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

});
}
}

_removeEventHandlers() {
const eventManager = this._getEventManager();
const { eventHandler } = this.state._editableLayerState;

for (const eventType of EVENT_TYPES) {
eventManager.off(eventType, eventHandler);
}
}

_getEventManager() {
return this.props.eventManager || this.context.deck.eventManager;
}
}