OpenLayers (OSM) 中触发功能弹出窗口的正确方法是什么?
我有功能 ID,我可以抓取 GeoRSS 负载端上的标记层,但我仍然不确定如何使弹出窗口以编程方式出现。
如果有必要,我将根据需要创建弹出窗口,但似乎我应该能够获取地图上绘制的标记的 id 并调用一些事件。我尝试使用 jQuery 并在地图元素上调用 $(marker-id).click()
事件,但这似乎不起作用。我缺少什么?
由于我被要求提供代码,而且我认为它是样板文件,所以到目前为止我的情况如下:
map = new OpenLayers.Map('myMap');
map.addLayer(new OpenLayers.Layer.OSM());
map.addLayer(new OpenLayers.Layer.GeoRSS(name,url));
//I've done some stuff as well in re: projections and centering and
//setting extents, but those really don't pertain to this question.
在其他地方,我做了一些 jQuery 模板,并为我构建了地图上显示的所有点的漂亮列表。我知道如何从图层 loadend
执行回调并获取图层对象,我知道如何手动从地图中检索图层,我知道如何迭代图层集合并找到我的图层。因此,我可以获取有关弹出窗口的任何详细信息,但我仍然不知道如何使用 DOM 或此 API 的内置方法来使其像 element.click() 一样简单
这是我更愿意做的。
I have the feature ID, I can grab the marker layer on GeoRSS loadend, but I'm still not sure how to cause the popup to appear programmatically.
I'll create the popup on demand if that's necessary, but it seems as though I should be able to get the id of the marker as drawn on the map and call some event on that. I've tried using jQuery and calling the $(marker-id).click()
event on the map elements, but that doesn't seem to be working. What am I missing?
Since I was asked for code, and since I presumed it to be boilerplate, here's where I am so far:
map = new OpenLayers.Map('myMap');
map.addLayer(new OpenLayers.Layer.OSM());
map.addLayer(new OpenLayers.Layer.GeoRSS(name,url));
//I've done some stuff as well in re: projections and centering and
//setting extents, but those really don't pertain to this question.
Elsewhere I've done a bit of jQuery templating and built me a nice list of all the points that are being shown on the map. I know how to do a callback from the layer loadend
and get the layer object, I know how to retrieve my layer out of the map manually, I know how to iter over the layers collection and find my layer. So I can grab any of those details about the popup, but I still don't know how to go about using the built-in methods of the DOM or of this API to make it as easy as element.click()
which is what I would prefer to do.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不必单击该功能即可打开弹出窗口。
首先,您需要从功能 ID 中引用该功能。我将在 GeoRSS 图层的 loadend 事件中使用图层上的 markers 属性来执行此操作。
假设您引用了您的功能,我会编写一个处理自动弹出窗口的方法:
You don't have to click the feature to open a popup.
First you need a reference to the feature from the feature id. I would do that in the
loadend
event of the GeoRSS layer, using themarkers
property on the layer.Assuming you have a reference to your feature, I would write a method which handles the automatic popup:
fwiw我终于回到了这个并做了一些完全不同的事情,但他的答案是一个很好的答案。
另请注意,我将
map
保留为全局变量,这样我就不必每次想使用它时都重新获取它fwiw I finally came back to this and did something entirely different, but his answer was a good one.
also note that I keep
map
as a global so I don't have to reacquire it everytime I want to use it