Auto open markers popup on react-leaflet map

2019-07-10 16:19发布

I use some markers on react-leaflet map to show various text.
But I can not find a flag for the autoOpen tooltip.

I get (position, children, onOpen, onClose) as available attributes.

render() {
    return (
        <div className={'ShapeLayer'}>
            {
                this.shapes.map(shape => {
                    return (
                        <Marker key={shape['id']} position={shape['coordinates']} draggable={false} opacity={1}>
                            <Popup>
                                <span>{shape['text']}</span>
                            </Popup>
                        </Marker>
                    );

                })
            }
        </div>
    )
}

This is done with this code on native leaflet

var marker = L.marker(shapess[i]['coordinates'], {
        opacity: 0.01
    }).bindTooltip(shapess[i]['text'],
        {
            permanent: true,
            className: "shapesText" + i,
            offset: [0, 0],
            direction: "center"
        }
    ).openTooltip().addTo(mymap);

How can I do the same on react_leflet

1条回答
祖国的老花朵
2楼-- · 2019-07-10 16:49

You can use Tooltip instead of a Popup if it's just for text and then use permanent attribute on the Tooltip.

 <Marker key={shape['id']} position={shape['coordinates']} draggable={false} opacity={1}>
    <Tooltip permanent>
          <span>{shape['text']}</span>
    </Tooltip>
</Marker>

Here is the source for more examples :

react-leaflet/example/components/tooltip.js

查看更多
登录 后发表回答