单击地图外部的链接时,如何使焦点对准地图标记? [英] How to get focus to map marker when click on a link outside the map?

查看:126
本文介绍了单击地图外部的链接时,如何使焦点对准地图标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个带有mapquest传单的地图,该地图上显示的标记很少,并且有一些弹出消息.但是,一切正常,但是在地图下面,我有一张桌子在显示酒店号码.这样的链接:

So, I have a map with the mapquest leaflet which showing few markers on it and have some popup messages. However, everything working well but underneath of the map I have one table where I am showing hotel number. so like this with link:

<a href='#Hotel22'>Hotel 22</a><a href='#Hotel23'>Hotel 23</a><a href='#Hotel24'>Hotel 24</a>

因此,当任何用户单击#Hotel22时,它将把焦点对准地图的特殊标记并打开标记窗口.这样用户就会知道22号酒店就在地图上...

So, when any user click on #Hotel22 then it will direct take focus to map's particulare marker and open up the marker window. So that user will know that the Hotel 22 is here on map...

如果有人知道这一点,那么我的地图是在传单中创建的,但使用mapquest传单api方式创建.由于项目的原因,我无法在此处复制/粘贴一些复杂的代码....

If any one know this so My map is created in leaflet but with mapquest leaflet api way. As because of project I cann't copy/paste some of the complex code here....

感谢我的朋友们.:)

推荐答案

基本上,您必须维护标记的关联数组.

You basically have to maintain an associative array of your markers.

<a href="#" onclick="focusOn('paris')">Paris</a>

// javascript
var markers = {};
markers["paris"] = L.marker([48.85749, 2.35107]).addTo(mymap)
.bindPopup("<b>Hello world!</b><br />I am Paris.");

function focusOn(city) {
   markers[city].openPopup();
}

请参见示例

这篇关于单击地图外部的链接时,如何使焦点对准地图标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆