custom marker is not shown react-leaflet

2.2k views Asked by At

I have used react-leaflet for showing the map. Also i have used leaflet-routing-machine for routing. The routing is shown correctly but the marker is not overriden by car icon. I tried on both routing and react-leaflet for overriding marker using divIcon but no success yet.

Here is my code

class CarRouting extends MapLayer {
  componentWillMount() {
    super.componentWillMount();
    const { map, from, to, position, ...props } = this.props;
    props.icon = L.divIcon({
        className: 'my-div-icon',
    });
    this.leafletElement =
  L.Routing.control({
  position: 'topleft',
  waypoints: [
    L.latLng(from[0], from[1]),
    L.latLng(to[0], to[1]),
  ],
}).addTo(map);
const source = L.marker([from[0], from[1]], props);
const destination = L.marker([to[0], to[1]], props);
const cities = L.layerGroup([source, destination]);
  }

  render() {
    return null;
  }
}

export default CarRouting;

car-result.js

  const icon = divIcon({
    className: 'my-div-icon',
    iconSize: [30, 30]
  });

  return (
    <Map center={position} zoom={5} style={{ height: 600 }}>
      <TileLayer
        url='https://mt{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}'
        subdomains='0123'
      />
      <Marker position={position} icon={icon} />
      <CarRouting from={[cityOrigenLat, cityOrigenLng]} to={[cityDestinoLat, cityDestinoLng]} />
    </Map>
  );
};

main.css

.my-div-icon {
  background: url('../../../public/assets/img/icons/shared_car.png');
  background-size: contain;
  background-repeat: no-repeat;
  width: 25px;
  height: 25px;
}

Did i miss anything?

UPDATE

The routing also gets broken now and still the marker is not overriden with car image.

enter image description here

0

There are 0 answers