dictionary - 传单:如何在鼠标悬停在该标记上时仅突出显示位于标记后面的多边形?
问题描述
通过在 php 上循环,我生成了一些多边形和标记。现在我想突出显示位于鼠标悬停标记后面的一个多边形。但是下面的代码总是突出显示相同的多边形。无论鼠标悬停哪个标记,它始终突出显示相同的多边形。我认为问题在于它总是需要循环的最后一个多边形。我怎样才能使鼠标悬停的标记突出显示它后面的多边形?提前非常感谢..
<?PHP
for ($i=0;$i<=count($station);$i++) {
?>
var polygon = new L.Polygon(line, {
color: pastel,
weight: 0.4,
opacity: 0.1,
fillColor: pastel,
fillOpacity: 0.05,
interactive: true
});
polygon.addTo(map);
var myIcon = L.divIcon({
className: 'divIcon',
iconSize: new L.Point(35, 15),
iconAnchor:[18, 20],
zIndexOffset: 1000,
html: '<?=$desc1[$i]?>'
});
var marker = L.marker([x1, y1], {icon: myIcon})
.addTo(map)
.bindTooltip('<?=$desc[$i]?>');
marker.on('mouseover', function() {
polygon.setStyle({
fillOpacity: 0.5
});
});
marker.on('mouseout', function() {
polygon.setStyle({
fillOpacity: 0.05
});
});
<?PHP
}
?>
解决方案
像这样引用标记上的多边形:
var polygon = new L.Polygon(line, {
color: pastel,
weight: 0.4,
opacity: 0.1,
fillColor: pastel,
fillOpacity: 0.05,
interactive: true
});
polygon.addTo(map);
var myIcon = L.divIcon({
className: 'divIcon',
iconSize: new L.Point(35, 15),
iconAnchor:[18, 20],
zIndexOffset: 1000,
html: '<?=$desc1[$i]?>'
});
var marker = L.marker([x1, y1], {icon: myIcon})
.addTo(map)
.bindTooltip('<?=$desc[$i]?>');
marker.refPoly = polygon;
marker.on('mouseover', function(e) {
e.target.refPoly.setStyle({
fillOpacity: 0.5
});
});
marker.on('mouseout', function(e) {
e.target.refPoly.setStyle({
fillOpacity: 0.05
});
});
推荐阅读
- javascript - React Native FlatList 不在 flexbox UI 中滚动
- sql-server-2019 - Base64 SQL 默认值,错误验证
- c# - Visual Studio 调试并获取 DNS 错误 INET_E_RESOURCE_NOT_FOUND
- python-3.x - Tkinter 的跟踪函数总是触发
- nlp - 我们可以使用句子转换器来嵌入没有标签的非英语句子吗?
- javascript - ReactJs useState 钩子进入无限循环
- firebase - 将 firebase 子集合中的数据提取到 React Native 中的 list.item 中
- sql - 从 SQL Server 中的字符串中查找最大值
- javascript - 从 TinyURL 的缩短方法捕获响应时出错
- excel - 用于生成数据驱动报告并发送给外部用户的工具