Skip to content

Commit 8bcf457

Browse files
committed
simplify & focus
1 parent aa3be46 commit 8bcf457

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2332
-2483
lines changed

package-lock.json

Lines changed: 1893 additions & 1639 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function FIXME() {
2+
return null;
3+
}

packages/map-gl-native/src/components/MapLayers.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/map-gl-native/src/components/MapProvider.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Map from "./Map.js";
44
import MapInteraction from "./MapInteraction.js";
55
import MapAutoZoom from "./MapAutoZoom.js";
66
import MapIdentify from "./MapIdentify.js";
7-
import MapLayers from "./MapLayers.js";
87
import Geojson from "../overlays/Geojson.js";
98
import Tile from "../overlays/Tile.js";
109
import VectorTile from "../overlays/VectorTile.js";
@@ -16,7 +15,6 @@ const MapProviderDefaults = {
1615
MapInteraction,
1716
MapAutoZoom,
1817
MapIdentify,
19-
MapLayers,
2018
Geojson,
2119
Tile,
2220
VectorTile,
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import Map from "./Map.js";
21
import MapProvider from "./MapProvider.js";
2+
import Map from "./Map.js";
33
import MapInteraction from "./MapInteraction.js";
44
import MapAutoZoom from "./MapAutoZoom.js";
55
import MapIdentify from "./MapIdentify.js";
6-
import MapLayers from "./MapLayers.js";
6+
import HighlightPopup from "./HighlightPopup.js";
77

88
export {
9-
Map,
109
MapProvider,
10+
Map,
1111
MapInteraction,
1212
MapAutoZoom,
1313
MapIdentify,
14-
MapLayers,
14+
HighlightPopup,
1515
};

packages/map-gl-native/src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
MapInteraction,
55
MapAutoZoom,
66
MapIdentify,
7-
MapLayers,
7+
HighlightPopup,
88
} from "./components/index.js";
99
import { Geojson, Highlight, VectorTile, Tile } from "./overlays/index.js";
1010
import {
@@ -20,11 +20,11 @@ export {
2020
MapInteraction,
2121
MapAutoZoom,
2222
MapIdentify,
23-
MapLayers,
24-
VectorTile,
25-
Tile,
23+
HighlightPopup,
2624
Geojson,
2725
Highlight,
26+
VectorTile,
27+
Tile,
2828
createMapInstance,
2929
useMapInstance,
3030
useGeolocation,

packages/map-gl-web/package.json

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,10 @@
3131
},
3232
"homepage": "https://wq.io/@wq/map-gl",
3333
"dependencies": {
34-
"@mapbox/mapbox-gl-draw": "^1.4.1",
35-
"@turf/circle": "^6.5.0",
36-
"@turf/union": "^6.5.0",
37-
"@wq/map": "^2.1.0",
38-
"@wq/material": "^2.1.0",
39-
"mapbox-gl": "npm:empty-npm-package@^1.0.0",
40-
"react-map-gl": "^7.0.25"
41-
},
42-
"devDependencies": {
43-
"@wq/material-web": "^2.1.0",
44-
"@wq/model": "^2.1.0",
45-
"@wq/react": "^2.1.0",
46-
"@wq/store": "^2.0.0"
34+
"@turf/bbox": "^7.2.0",
35+
"@turf/centroid": "^7.2.0",
36+
"@turf/union": "^7.2.0",
37+
"@wq/react": "^3.0.0-a1-dev1.g760eb56",
38+
"react-map-gl": "^8.0.1"
4739
}
4840
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* @jest-environment jsdom
33
*/
4-
import mapgl from "../index.js";
4+
import { MapProvider } from "../index.js";
55

66
test("it loads", () => {
7-
expect(mapgl.name).toBe("map-gl");
7+
expect(MapProvider.displayName).toBe("MapProvider:wq");
88
});

packages/map-gl-web/src/basemaps/Tile.js

Lines changed: 0 additions & 49 deletions
This file was deleted.

packages/map-gl-web/src/basemaps/VectorTile.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/map-gl-web/src/basemaps/index.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/map-gl-web/src/components/GeoHelpIcon.js

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 111 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,55 @@
11
import React, { useMemo } from "react";
2-
import { Popup } from "react-map-gl";
3-
import {
4-
HighlightPopup as ModalPopup,
5-
HighlightContent,
6-
computeBounds,
7-
} from "@wq/map";
8-
import { usePluginReducer } from "@wq/react";
9-
import { useMinWidth } from "@wq/material";
10-
11-
export default function HighlightPopup({ inMap }) {
12-
const showInMap = useMinWidth(600);
2+
import { Popup } from "react-map-gl/maplibre";
3+
import { useComponents, withWQ, createFallbackComponents } from "@wq/react";
4+
import centroid from "@turf/centroid";
5+
import PropTypes from "prop-types";
6+
7+
const HighlightPopupFallback = {
8+
components: {
9+
useMinWidth(width) {
10+
return window.screen.width >= width;
11+
},
12+
},
13+
};
14+
15+
function HighlightPopup({ data, inMap, onClose }) {
16+
const { useMinWidth } = useComponents(),
17+
showInMap = useMinWidth(600);
1318
if (inMap && !showInMap) {
1419
return null;
1520
} else if (!inMap && showInMap) {
1621
return null;
1722
} else if (inMap) {
18-
return <InMapPopup />;
23+
return <InMapPopup data={data} onClose={onClose} />;
1924
} else {
20-
return <ModalPopup />;
25+
return <ModalPopupWQ data={data} onClose={onClose} />;
2126
}
2227
}
2328

24-
export function InMapPopup() {
25-
const [{ highlight }, { clearHighlight }] = usePluginReducer("map"),
26-
[longitude, latitude] = useMemo(
27-
() => findPoint(highlight),
28-
[highlight]
29-
);
30-
if (!highlight || latitude === null || longitude === null) {
29+
export default withWQ(HighlightPopup, { fallback: HighlightPopupFallback });
30+
31+
export function InMapPopup({ data, onClose }) {
32+
const dataIsEmpty = !data || !data.features || data.features.length === 0,
33+
[longitude, latitude] = useMemo(() => {
34+
if (dataIsEmpty) {
35+
return [null, null];
36+
}
37+
return centroid(data).geometry.coordinates;
38+
}, [data]);
39+
40+
if (dataIsEmpty) {
3141
return null;
3242
}
43+
3344
return (
3445
<Popup
3546
latitude={latitude}
3647
longitude={longitude}
37-
onClose={clearHighlight}
48+
onClose={onClose}
3849
maxWidth="80vw"
3950
>
4051
<div style={{ maxHeight: "40vh", overflowY: "auto" }}>
41-
{highlight.features.map((feature) => (
52+
{data.features.map((feature) => (
4253
<HighlightContent
4354
key={feature.id}
4455
feature={feature}
@@ -50,23 +61,85 @@ export function InMapPopup() {
5061
);
5162
}
5263

53-
function findPoint(highlight) {
54-
if (!highlight || !highlight.features || !highlight.features.length) {
55-
return [null, null];
56-
}
57-
const point = highlight.features.find(
58-
(feature) => feature.geometry && feature.geometry.type === "Point"
64+
const ModalPopupFallback = {
65+
components: createFallbackComponents(
66+
["Popup", "View", "ScrollView", "IconButton"],
67+
"@wq/material"
68+
),
69+
};
70+
71+
function ModalPopup({ data, onClose }) {
72+
const { Popup, View, ScrollView, IconButton } = useComponents(),
73+
features = (data && data.features) || [];
74+
return (
75+
<View style={{ position: "absolute", bottom: 0 }}>
76+
<Popup
77+
open={features.length > 0}
78+
onClose={onClose}
79+
variant="persistent"
80+
>
81+
<IconButton
82+
icon="close"
83+
onClick={onClose}
84+
style={{
85+
position: "absolute",
86+
right: 0,
87+
top: 0,
88+
zIndex: 1,
89+
}}
90+
/>
91+
<ScrollView style={{ maxHeight: "33vh" }}>
92+
{features.map((feature) => (
93+
<HighlightContentWQ
94+
key={feature.id}
95+
feature={feature}
96+
/>
97+
))}
98+
</ScrollView>
99+
</Popup>
100+
</View>
59101
);
102+
}
60103

61-
if (point) {
62-
return point.geometry.coordinates;
63-
} else {
64-
const bounds = computeBounds(highlight.features);
65-
if (bounds) {
66-
const [[minx, miny], [maxx, maxy]] = bounds;
67-
return [(minx + maxx) / 2, (miny + maxy) / 2];
68-
} else {
69-
return [0, 0];
70-
}
104+
const ModalPopupWQ = withWQ(ModalPopup, { fallback: ModalPopupFallback });
105+
106+
export { ModalPopupWQ as ModalPopup };
107+
108+
const HighlightContentFallback = {
109+
components: {
110+
Text({ children }) {
111+
return <div>{children}</div>;
112+
},
113+
DefaultPopup({ feature: { id, properties = {} } }) {
114+
const { Text } = useComponents();
115+
const label = properties.label || properties.name || id;
116+
return <Text>{label}</Text>;
117+
},
118+
},
119+
};
120+
121+
function HighlightContent({ feature, inMap }) {
122+
const popupName = feature.popup
123+
? `${feature.popup}-popup`
124+
: "default-popup",
125+
components = useComponents();
126+
127+
let View = components[popupName];
128+
if (!View) {
129+
console.warn(`No component named ${popupName}, using default.`);
130+
View = components["default-popup"];
71131
}
132+
133+
return <View feature={feature} inMap={inMap} />;
72134
}
135+
136+
HighlightContent.propTypes = {
137+
feature: PropTypes.object,
138+
inMap: PropTypes.bool,
139+
};
140+
141+
const HighlightContentWQ = withWQ(HighlightContent, {
142+
fallback: HighlightContentFallback,
143+
});
144+
145+
export { HighlightContentWQ as HighlightContent };

0 commit comments

Comments
 (0)