Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Leaflet: Show popup on mouseover

Has anyone been able to use the React Leaflet Popup element to show a popup on mouseover rather than on click?

I can't seem to find a way to achieve this.

like image 505
Nick Barrett Avatar asked Oct 17 '25 06:10

Nick Barrett


1 Answers

I've recently solved this problem using React Refs and the Leaflet API.

A barebones example:

import React, { Component } from 'react';

import { Circle } from 'react-leaflet';

class Foo extends Component {
    render() {
        const { center, radius } = this.props;
        return (
            <Circle
              ref={circle => { this.circle = circle; }}
              center={center}
              radius={radius}
              onMouseOver={() => {
                  this.circle.leafletElement.bindPopup('foo').openPopup();
              }}/>
        );
    }
}

export default Foo;
like image 169
dpassen Avatar answered Oct 22 '25 01:10

dpassen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!