简体   繁体   English

如何通过单击标记来隐藏标记并缩放指定的地图位置?

[英]How to hide the marker and zoom on a specified map location by clicking on the marker?

I have a project to finish, and I have 1 month to finish it, I am very late… I have tried to do what I want to have, but it never worked, I am a beginner in Javascript… Here is what I would like to have in order to continue my project. 我有一个完成的项目,我有一个月的时间来完成它,我已经很晚了...我试图做我想要的东西,但它从未奏效,我是Javascript的初学者......这就是我想要的为了继续我的项目。 Sorry in advance for my English… 提前抱歉我的英文...

I would like that, when I click on a country, markers appears (It works), but I would also like that when I click on a marker, this one disappear and zoom on a specified location (the river, to be precise). 我想,当我点击一个国家时,会出现标记(它有效),但我也希望当我点击一个标记时,这个标记会消失并放大指定位置(确切地说是河流)。 And I also wanted that marker's popup are shown on mouseover but I didn't succeed. 而且我也想在鼠标悬停时显示标记的弹出窗口,但我没有成功。

I don't know all the possibilities of javascript. 我不知道javascript的所有可能性。 But is it possible to see these things if I zoom out ? 但如果我缩小,有可能看到这些东西吗? (for example : I see the river, I zoom out to the country level and markers appears) (例如:我看到河流,我缩小到国家级别并显示标记)

A help would considerably help me in my project and hopefully allow me to finish in time. 帮助对我的项目有很大的帮助,希望能让我及时完成。

Thank you for your attention, 感谢您的关注,

Here is the link of my full code that works till before my last changes : https://jsfiddle.net/Gio687351/cj9bvrg7/1/ 这是我的完整代码的链接,直到我上次更改之前一直工作: https//jsfiddle.net/Gio687351/cj9bvrg7/1/

Here is one of the codes that I have tested : 这是我测试过的代码之一:

 function toggleLayerVisibility(map, selectedLayer) { if (selectedLayerId && selectedLayerId !== selectedLayer._leaflet_id) { map.eachLayer(layer => { if (layer._leaflet_id === selectedLayerId) geojson.resetStyle(layer); }); } selectedLayer.setStyle({ opacity: 0, fillOpacity: 0.0 }); selectedLayerId = selectedLayer._leaflet_id; //save identifier of a selected layer map.on('zoomend', function() { if (map.getZoom() < 8 && map.getZoom() > 6){ map.removemarker; } else { map.on('zoomend', { marker.on('mouseover', function(e) { L.marker([52.7472, -8.5087]).bindPopup('Limerick, Shannon River').addTo(map); L.marker([53.34565, -6.32105]).bindPopup('Dublin, River Liffey').addTo(map); L.marker([47.88363, 7.22444]).bindPopup('Soultz-Haut-Rhin, Le Rimbach').addTo(map); } }); } }); 

我找到了解决方案: 在此处输入图像说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM