I have a list, and through clicking on the list Elements, I want to open the pop up on the marker. Currently, the pop up only opens when the marker is clicked.
This is how I create the marker and the pop ups
import React from 'react';
import {
CircleMarker,
Popup,
} from 'react-leaflet';
class PointsLayer extends React.Component {
render() {
const { data } = this.props;
return (
data.map(point => {
return (
<CircleMarker
key={point.id}
center={point.coordinates}>
<Popup>
Fancy Pop Up
</Popup>
</CircleMarker>
)
})
)
}
and
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import {
Map,
} from 'react-leaflet';
import L from 'leaflet';
import PointsList from './PointsList;
import PointsLayer from './PointsLayer;
class Map extends React.Component {
componentDidMount() {
this.map = this.mapInstance.leafletElement;
}
render() {
const { data } = this.props;
return (
<>
<Map
ref={e => { this.mapInstance = e }}}>
<TileLayer
url=..." />
<PointsLayer
data={data} />
</Map>
<PointsList
data={data} />
</>
)
}
}
Each data point from data
is a marker on the <Map />
through the <PointsLayer />
component, and a listentry in <PointsList />
.
I want to open the pop up in <PointsLayer />
when the corrresponding entry in <PointsList />
is clicked.
How would I do that?