在单击其他地方时,如何简单地更改单击标记图标,然后返回原始状态?
我正在尝试在我的自定义地图上获取此功能 https://rodadagua.netlify.app/
've在这里找到了一些非常紧密的例子和问题,但不幸的是,我不知道自己在做什么。
这本质上是相同的问题更改(并在单击时更改)传单图标但是,有了这样的基本知识,我无法解决。我还发现了这个问题传单映射:单击“单击更改所有颜色的颜色”标记和示例
我想在单击时更改标记图标(以显示不同的彩色版本),然后在单击其他地方(例如,EG)时返回原始状态(原始图标/颜色)。关闭关联的弹出窗口或单击地图或单击另一个标记。
我要去的壁橱是我可以点击更改图标,但我想将其更改。
var defaultIcon = L.icon({
iconUrl: 'scripts/leaflet/images/marker-icon.png',
shadowUrl: 'scripts/leaflet/images/marker-shadow.png',
});
var brownIcon = L.icon({
iconUrl: 'scripts/leaflet/images/marker-icon-brown.png',
shadowUrl: 'scripts/leaflet/images/marker-shadow.png',
});
var testmarker = L.marker([0.0, 0.0], {icon: defaultIcon}).addTo(map);
testmarker.on('click', function(e) {
testmarker.setIcon(brownIcon);
});
我正在使用基本的传单脚本来定义地图等。然后,我的所有标记和弹出窗口都像此示例一样设置:
var marker_Waldemar = L.marker([15.0, -40.0]).addTo(map);
marker_Waldemar.bindPopup('<h3>EMEF Prof. Waldemar Rodrigues</h3><p><iframe src="https://galeriafeira.netlify.app/" width="500" height="354" style="border:none;"></iframe></p><p><b>Feira de Ciências</b></p>', {
maxWidth : 520,
maxHeight : 450,
});
我想确切地知道我需要放置什么代码以及在哪里。
I'm trying to get this function on my custom map https://rodadagua.netlify.app/
I've found some very close examples and questions on here but being a complete novice unfortunately I have no idea what I´m doing.
This is essentially the same question Change (and change back) leaflet icon on click but with such basic knowledge I can't work it out. Also I found this question Leaflet map: on click changing color of all markers and example https://jsfiddle.net/vz7jmnqs/2/ is essentially what I'm after but again I can't work out how to include it in my code and make it work.
I want to change marker icon when clicked (so that it shows a different coloured version) and then return back to original state (original icon/colour) when click elsewhere, anywhere, eg. close the associated popup or click on the map or click on another marker.
The closet I've got to is I can change the icon on a click, but I want to change it back.
var defaultIcon = L.icon({
iconUrl: 'scripts/leaflet/images/marker-icon.png',
shadowUrl: 'scripts/leaflet/images/marker-shadow.png',
});
var brownIcon = L.icon({
iconUrl: 'scripts/leaflet/images/marker-icon-brown.png',
shadowUrl: 'scripts/leaflet/images/marker-shadow.png',
});
var testmarker = L.marker([0.0, 0.0], {icon: defaultIcon}).addTo(map);
testmarker.on('click', function(e) {
testmarker.setIcon(brownIcon);
});
I'm using the basic Leaflet script to define the map etc. then all of my markers and popups are set up like this example:
var marker_Waldemar = L.marker([15.0, -40.0]).addTo(map);
marker_Waldemar.bindPopup('<h3>EMEF Prof. Waldemar Rodrigues</h3><p><iframe src="https://galeriafeira.netlify.app/" width="500" height="354" style="border:none;"></iframe></p><p><b>Feira de Ciências</b></p>', {
maxWidth : 520,
maxHeight : 450,
});
I would like to know exactly what code I need to put in and where.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它将完成工作!
It will do the job!