Merge pull request #46 from alDuncanson/feature/custom-icons

Feature/custom icons
This commit is contained in:
Alex Duncanson 2018-11-05 09:27:41 -05:00 committed by GitHub
commit a753bcfb0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 47 additions and 1 deletions

BIN
public/mapicons/cage.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
public/mapicons/paws.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

View File

@ -207,8 +207,44 @@ export class MapContainer extends Component {
} }
} }
/**
* Determines marker icon based on the
* sighting type.
*/
sightingIcon = (type) => {
let pinIcon;
switch(type) {
case 'visual':
pinIcon = '/mapicons/marten-icon.png';
break;
case 'roadkill':
pinIcon = '/mapicons/tire-icon.png';
break;
case 'viewed_tracks':
pinIcon = '/mapicons/paws.png';
break;
case 'trapped':
pinIcon = '/mapicons/cage.png';
break;
case 'photo':
pinIcon = '/mapicons/photo-icon.png';
break;
case 'other':
pinIcon = '/mapicons/other-icon.png';
break;
default:
break;
}
return pinIcon;
}
/**
* Formats date using Moment.js.
*/
formatDate = date => { formatDate = date => {
return (moment(date, "YYYY-MM").format("MMMM YYYY").toString()); return (moment(date, "YYYY-MM").format("MMMM YYYY").toString())
} }
// Set the state of the component to contain user coordinates and initial // Set the state of the component to contain user coordinates and initial
@ -225,6 +261,8 @@ export class MapContainer extends Component {
}; };
render() { render() {
const {google} = this.props;
return ( return (
// Render the Google Map, Marker, and InfoWindow components // Render the Google Map, Marker, and InfoWindow components
<div className="sighting-google-map-container"> <div className="sighting-google-map-container">
@ -244,6 +282,9 @@ export class MapContainer extends Component {
/> />
{this.state.sightings.map((sighting) => { {this.state.sightings.map((sighting) => {
let pinIcon = this.sightingIcon(sighting.type)
return ( return (
<Marker <Marker
key={sighting.id} key={sighting.id}
@ -254,6 +295,11 @@ export class MapContainer extends Component {
time={<Fragment><b>Time:</b> {this.getTime(sighting.time)}</Fragment>} time={<Fragment><b>Time:</b> {this.getTime(sighting.time)}</Fragment>}
confidence={<Fragment><b>I am confident of my sighting:</b> {this.getConfidence(sighting.confidence)}</Fragment>} confidence={<Fragment><b>I am confident of my sighting:</b> {this.getConfidence(sighting.confidence)}</Fragment>}
description={<Fragment><b>Description:</b> {sighting.desc}</Fragment>} description={<Fragment><b>Description:</b> {sighting.desc}</Fragment>}
icon={{
url: pinIcon,
anchor: new google.maps.Point(32,32),
scaledSize: new google.maps.Size(32,32)
}}
/> />
) )
})} })}