Please make sure to check the following boxes before submitting an issue. Thanks!
Icons Render
Create react app with latest leaflet.
Try rendering markers.
Example:
import React from 'react'
import { Map, TileLayer, Marker } from 'react-leaflet';
import lorama from './images/marker-icon.png'
export class MapComponent extends React.Component {
render() {
const markers = this.props.locations.map((e, index) => (
<Marker key={index} position={[e.lat, e.lng]} icon={lorama} />
));
console.log(markers)
const position = [51.0, -0.09]
return (
<div className="marginTopXS box MpH fourEighty">
<p className="subtitle">{this.props.title}</p>
<Map center={position} zoom={2}>
<TileLayer
url='http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png'
attribution='© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> © <a href="http://cartodb.com/attributions">CartoDB</a>'
subdomains='abcd'
maxZoom="19"
/>
{markers}
</Map>
<small className="date">As of {this.props.now}</small>
</div>
);
}
}
Please provide the simplest example possible to reproduce the issue, based on this WebpackBin.
Please refer to Leaflet's doc, Marker expects a Leaflet.Icon to be provided as icon, not a string.
@PaulLeCam Can you give an example? I looked at that and couldn't get it to work?
```
const image = {
iconUrl: require('../public/marker-icon.png'),
shadowUrl: require('../public/marker-shadow.png'),
iconSize: [38, 95], // size of the icon
shadowSize: [50, 64], // size of the shadow
iconAnchor: [22, 94], // point of the icon which will correspond to marker's location
shadowAnchor: [4, 62], // the same for the shadow
popupAnchor: [-3, -76]// point from which the popup should open relative to the iconAnchor
}
const markers = this.props.locations.map((e, index) => (
<Marker key={index} position={[e.lat, e.lng]} icon={image} />
));
```
As I wrote in my previous comment, you need to use Leaflet.icon, please refer to the docs.
i have a same problem and this my solution, thanks @PaulLeCam for insight
import Leaflet from 'leaflet'
const image = Leaflet.Icon({
iconUrl: require('../public/marker-icon.png'),
shadowUrl: require('../public/marker-shadow.png'),
iconSize: [38, 95], // size of the icon
shadowSize: [50, 64], // size of the shadow
iconAnchor: [22, 94], // point of the icon which will correspond to marker's location
shadowAnchor: [4, 62], // the same for the shadow
popupAnchor: [-3, -76]// point from which the popup should open relative to the iconAnchor
})
@evo3cx I had to use new Leaflet.Icon
new Leaflet.Icon
@joeferraro Thank you so much!!
Most helpful comment
@evo3cx I had to use
new Leaflet.Icon