Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arbitrary function on react-leaflet marker click

React-leaflet nicely provides the ability to put content within a Popup of a Marker.

For instance in my example:

            <Marker position={[item.lat, item.lng]} key={item.machineid}>
              <Popup maxWidth={720}>
                <ItemGrid machineid={item.machineid}
                          username={this.props.username}/>
              </Popup>
            </Marker>

However if this content is too big, it can be unwieldly, especially on mobile. I would like to have a (bootstrap) Modal interface activate on the click of the Marker. Is there way to do that in react-leaflet?

like image 677
notconfusing Avatar asked Dec 01 '16 02:12

notconfusing


1 Answers

Update: Evented behavior#

Use the eventHandlers listener function inside the Marker component:

<Marker
  position={[50.5, 30.5]}
  eventHandlers={{
    click: (e) => {
      console.log('marker clicked', e)
    },
  }}
/>
like image 118
Selmi Karim Avatar answered Oct 16 '22 04:10

Selmi Karim