OpenLayers event.register未注册 [英] OpenLayers event.register not registering

查看:263
本文介绍了OpenLayers event.register未注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我是OpenLayers的菜鸟.我的问题是这个...

Ok I am a noob to OpenLayers. The problem that I have is this...

在我的JavaScript中,初始化地图,添加基本OSM图层并居中之后,我的代码对要添加到地图的标记进行ajax查找,所有标记均在组中,因此它为每个组,然后将标记添加到组图层.但是,在将标记添加到图层之前,它会使用简单的警报功能对mousedown进行事件注册.

In my javascript, after initializing the map, adding the base OSM layer and centering, my code does an ajax lookup of points for the markers to add to the map, all markers are in groups, so it creates a new layer for every group and adds the markers to the group layer. But, before adding the marker to the layer it does an event register of mousedown with a simple alert function.

这里的问题是,当我单击标记时,光标会变成一只手,就像它认为我要拖动地图一样.就像在顶层阻止了点击一样.我尝试了控制台日志记录而不是警报,只是为了确保但它实际上从未触发事件单击.很难显示出完整的代码图的代码示例,但这是一个代码段:

The problem here is that when I go to click on a marker, the cursor just turns to a hand like it thinks I want to drag the map. It's like there's some other layer on top that's preventing the click. I tried console logging instead of the alert just to make sure but it never actually triggers the event click. It's hard to do a code sample that will display the full picture of the code, but here's a snippet:

function createMarker(lat, lon) {
    var icon = new OpenLayers.Icon('/mapicon/icon-b.png', new OpenLayers.Size(12, 20), new OpenLayers.Pixel(-6, -10)); // this is a custom image
    lonlat = new OpenLayers.LonLat(lon, lat);
    var marker = new OpenLayers.Marker(lonlat, icon.clone());
    return marker;
}

marker = createMarker(lat,lon,'Example Title');
marker.events.register('mousedown', pin, function(evt) { alert('help!'); OpenLayers.Event.stop(evt); });

我撞墙了,如果我不秃头,我会把头发拔掉.有人有什么想法吗?

I am hitting a wall and if I weren't bald, I'd be pulling my hair out. Anyone have any ideas?

推荐答案

感谢所有帮助.问题是(并且OL文档很糟糕,所以它在任何地方都没有提到),这与创建图层的顺序有关.在我的代码中,我遍历了一系列的层名称,并为每个名称创建了一个标记层和一个矢量层.我尝试过先创建标记层,然后再创建矢量层的方法,它具有相同的单击残废效果.因此,我尝试遍历一次以首先创建所有矢量层.再次循环遍历并创建标记层,并且工作正常.

Thanks for the help all. The problem is (and the OL documentation is HORRIBLY pathetic so it doesn't state this anywhere) that it has to do with the order in which you create the layers. In my code, I loop through an array of layer names and I was creating a marker layer and a vector layer for each name. I tried it with creating the marker layer first and then creating the vector layer first and it had the same click crippling effect. So I tried looping through once to create all of the vector layers first. The loop through again and create the marker layers and that worked.

OL是一个很棒的映射系统.他们如此糟糕的文档真是可惜.样本几乎没有用.如果OL是由社区推动的,为什么没有OL论坛?我必须来这里是因为这似乎是OL用户进行任何类型发布的唯一位置.

OL is a great mapping system. It's just a shame that they have such poor documentation. The samples are nearly useless. If OL is such a community driven thing, why is there no OL forums? I had to come here because it seems to be the only place where OL users do any kind of posting.

这篇关于OpenLayers event.register未注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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