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

feat: replace StaticMap By Maplibre #308

Merged
merged 7 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
"author": "",
"license": "ISC",
"dependencies": {
"@deck.gl/core": "^8.9.32",
"@deck.gl/extensions": "^8.9.32",
"@deck.gl/geo-layers": "^8.9.32",
"@deck.gl/layers": "^8.9.32",
"@deck.gl/mesh-layers": "^8.9.32",
"@deck.gl/react": "^8.9.32",
"@fortawesome/fontawesome-svg-core": "^1.2.36",
"@fortawesome/free-solid-svg-icons": "^5.15.4",
"@fortawesome/react-fontawesome": "^0.1.17",
Expand All @@ -29,18 +35,18 @@
"@loaders.gl/i3s": "^4.0.0-beta.2",
"@loaders.gl/loader-utils": "^4.0.0-beta.2",
"@loaders.gl/tiles": "^4.0.0-beta.2",
"@luma.gl/core": "^8.5.14",
"@math.gl/proj4": "^3.6.3",
"@probe.gl/stats": "^4.0.4",
"@reduxjs/toolkit": "^1.9.5",
"deck.gl": "^8.8.3",
"apache-arrow": "^13.0.0",
belom88 marked this conversation as resolved.
Show resolved Hide resolved
"html2canvas": "^1.4.1",
"maplibre-gl": "^3.5.2",
"normalize.css": "^8.0.1",
"prop-types": "^15.8.1",
"react": "^17.0.2",
"react-color": "^2.19.3",
"react-dom": "^17.0.2",
"react-map-gl": "^5.0.0",
"react-map-gl": "^7.1.6",
"react-redux": "^8.1.1",
"react-responsive": "^9.0.0-beta.8",
"react-router-dom": "^6.2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { setupStore } from "../../../redux/store";
import { setColorsByAttrubute } from "../../../redux/slices/colors-by-attribute-slice";

jest.mock("@loaders.gl/core");

jest.mock("@loaders.gl/i3s", () => {
return jest.fn().mockImplementation(() => {
return null;
});
});
jest.mock("../histogram", () => ({
HistogramChart: jest.fn().mockImplementation(() => <div>HistogramChart</div>),
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,36 @@ import { MemoryUsagePanel } from "../../memory-usage-panel/memory-usage-panel";
import { setupStore } from "../../../redux/store";
import { setDragMode } from "../../../redux/slices/drag-mode-slice";

jest.mock("@loaders.gl/core");
jest.mock("react-map-gl/maplibre", () => {
return jest.fn().mockImplementation(() => {
return null;
});
});
jest.mock("@loaders.gl/core", () => {
return {
load: jest.fn(),
};
});
jest.mock("@loaders.gl/i3s", () => {
return jest.fn().mockImplementation(() => {
return null;
});
});
jest.mock("@loaders.gl/3d-tiles", () => {
return jest.fn().mockImplementation(() => {
return null;
});
});
jest.mock("@deck.gl/layers", () => {
return jest.fn().mockImplementation(() => {
return null;
});
});
jest.mock("@deck.gl/geo-layers", () => {
return jest.fn().mockImplementation(() => {
return null;
});
});
jest.mock("../../deck-gl-wrapper/deck-gl-wrapper");
jest.mock("../../main-tools-panel/main-tools-panel");
jest.mock("../../layers-panel/layers-panel");
Expand Down
5 changes: 5 additions & 0 deletions src/components/debug-panel/debug-panel.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import {
selectBoundingVolumeType,
} from "../../redux/slices/debug-options-slice";

jest.mock("@loaders.gl/i3s", () => {
return jest.fn().mockImplementation(() => {
return null;
});
});
jest.mock("../../utils/hooks/layout");
jest.mock("../close-button/close-button", () => ({
CloseButton: ({ onClick }) => {
Expand Down
48 changes: 40 additions & 8 deletions src/components/deck-gl-wrapper/deck-gl-wrapper.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,45 @@ import {

// Mocks
jest.mock("@loaders.gl/core");
jest.mock("@loaders.gl/i3s", () => {
return {
COORDINATE_SYSTEM: {
METER_OFFSETS: 2,
LNGLAT_OFFSETS: 3,
},
};
});
jest.mock("@loaders.gl/3d-tiles", () => {
return jest.fn().mockImplementation(() => {
return null;
});
});
jest.mock("@loaders.gl/images");
jest.mock("@loaders.gl/tiles");
jest.mock("@deck.gl/react", () => {
return jest.fn().mockImplementation(() => {
return null;
});
});
jest.mock("react-map-gl/maplibre", () => {
return {
Map: jest.fn().mockImplementation(() => <div></div>),
};
});
jest.mock("@deck.gl/core");
jest.mock("@deck.gl/layers");
jest.mock("@deck.gl/geo-layers");
jest.mock("react-map-gl");
jest.mock("@deck.gl/layers", () => {
return {
LineLayer: jest.fn(),
ScatterplotLayer: jest.fn(),
};
});

jest.mock("@deck.gl/geo-layers", () => {
return {
Tile3DLayer: jest.fn(),
TerrainLayer: jest.fn(),
};
});
jest.mock("../../utils/debug/build-minimap-data");
jest.mock("../../utils/debug/texture-selector-utils");
jest.mock("../../utils/debug/frustum-utils");
Expand Down Expand Up @@ -61,7 +89,7 @@ import { setupStore } from "../../redux/store";
import { setColorsByAttrubute } from "../../redux/slices/colors-by-attribute-slice";
import { setDragMode } from "../../redux/slices/drag-mode-slice";
import { setDebugOptions } from "../../redux/slices/debug-options-slice";
import { addBaseMap } from "../../redux/slices/base-maps-slice"
import { addBaseMap } from "../../redux/slices/base-maps-slice";

const simpleCallbackMock = jest.fn().mockImplementation(() => {
/* Do Nothing */
Expand Down Expand Up @@ -336,7 +364,11 @@ describe("Deck.gl I3S map component", () => {

it("Should render pickable with auto highlighting", () => {
const store = setupStore();
callRender(renderWithProvider, { pickable: true, autoHighlight: true }, store);
callRender(
renderWithProvider,
{ pickable: true, autoHighlight: true },
store
);
const { pickable, autoHighlight } = Tile3DLayer.mock.lastCall[0];
expect(pickable).toBe(true);
expect(autoHighlight).toBe(true);
Expand Down Expand Up @@ -509,8 +541,7 @@ describe("Deck.gl I3S map component", () => {

describe("Render TerrainLayer", () => {
const store = setupStore();
store.dispatch(
addBaseMap({ id: "Terrain", mapUrl: "", name: "Terrain" }));
store.dispatch(addBaseMap({ id: "Terrain", mapUrl: "", name: "Terrain" }));
it("Should render terrain", () => {
callRender(renderWithProvider, undefined, store);
expect(TerrainLayer).toHaveBeenCalled();
Expand All @@ -519,7 +550,8 @@ describe("Deck.gl I3S map component", () => {
it("Should call onTerrainTileLoad", () => {
const store = setupStore();
store.dispatch(
addBaseMap({ id: "Terrain", mapUrl: "", name: "Terrain" }));
addBaseMap({ id: "Terrain", mapUrl: "", name: "Terrain" })
);
const { rerender } = callRender(renderWithProvider, undefined, store);
const { onTileLoad } = TerrainLayer.mock.lastCall[0];
const terrainTile = {
Expand Down
25 changes: 9 additions & 16 deletions src/components/deck-gl-wrapper/deck-gl-wrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Map as MaplibreMap } from "react-map-gl/maplibre";
import DeckGL from "@deck.gl/react";
import { LineLayer, ScatterplotLayer } from "@deck.gl/layers";
import { TerrainLayer, Tile3DLayer } from "@deck.gl/geo-layers";
Expand All @@ -14,7 +15,6 @@ import {
View,
} from "@deck.gl/core";
import { useEffect, useMemo, useState, useRef } from "react";
import { StaticMap } from "react-map-gl";
import { CONTRAST_MAP_STYLES } from "../../constants/map-styles";
import {
NormalsDebugData,
Expand Down Expand Up @@ -58,7 +58,10 @@ import {
selectBoundingVolumeColorMode,
selectBoundingVolumeType,
} from "../../redux/slices/debug-options-slice";
import { selectBaseMaps, selectSelectedBaseMapId } from "../../redux/slices/base-maps-slice";
import {
selectBaseMaps,
selectSelectedBaseMapId,
} from "../../redux/slices/base-maps-slice";

const TRANSITION_DURAITON = 4000;
const INITIAL_VIEW_STATE = {
Expand Down Expand Up @@ -212,8 +215,8 @@ export const DeckGlWrapper = ({
const baseMaps = useAppSelector(selectBaseMaps);
const selectedBaseMapId = useAppSelector(selectSelectedBaseMapId);
const selectedBaseMap = baseMaps.find((map) => map.id === selectedBaseMapId);
const showTerrain=selectedBaseMap?.id === "Terrain";
const mapStyle=selectedBaseMap?.mapUrl;
const showTerrain = selectedBaseMap?.id === "Terrain";
const mapStyle = selectedBaseMap?.mapUrl;
const VIEWS = useMemo(
() => [
new MapView({
Expand Down Expand Up @@ -761,21 +764,11 @@ export const DeckGlWrapper = ({
currentViewport = viewport;
}}
{!showTerrain && (
<StaticMap
reuseMaps
mapStyle={mapStyle}
preventStyleDiffing
preserveDrawingBuffer
/>
<MaplibreMap mapStyle={mapStyle} terrain={undefined}></MaplibreMap>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<MaplibreMap mapStyle={mapStyle} terrain={undefined}></MaplibreMap>
<MaplibreMap mapStyle={mapStyle}></MaplibreMap>

)}
{mapStyle && (
<View id="minimap">
<StaticMap
reuseMaps
mapStyle={CONTRAST_MAP_STYLES[mapStyle]}
preventStyleDiffing
preserveDrawingBuffer
/>
<MaplibreMap mapStyle={CONTRAST_MAP_STYLES[mapStyle]}></MaplibreMap>
</View>
)}
</DeckGL>
Expand Down
7 changes: 2 additions & 5 deletions src/components/layers-panel/layers-panel.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ import { LayerSettingsPanel } from "./layer-settings-panel";
import { load } from "@loaders.gl/core";
import { PageId } from "../../types";
import { setupStore } from "../../redux/store";
import {
selectSelectedBaseMapId,
} from "../../redux/slices/base-maps-slice";
import { selectSelectedBaseMapId } from "../../redux/slices/base-maps-slice";

jest.mock("@loaders.gl/core", () => ({
load: jest.fn(),
}));

jest.mock("@loaders.gl/i3s", () => ({
ArcGisWebSceneLoader: jest.fn(),
}));
Expand Down Expand Up @@ -277,7 +274,7 @@ describe("Layers Panel", () => {
});

const state = store.getState();
const baseMapId = selectSelectedBaseMapId(state);
const baseMapId = selectSelectedBaseMapId(state);
expect(baseMapId).toEqual("https://test-base-map.url");
});

Expand Down
5 changes: 5 additions & 0 deletions src/components/layers-panel/map-options-panel.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import {
selectSelectedBaseMapId,
} from "../../redux/slices/base-maps-slice";

jest.mock("@loaders.gl/i3s", () => {
return jest.fn().mockImplementation(() => {
return null;
});
});
jest.mock("./base-map-list-item/base-map-list-item");
jest.mock("../plus-button/plus-button");
jest.mock("./delete-confirmation");
Expand Down
6 changes: 6 additions & 0 deletions src/components/map-control-panel/map-control-panel.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { MapControllPanel } from "./map-control-panel";
import { setupStore } from "../../redux/store";
import { setDragMode } from "../../redux/slices/drag-mode-slice";

jest.mock("@loaders.gl/i3s", () => {
return jest.fn().mockImplementation(() => {
return null;
});
});

describe("MapControllPanel", () => {
let componentElement;
let buttons;
Expand Down
28 changes: 12 additions & 16 deletions src/pages/dashboard/dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Map as MaplibreMap } from "react-map-gl/maplibre";
import { useState, useCallback } from "react";
import { StaticMap } from "react-map-gl";
import DeckGL from "@deck.gl/react";
import { Tile3DLayer } from "@deck.gl/geo-layers";
import { I3SLoader } from "@loaders.gl/i3s";
Expand Down Expand Up @@ -149,7 +149,7 @@ const Title = styled.div<LayoutProps>`
desktop: "73px",
tablet: "73px",
mobile: "45px",
})};
})};
`;

const GreenText = styled.span`
Expand Down Expand Up @@ -179,7 +179,7 @@ const IphoneImage = styled.img`
left: 1670px;
z-index: 4;
width: 198px;

@media (max-width: 1670px) {
left: calc(100% - 184px);
}
Expand Down Expand Up @@ -310,7 +310,7 @@ export const Dashboard = () => {

return (
<DashboardContainer id="dashboard-container" layout={layout}>
<DeckWithTitleWrapper layout={layout}>
<DeckWithTitleWrapper layout={layout}>
<Title id="dashboard-title" layout={layout}>
Explore and Debug I3S Data with one
<GreenText id="green-text"> Simple and Easy-to-Use Tool</GreenText>
Expand All @@ -322,7 +322,7 @@ export const Dashboard = () => {
layers={[tile3DLayer]}
initialViewState={viewState}
>
<StaticMap mapStyle={DEFAULT_MAP_STYLE} />
<MaplibreMap mapStyle={DEFAULT_MAP_STYLE}></MaplibreMap>
</DeckGL>
</DeckWithTitleWrapper>
<Wrapper id="tools-wrapper" layout={layout}>
Expand All @@ -333,17 +333,13 @@ export const Dashboard = () => {
src={AppShowcase}
/>
)}
{layout === Layout.Desktop &&
(
<>
<MacImage id="mac-image" src={Mac} />
<IphoneImage id="iphone-image" src={Iphone} />
</>
)}
<ToolsContainer
id="tools-description-container"
layout={layout}
>
{layout === Layout.Desktop && (
<>
<MacImage id="mac-image" src={Mac} />
<IphoneImage id="iphone-image" src={Iphone} />
</>
)}
<ToolsContainer id="tools-description-container" layout={layout}>
<ToolsItem id="tools-item-viewer" layout={layout}>
<ViewerImage />
<ToolItemDescription layout={layout}>
Expand Down
8 changes: 6 additions & 2 deletions src/redux/slices/attribute-stats-map-slice.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import {
getAttributeStatsInfo,
selectStatisitcsMap,
} from "./attribute-stats-map-slice";
import { StatsInfo } from "@loaders.gl/i3s";

jest.mock("@loaders.gl/core");
jest.mock("@loaders.gl/i3s", () => {
return jest.fn().mockImplementation(() => {
return null;
});
});

describe("slice: attribute-stats-map", () => {
it("Selector should return the initial state", () => {
Expand Down Expand Up @@ -54,7 +58,7 @@ describe("slice: attribute-stats-map", () => {
});
});

const stats: StatsInfo = {
const stats = {
avg: 27.159085097827166,
max: 1408.377901,
min: 0,
Expand Down
Loading
Loading