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

Deck migration/draw layer #2614

Merged
merged 13 commits into from
Apr 16, 2024
Merged
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ bower_components
build/Release

# Dependency directories
vendor/
node_modules/
.pnp.*
.yarn/*
Expand Down
28 changes: 20 additions & 8 deletions apps/fishing-map/features/map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ViewState } from 'react-map-gl'
import { GFWAPI } from '@globalfishingwatch/api-client'
import { LayerComposer } from '@globalfishingwatch/layer-composer'
import type { RequestParameters } from '@globalfishingwatch/maplibre-gl'
import { RulersLayer } from '@globalfishingwatch/deck-layers'
import { RulersLayer, DrawLayer } from '@globalfishingwatch/deck-layers'
import {
useIsDeckLayersLoading,
useSetDeckLayerComposer,
Expand Down Expand Up @@ -39,10 +39,15 @@ import styles from './Map.module.css'
import MapAnnotations from './overlays/annotations/Annotations'
import MapAnnotationsDialog from './overlays/annotations/AnnotationsDialog'
import useRulers from './overlays/rulers/rulers.hooks'
import { useDrawLayer } from './overlays/draw/draw.hooks'
import { useMapDrawConnect } from './map-draw.hooks'
// This avoids type checking to complain
// https://github.com/visgl/deck.gl/issues/7304#issuecomment-1277850750
const RulersLayerComponent = RulersLayer as any
const MapDraw = dynamic(() => import(/* webpackChunkName: "MapDraw" */ './MapDraw'))
const DrawLayerComponent = DrawLayer as any
const DrawDialog = dynamic(
() => import(/* webpackChunkName: "DrawDialog" */ './overlays/draw/DrawDialog')
)
const PopupWrapper = dynamic(
() => import(/* webpackChunkName: "PopupWrapper" */ './popups/PopupWrapper')
)
Expand Down Expand Up @@ -72,11 +77,6 @@ const handleError = async ({ error }: any) => {
}
}

const layerComposer = new LayerComposer({
sprite:
'https://raw.githubusercontent.com/GlobalFishingWatch/map-gl-sprites/master/out/sprites-map',
})

const mapStyles = {
width: '100%',
height: '100%',
Expand Down Expand Up @@ -110,7 +110,7 @@ const MapWrapper = () => {
useMapRulersDrag()
const { rulers, editingRuler, rulersVisible } = useRulers()
// const map = useMapInstance()
// const { isMapDrawing } = useMapDrawConnect()
const { isMapDrawing } = useMapDrawConnect()
// const { generatorsConfig, globalConfig } = useGeneratorsConnect()

// const setMapReady = useSetRecoilState(mapReadyAtom)
Expand Down Expand Up @@ -248,6 +248,8 @@ const MapWrapper = () => {
// }, [isMapInteractionDisabled, styleInteractiveLayerIds])

const setDeckLayerLoadedState = useSetDeckLayerLoadedState()
const { onDrawEdit, onDrawClick, drawLayerMode, drawFeaturesIndexes, drawFeatures } =
useDrawLayer()

const currentRuler = editingRuler ? [editingRuler] : []

Expand Down Expand Up @@ -293,7 +295,17 @@ const MapWrapper = () => {
visible={rulersVisible}
/>
)}
{isMapDrawing && (
<DrawLayerComponent
data={drawFeatures}
onEdit={onDrawEdit}
onClick={onDrawClick}
selectedFeatureIndexes={drawFeaturesIndexes}
mode={drawLayerMode}
/>
)}
</DeckGL>
{isMapDrawing && <DrawDialog />}
<MapPopups />
{/* {style && (
<Map
Expand Down
161 changes: 0 additions & 161 deletions apps/fishing-map/features/map/MapDrawControl.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion apps/fishing-map/features/map/map.draw.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
DatasetConfiguration,
DatasetTypes,
} from '@globalfishingwatch/api-types'
import type { DrawFeature, DrawPointPosition } from './MapDraw'
import type { DrawFeature, DrawPointPosition } from './overlays/draw/DrawDialog'

export const getCoordinatePrecisionRounded = (coordinate: Position): Position => {
return coordinate.map((points) => Math.round(points * 100000) / 100000)
Expand Down
Loading
Loading