generated from NYCPlanning/ae-remix-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement fly to on selection for CCD, CD, and project layers with ne…
…w FlyToGeoJsonExtension Co-authored-by: horatio <[email protected]>
- Loading branch information
1 parent
9049b5a
commit 328101b
Showing
9 changed files
with
13,086 additions
and
15,519 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/components/layers/useCapitalProjectBudgetedGeoJsonLayer.client.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { GeoJsonLayer } from "@deck.gl/layers"; | ||
import { CapitalProjectBudgetedGeoJson } from "~/gen"; | ||
import { useParams } from "@remix-run/react"; | ||
import { FlyToGeoJsonExtension } from "../../extensions"; | ||
|
||
export function useCapitalProjectBudgetedGeoJsonLayer() { | ||
const { managingCode, capitalProjectId } = useParams(); | ||
|
||
return new GeoJsonLayer<CapitalProjectBudgetedGeoJson>({ | ||
id: "capitalProjectBudgetedGeoJson", | ||
data: | ||
managingCode === undefined || capitalProjectId === undefined | ||
? [] | ||
: `${import.meta.env.VITE_ZONING_API_URL}/api/capital-projects/${managingCode}/${capitalProjectId}/geojson`, | ||
pickable: true, | ||
getFillColor: ({ id }) => { | ||
switch (id) { | ||
case `${managingCode}${capitalProjectId}`: | ||
return [56, 178, 172, 166]; | ||
default: | ||
return [217, 107, 39, 166]; | ||
} | ||
}, | ||
getPointRadius: 5, | ||
getLineColor: [255, 255, 255, 255], | ||
getLineWidth: 1, | ||
updateTriggers: { | ||
getFillColor: [managingCode, capitalProjectId], | ||
getPointColor: [managingCode, capitalProjectId], | ||
}, | ||
extensions: [new FlyToGeoJsonExtension()], | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { | ||
Layer, | ||
LayerExtension, | ||
UpdateParameters, | ||
FlyToInterpolator, | ||
WebMercatorViewport, | ||
} from "@deck.gl/core"; | ||
import { bbox } from "@turf/bbox"; | ||
import { Geometry } from "geojson"; | ||
|
||
export class FlyToGeoJsonExtension extends LayerExtension { | ||
updateState( | ||
this: Layer, | ||
{ props, oldProps, changeFlags }: UpdateParameters<Layer>, | ||
): void { | ||
const { deck: deckInstance } = this.context; | ||
if (deckInstance === undefined) { | ||
throw new Error("Deck instance undefined in FlyToGeoJsonExtension"); | ||
} | ||
if ( | ||
!Array.isArray(props.data) && | ||
((Array.isArray(oldProps.data) && oldProps.data.length === 0) || | ||
changeFlags.dataChanged) | ||
) { | ||
const viewport = this.context.viewport as WebMercatorViewport; | ||
const [minX, minY, maxX, maxY] = bbox(props.data as Geometry); | ||
const { longitude, latitude, zoom } = viewport.fitBounds([ | ||
[minX, minY], | ||
[maxX, maxY], | ||
]); | ||
const newViewState = { | ||
longitude, | ||
latitude, | ||
zoom: zoom - 0.25, | ||
transitionDuration: 750, | ||
transitionInterpolator: new FlyToInterpolator(), | ||
}; | ||
deckInstance.props.onViewStateChange({ | ||
viewState: newViewState, | ||
viewId: viewport.id, | ||
interactionState: {}, | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { FlyToGeoJsonExtension } from './FlyToGeoJsonExtension'; |
Oops, something went wrong.