Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 17e67ce

Browse files
committed
conditionally render based on MultiLineString or FeatureCollection
1 parent a98a985 commit 17e67ce

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

app/components/Basemap.jsx

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
1-
import { geoPath } from "d3";
2-
31
export const Basemap = ({
4-
geoJSONFeatures,
5-
pathGenerator,
6-
height = 975,
7-
width = 610,
8-
pathProps,
2+
geoJSON,
3+
height = 610,
4+
pathGen,
5+
pathProps = {},
6+
width = 975,
97
}) => {
10-
const fill = props.fill || "none";
11-
const stroke = props.stroke || "white";
8+
geoJSON && console.log("geoJSON:\n", geoJSON);
9+
10+
const isMultiLineString = geoJSON.type === "MultiLineString";
1211

1312
return (
14-
<svg viewbox={`0 0 ${width} ${height}`} xmlns="http://www.w3.org/2000/svg">
13+
<svg viewBox={`0 0 ${width} ${height}`} xmlns="http://www.w3.org/2000/svg">
1514
<g>
16-
{geoJSONFeatures.map(({ id, geometry }) => {
17-
<path
18-
key={id}
19-
d={pathGenerator(geometry)}
20-
fill={fill}
21-
stroke={stroke}
22-
/>;
23-
})}
15+
{isMultiLineString
16+
? geoJSON.coordinates.map((array, index) => {
17+
return (
18+
<path
19+
key={index}
20+
d={pathGen({
21+
type: "LineString",
22+
coordinates: array,
23+
})}
24+
{...pathProps}
25+
className="hover:fill-green-400"
26+
/>
27+
);
28+
})
29+
: geoJSON.features.map(({ id, geometry }) => {
30+
return (
31+
<path
32+
key={id}
33+
d={pathGen(geometry)}
34+
{...pathProps}
35+
className="hover:fill-green-400"
36+
/>
37+
);
38+
})}
2439
</g>
2540
</svg>
2641
);

0 commit comments

Comments
 (0)