-
-
Notifications
You must be signed in to change notification settings - Fork 125
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 #178 from damianmoore/map-photo-clustering#14
[Feature] 14: Map photo clustering and filtering according to pan and zoom
- Loading branch information
Showing
10 changed files
with
196 additions
and
190 deletions.
There are no files selected for viewing
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 |
---|---|---|
@@ -1,58 +1,85 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { Link } from 'react-router-dom' | ||
import { Map, Marker, Popup, TileLayer } from 'react-leaflet' | ||
import '../static/css/Map.css' | ||
import { MapContainer, Marker, Popup, TileLayer } from 'react-leaflet' | ||
import MarkerClusterGroup from 'react-leaflet-markercluster' | ||
|
||
import '../static/css/Map.css' | ||
import 'react-leaflet-markercluster/dist/styles.min.css' // sass | ||
|
||
const MapView = ({ photos, bounds, location, zoom, hideAttribution }) => { | ||
const MapView = ({ | ||
photos, | ||
bounds, | ||
location, | ||
zoom, | ||
maxZoom, | ||
hideAttribution, | ||
}) => { | ||
let markers = [] | ||
let tileUrl = 'https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png' | ||
let attribution = hideAttribution ? '' : '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' | ||
let attribution = hideAttribution | ||
? '' | ||
: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' | ||
let tileLayer = <TileLayer attribution={attribution} url={tileUrl} /> | ||
|
||
if (photos) { | ||
markers = photos.map((photo, idx) => ( | ||
photo.location ? | ||
markers = photos.map((photo, idx) => | ||
photo.location ? ( | ||
<Marker | ||
key={`marker-${photo.id}`} | ||
position={[photo.location[0], photo.location[1]]}> | ||
position={[photo.location[0], photo.location[1]]} | ||
> | ||
<Popup> | ||
<Link to={'/photo/' + photo.id} key={photo.id}> | ||
<img src={photo.thumbnail} style={{ width: 128, height: 128 }} alt="marker popup" /> | ||
<img | ||
src={photo.thumbnail} | ||
style={{ width: 128, height: 128 }} | ||
alt="marker popup" | ||
/> | ||
</Link> | ||
</Popup> | ||
</Marker> | ||
: | ||
null | ||
)) | ||
|
||
) : null | ||
) | ||
return ( | ||
<div className="Map"> | ||
<Map bounds={bounds} boundsOptions={{padding: [100, 100], maxZoom: 15}}> | ||
<MapContainer | ||
bounds={bounds} | ||
boundsOptions={{ padding: [100, 100], maxZoom: maxZoom }} | ||
zoom={zoom} | ||
center={[30, 0]} | ||
> | ||
{tileLayer} | ||
{markers} | ||
</Map> | ||
<MarkerClusterGroup>{markers}</MarkerClusterGroup> | ||
</MapContainer> | ||
</div> | ||
) | ||
} | ||
|
||
else if (location) { | ||
markers = [ | ||
<Marker | ||
key='marker' | ||
position={location}> | ||
</Marker> | ||
] | ||
} else if (location) { | ||
markers = [<Marker key="marker" position={location}></Marker>] | ||
|
||
return ( | ||
<div className="Map"> | ||
<Map center={location} zoom={zoom} zoomControl={true}> | ||
<MapContainer center={location} zoom={zoom} zoomControl={true}> | ||
{tileLayer} | ||
{markers} | ||
</Map> | ||
<MarkerClusterGroup>{markers}</MarkerClusterGroup> | ||
</MapContainer> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
MapView.propTypes = { | ||
photos: PropTypes.string, | ||
bounds: PropTypes.func, | ||
location: PropTypes.array, | ||
zoom: PropTypes.number, | ||
maxZoom: PropTypes.number, | ||
hideAttribution: PropTypes.bool, | ||
} | ||
|
||
MapView.defaultProps = { | ||
zoom: 2, | ||
maxZoom: 15, | ||
} | ||
|
||
export default MapView |
Oops, something went wrong.