I have a list of layers drawn on the map with their geometry and other data. I want to change the style of those point whenever I click the name om the left. I have the event but I dont know how to change the style of already drawn layer.
This is the part of my code that I tried:
export const SearchItem = ({ data, map }) => {
const [isShown, setIsShown] = useState(false)
if (isShown) {
const format = new Format()
const feature = format.readFeature(data.geom, {
dataProjection: "EPSG:4326",
featureProjection: "EPSG:3857",
})
let vectorSource = new VectorSource({
features: [feature],
})
let vectorLayer = new VectorLayer({
source: vectorSource,
displayInLayerSwitcher: false,
style: new Style({
fill: new Stroke({
color: "#FF5733",
}),
stroke: new Stroke({
color: "#FF5733",
width: 5,
}),
}),
})
const select = new Select({
layers: [vectorLayer],
})
map.addInteraction(select)
}
return (
<div
onMouseEnter={() => setIsShown(true)}
onMouseLeave={() => setIsShown(false)}
className="product-item"
>
<div className="product-list-detail">
<h5 className="p-mb-2">{data.yurt_ad}</h5>
<i className="pi pi-phone product-category-icon"></i>
<span className="product-category">{data.telefon}</span>
<div className="search-item-address">
<i className="pi pi-map-marker product-category-icon"></i>
<span className="product-category">{data.adres}</span>
</div>
</div>
</div>
)
}
So this code is the part when clicked on the list on each name which will gives me the geometry of that layer. Since I have the Geometry of the clicked layer, it should be possible to change its style on the map.
Am I wrong?
feature.setStyle()
but doesnt work.feature
from?data.name
is shown on the list anddata.geom
is the geometry pf each data from the list