Spaces:
Runtime error
Runtime error
Commit
·
5758323
1
Parent(s):
8c93eed
Getting rid of default marker upon start
Browse filesInitializing markerPosition to null and rendering it only if it's not null.
- frontend/src/components/Map.js +17 -21
frontend/src/components/Map.js
CHANGED
@@ -10,14 +10,9 @@ import { MapContainer, TileLayer,
|
|
10 |
Tooltip
|
11 |
} from 'react-leaflet';
|
12 |
import L from 'leaflet';
|
13 |
-
// import {*} from 'geodesy';
|
14 |
-
// Test import of geodesy
|
15 |
import 'leaflet/dist/leaflet.css';
|
16 |
import generateGeodesicPoints from '../utils/mapUtils';
|
17 |
|
18 |
-
// Haversine-based geodesic interpolator
|
19 |
-
|
20 |
-
|
21 |
|
22 |
delete L.Icon.Default.prototype._getIconUrl;
|
23 |
L.Icon.Default.mergeOptions({
|
@@ -47,7 +42,7 @@ const ResizeHandler = ({ trigger }) => {
|
|
47 |
return null;
|
48 |
};
|
49 |
const Map = ( { onMapClick, searchQuery, contentType } ) => {
|
50 |
-
const [markerPosition, setMarkerPosition] = useState(
|
51 |
const [wikiContent, setWikiContent] = useState(null);
|
52 |
const [panelSize, setPanelSize] = useState('half');
|
53 |
const [wikiWidth, setWikiWidth] = useState(20);
|
@@ -274,7 +269,7 @@ const Map = ( { onMapClick, searchQuery, contentType } ) => {
|
|
274 |
overflow: 'hidden'
|
275 |
}}>
|
276 |
<MapContainer
|
277 |
-
center={markerPosition}
|
278 |
zoom={2}
|
279 |
style={{ height: '100%', width: '100%' }}
|
280 |
>
|
@@ -284,21 +279,22 @@ const Map = ( { onMapClick, searchQuery, contentType } ) => {
|
|
284 |
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
285 |
/>
|
286 |
<ClickHandler onClick={handleGeoClick} />
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
|
|
|
|
|
|
299 |
)}
|
300 |
-
</Marker>
|
301 |
-
|
302 |
{geoPoints.map((pt, index) => (
|
303 |
<Marker key={`geo-${index}`} position={[pt.lat, pt.lon]}>
|
304 |
<Popup>
|
|
|
10 |
Tooltip
|
11 |
} from 'react-leaflet';
|
12 |
import L from 'leaflet';
|
|
|
|
|
13 |
import 'leaflet/dist/leaflet.css';
|
14 |
import generateGeodesicPoints from '../utils/mapUtils';
|
15 |
|
|
|
|
|
|
|
16 |
|
17 |
delete L.Icon.Default.prototype._getIconUrl;
|
18 |
L.Icon.Default.mergeOptions({
|
|
|
42 |
return null;
|
43 |
};
|
44 |
const Map = ( { onMapClick, searchQuery, contentType } ) => {
|
45 |
+
const [markerPosition, setMarkerPosition] = useState(null);
|
46 |
const [wikiContent, setWikiContent] = useState(null);
|
47 |
const [panelSize, setPanelSize] = useState('half');
|
48 |
const [wikiWidth, setWikiWidth] = useState(20);
|
|
|
269 |
overflow: 'hidden'
|
270 |
}}>
|
271 |
<MapContainer
|
272 |
+
center={markerPosition || [0, 0]} // Default center if no marker position
|
273 |
zoom={2}
|
274 |
style={{ height: '100%', width: '100%' }}
|
275 |
>
|
|
|
279 |
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
280 |
/>
|
281 |
<ClickHandler onClick={handleGeoClick} />
|
282 |
+
{markerPosition && ( // Getting rid of default marker upon start.
|
283 |
+
<Marker position={markerPosition}>
|
284 |
+
{contentType === 'summary' && (
|
285 |
+
<Popup minWidth={250}>
|
286 |
+
{wikiContent ? (
|
287 |
+
<>
|
288 |
+
<strong>{wikiContent.title}</strong><br />
|
289 |
+
<p style={{ fontSize: '12px' }}>{wikiContent.content}</p>
|
290 |
+
</>
|
291 |
+
) : (
|
292 |
+
"Search for a location to see information"
|
293 |
+
)}
|
294 |
+
</Popup>
|
295 |
+
)}
|
296 |
+
</Marker>
|
297 |
)}
|
|
|
|
|
298 |
{geoPoints.map((pt, index) => (
|
299 |
<Marker key={`geo-${index}`} position={[pt.lat, pt.lon]}>
|
300 |
<Popup>
|