Skip to content

Commit 4d93ba2

Browse files
committed
Greate a GridLine
1 parent 2b75ab8 commit 4d93ba2

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import SelectFeature from "./examples/SelectFeature";
55
import EarthquakeClusters from "./examples/EarthquakeClusters";
66
import { useState } from "react";
77
import SecondMapDialog from "./examples/SecondMapDialog";
8+
import GridLine from "./components/map/layers/GridLine";
89

910
function App() {
1011
const [showDialog, setShowDialog] = useState(false);
@@ -17,6 +18,7 @@ function App() {
1718
<Map>
1819
{/* <SelectFeature /> */}
1920
<EarthquakeClusters />
21+
<GridLine />
2022
</Map>
2123
{showDialog && <SecondMapDialog />}
2224
</div>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React, { useContext, useEffect } from "react";
2+
import MapContext from "../context/MapContext";
3+
import { Graticule } from "ol";
4+
import { Stroke } from "ol/style";
5+
6+
type Props = {};
7+
8+
const GridLine = (props: Props) => {
9+
const { map } = useContext(MapContext);
10+
11+
// Create a grid line layer using OpenLayers Graticule function
12+
const gridLineLayer = new Graticule({
13+
strokeStyle: new Stroke({
14+
color: "rgba(128,128,128,0.9)",
15+
width: 2,
16+
lineDash: [0.5, 4],
17+
}),
18+
showLabels: true,
19+
wrapX: false,
20+
zIndex: 10,
21+
});
22+
23+
useEffect(() => {
24+
console.log("Adding grid line layer to map");
25+
if (!map) return;
26+
map.addLayer(gridLineLayer);
27+
28+
return () => {
29+
map.removeLayer(gridLineLayer);
30+
};
31+
});
32+
33+
return null;
34+
};
35+
36+
export default GridLine;

0 commit comments

Comments
 (0)