DebasishDhal99 commited on
Commit
bbaff48
·
1 Parent(s): fede4e1

Add borders for satellite map view

Browse files

- Manually copypasted a json denoting all the border coordinates of the world. Source - https://raw.githubusercontent.com/datasets/geo-countries/master/data/countries.geojson
- This was easier than using a module.
- Sub-country level border unavailable in the copypasted data. I won't add it as it'll make it messier.

Files changed (2) hide show
  1. README.md +2 -1
  2. frontend/src/components/Map.js +27 -5
README.md CHANGED
@@ -22,4 +22,5 @@ pinned: false
22
 
23
  ## Resources
24
  - [Geodesic Area calculator](https://geographiclib.sourceforge.io/cgi-bin/Planimeter?type=polygon&rhumb=geodesic&radius=6378137&flattening=1%2F298.257223563&input=40.7128%2C+-74.0060%0D%0A34.0522%2C+-118.2437%0D%0A51.5074%2C+0.1278&option=Submit)
25
- - [Area calculator function in geographiclib-geodesic module's codebase](https://github.com/geographiclib/geographiclib-js/blob/main/geodesic/PolygonArea.js)
 
 
22
 
23
  ## Resources
24
  - [Geodesic Area calculator](https://geographiclib.sourceforge.io/cgi-bin/Planimeter?type=polygon&rhumb=geodesic&radius=6378137&flattening=1%2F298.257223563&input=40.7128%2C+-74.0060%0D%0A34.0522%2C+-118.2437%0D%0A51.5074%2C+0.1278&option=Submit)
25
+ - [Area calculator function in geographiclib-geodesic module's codebase](https://github.com/geographiclib/geographiclib-js/blob/main/geodesic/PolygonArea.js)
26
+ - [Country border data](https://raw.githubusercontent.com/datasets/geo-countries/master/data/countries.geojson)
frontend/src/components/Map.js CHANGED
@@ -9,7 +9,7 @@ import { MapContainer, TileLayer,
9
  Polyline,
10
  Tooltip,
11
  Polygon,
12
- // GeoJSON
13
  } from 'react-leaflet';
14
  import L from 'leaflet';
15
  import 'leaflet/dist/leaflet.css';
@@ -78,6 +78,8 @@ const Map = ( { onMapClick, searchQuery, contentType } ) => {
78
 
79
  const [viewPanelOpen, setViewPanelOpen] = useState(true);
80
 
 
 
81
  const handleMouseDown = (e) => {
82
  isDragging.current = true;
83
  startX.current = e.clientX;
@@ -294,6 +296,14 @@ const Map = ( { onMapClick, searchQuery, contentType } ) => {
294
  }
295
  }, [geoToolMode, areaPoints]);
296
 
 
 
 
 
 
 
 
 
297
 
298
  const wrapCount = 3;
299
 
@@ -340,6 +350,7 @@ const Map = ( { onMapClick, searchQuery, contentType } ) => {
340
 
341
  // const longitudeLines = generateLongitudeLines(30, 1);
342
 
 
343
  return (
344
  <div ref={containerRef} style={{ display: 'flex', height: '100vh', width: '100%', overflow: 'hidden' }}>
345
  {panelSize !== 'closed' && (
@@ -496,13 +507,24 @@ const Map = ( { onMapClick, searchQuery, contentType } ) => {
496
  {baseLayer === "satellite" && (
497
  <>
498
  <TileLayer
499
- url="https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
500
- attribution='&copy; <a href="https://www.esri.com/">Esri</a> & contributors'
501
  />
502
  <TileLayer
503
- url="https://{s}.basemaps.cartocdn.com/light_only_labels/{z}/{x}/{y}.png"
504
- attribution='&copy; CartoDB'
505
  />
 
 
 
 
 
 
 
 
 
 
 
506
  </>
507
  )}
508
 
 
9
  Polyline,
10
  Tooltip,
11
  Polygon,
12
+ GeoJSON
13
  } from 'react-leaflet';
14
  import L from 'leaflet';
15
  import 'leaflet/dist/leaflet.css';
 
78
 
79
  const [viewPanelOpen, setViewPanelOpen] = useState(true);
80
 
81
+ const [countryBorders, setCountryBorders] = useState(null);
82
+
83
  const handleMouseDown = (e) => {
84
  isDragging.current = true;
85
  startX.current = e.clientX;
 
296
  }
297
  }, [geoToolMode, areaPoints]);
298
 
299
+ useEffect(() => {
300
+ if (!countryBorders) {
301
+ fetch('/data/countryBorders.json')
302
+ .then(res => res.json())
303
+ .then(data => setCountryBorders(data))
304
+ .catch(err => console.error("Failed to load country borders:", err));
305
+ }
306
+ }, [countryBorders]);
307
 
308
  const wrapCount = 3;
309
 
 
350
 
351
  // const longitudeLines = generateLongitudeLines(30, 1);
352
 
353
+
354
  return (
355
  <div ref={containerRef} style={{ display: 'flex', height: '100vh', width: '100%', overflow: 'hidden' }}>
356
  {panelSize !== 'closed' && (
 
507
  {baseLayer === "satellite" && (
508
  <>
509
  <TileLayer
510
+ url="https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
511
+ attribution='&copy; <a href="https://www.esri.com/">Esri</a> & contributors'
512
  />
513
  <TileLayer
514
+ url="https://{s}.basemaps.cartocdn.com/light_only_labels/{z}/{x}/{y}.png"
515
+ attribution='&copy; CartoDB'
516
  />
517
+ {countryBorders && (
518
+ <GeoJSON
519
+ data={countryBorders}
520
+ style={{
521
+ color: '#ffff99',
522
+ weight: 1.5,
523
+ opacity: 0.8,
524
+ fillOpacity: 0.1,
525
+ }}
526
+ />
527
+ )}
528
  </>
529
  )}
530