-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from 2308-Bread/feat/map
Feat/map
- Loading branch information
Showing
19 changed files
with
308 additions
and
14 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
File renamed without changes.
File renamed without changes.
Empty file.
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 {}; |
Empty file.
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 {}; |
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,18 @@ | ||
body, html { | ||
margin: 0; | ||
padding: 0; | ||
overflow: hidden; | ||
} | ||
|
||
.main { | ||
height: 100vh; | ||
width: 100vw; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.map-container { | ||
height: 60vh; | ||
width: 100%; | ||
} |
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
import React from 'react'; | ||
import './Main.css'; | ||
import MapComponent from '../Map/Map'; | ||
|
||
const Main = () => { | ||
return ( | ||
<div className="main"> | ||
<div className="map-container"> | ||
<MapComponent /> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Main; |
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,24 @@ | ||
.map-container { | ||
margin: 20px auto; | ||
margin-top: 100px; | ||
margin-bottom: 100px; | ||
width: 60%; | ||
max-width: 600px; | ||
overflow: hidden; | ||
} | ||
|
||
.leaflet-container { | ||
height: calc(100vh - 100px); | ||
width: 100%; | ||
} | ||
|
||
.country-label div { | ||
color: rgba(41, 72, 51, 0.7); | ||
font-size: 1rem; | ||
text-align: center; | ||
font-weight: bold; | ||
} | ||
|
||
.leaflet-control-attribution { | ||
display: none; | ||
} |
Empty file.
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,75 @@ | ||
import React, { useEffect } from 'react'; | ||
import { MapContainer, TileLayer, useMap } from 'react-leaflet'; | ||
import L from 'leaflet'; | ||
import countriesGeoJson from '../../data/countries.json'; | ||
import './Map.css'; | ||
|
||
const MapComponent = () => { | ||
return ( | ||
<MapContainer center={[0, 0]} zoom={2} style={{ height: '80vh', width: '100%' }}> | ||
<TileLayer | ||
url="https://tile.thunderforest.com/mobile-atlas/{z}/{x}/{y}.png?apikey=a7eda3efcc6b40449d697372a8171c3b" | ||
attribution='© <a href="http://thunderforest.com">Thunderforest</a> contributors' | ||
noWrap={true} | ||
/> | ||
<GeoJSONLayer /> | ||
</MapContainer> | ||
); | ||
}; | ||
|
||
const GeoJSONLayer = () => { | ||
const map = useMap(); | ||
|
||
useEffect(() => { | ||
const geoJsonLayer = L.geoJSON(countriesGeoJson as any, { | ||
style: () => ({ | ||
fillColor: "rgba(62, 109, 78, 0.5)", | ||
color: '#3e6d4e', | ||
weight: 1, | ||
dashArray: '3', | ||
fillOpacity: 0.5 | ||
}), | ||
onEachFeature: (feature, layer) => { | ||
|
||
layer.on({ | ||
mouseover: (e) => { | ||
var layer = e.target; | ||
layer.setStyle({ | ||
fillColor: "rgba(62, 109, 78, 0.5)", | ||
weight: 3, | ||
opacity: 1, | ||
color: '#3e6d4e', | ||
dashArray: '3', | ||
fillOpacity: 0.7 | ||
}); | ||
}, | ||
mouseout: (e) => { | ||
var layer = e.target; | ||
geoJsonLayer.resetStyle(layer); | ||
} | ||
}); | ||
|
||
if (feature.properties && feature.properties.name) { | ||
if (layer instanceof L.Polygon || layer instanceof L.Polyline) { | ||
const center = layer.getBounds().getCenter(); | ||
const marker = L.marker(center, { | ||
icon: new L.DivIcon({ | ||
className: 'country-label', | ||
html: `<div>${feature.properties.name}</div>`, | ||
iconSize: L.point(100, 40), | ||
iconAnchor: [40, 20] | ||
}) | ||
}); | ||
marker.addTo(map) | ||
} | ||
} | ||
}, | ||
}) | ||
|
||
geoJsonLayer.addTo(map) | ||
}, [map]) | ||
|
||
return null; | ||
} | ||
|
||
export default MapComponent |
File renamed without changes.
Empty file.
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 {}; |
Oops, something went wrong.