简体   繁体   English

Openlayers 2. z轴和选择控制

[英]Openlayers 2. z-axis and select control

I've got a couple vector layers one has polygons, one has lines. 我有几个矢量图层,一个有多边形,一个有线条。 We have a need to add lines to the line layer that attach to the polygons (database procedure requires the polygons IDs, which are stored in attributes on the polygons) 我们需要在连接到多边形的线图层上添加线条(数据库过程需要多边形ID,这些ID存储在多边形的属性中)

So I have a drawFeature control on the lineLayer, and a selectFeature (which stores off the ID on hover rather than just selecting) on the polygonLayer. 所以我在lineLayer上有一个drawFeature控件,在polygonLayer上有一个selectFeature(在悬停时存储ID而不是只选择)。 It actually works just fine except the z axis of the linelayer while added is lower, so it shows the new line being drawn under the polygon. 它实际上工作得很好,除了添加时线层的z轴较低,因此它显示了在多边形下方绘制的新线。 Would rather have the line show over the polygon. 宁愿在多边形上显示线。 I know it's because when the selectFeature control is active it's setting the z-index of the polygon layer higher than the lineLayer. 我知道这是因为当selectFeature控件处于活动状态时,它将多边形图层的z索引设置为比lineLayer高。 I manually set the z-index of the linelayer higher than the polygon layer using lineLayer.setZIndex(800) or whatever, and that certainly makes the new line draw over the polygons, but then the selectFeature events don't trigger. 我使用lineLayer.setZIndex(800)或其他方法手动将线层的z-index设置为高于多边形层,这肯定会使新线绘制在多边形上,但是selectFeature事件不会触发。 I've considered several solutions including adding the drawFeature to my polygon layer and then moving the feature to the line layer when done, but it's still rendering under the polygons, I even played with the graphicZIndex on the "temporary" style for my stylemap on the polygon layer. 我考虑了几种解决方案,包括将drawFeature添加到多边形层,然后在完成后将其移动到线层,但是它仍在多边形下渲染,我什至在我的样式图上使用了“临时”样式的graphicZIndex多边形层。 to no avail (i did set the renderOptions zindexing to true on the polygon layer) 没有用(我确实在多边形图层上将renderOptions zindexing设置为true)

I may be approaching this from the wrong angle, so I'm open to suggestions. 我可能从错误的角度接近这个,所以我愿意接受建议。 If there was a function available on the vector layer something like getFeatureByPosition(position), I could grab the position on sketchStarted, and sketchEnded events and query that, but so far I've been unable to find anything like that. 如果矢量层上有可用的函数,例如getFeatureByPosition(position),我可以在sketchStarted和sketchEnded事件上获取位置并进行查询,但是到目前为止,我一直找不到这样的东西。

I'm not on my dev box at the moment in case anyone is wondering why no code. 我现在不在我的开发盒上,万一有人想知道为什么没有代码。 Wanted to post this from work, but the base network is having issues displaying the logon page (due to ssl I think) 希望从工作中发布此信息,但基本网络在显示登录页面时出现问题(由于我认为是ssl)

So my solution required a few things. 所以我的解决方案需要一些东西。 First I needed to upgrade from OL 2.10 to the latest 2.13.1. 首先,我需要从OL 2.10升级到最新的2.13.1。 Mostly this was due to needing a new event that was added to 2.11 (I think or maybe 2.12) the event is "featureover" which can be caught at the map level and therefore will trigger on all layers, so I'm not fighting with Z-Index of the select. 大多数情况下,这是因为需要一个新的事件被添加到2.11(我认为或者可能是2.12),事件是“featureover”,可以在地图级别捕获,因此将触发所有图层,所以我不打算与Z-Index的选择。 I removed the select control from the polygon layer as it was not needed. 我从多边形图层中删除了选择控件,因为它不需要。

var featureOverHandler = function(event){
    if (event.feature.layer.id == polygonLayer.id) {
        selectedPolygonId = event.feature.attributes.POLYGON_ID;
        console.log("Selected Polygon Id: " + selectedPolygonId);
        map.events.unregister('featureover',map,featureOverHandler);
        map.events.register('featureout',map,featureOutHandler);
    }
};
var featureOutHandler = function (event) {
    if (event.feature.layer.id == polygonLayer.id) {
        selectedPolygonId = 0;
        console.log("Cleared Selected Polygon ID ");
        map.events.unregister('featureout', map, featureOutHandler);
        map.events.register('featureover', map, featureOverHandler);
    }
};

These will catch the polygon that is currently hovered over. 这些将捕获当前悬停的多边形。 But then I add events to catch where the line starts and ends. 但是随后我添加了事件以捕获行的开始和结束位置。 Since as of 2.11, they changed the way the "sketchstarted" event works, you can non longer use that to capture which polygon the pointer was over when the first point was added. 由于从2.11开始,它们更改了“ sketchstarted”事件的工作方式,因此您不能再使用该事件来捕获添加第一个点时指针位于哪个多边形上。 I used the point callback on the vector layer. 我在矢量图层上使用了点回调。

var vDrawOptions = {
    callbacks: {
        "point": function (p) {
            if (p.parent.components.length == 2) {
                console.log("First Point added");
                startingPolygonId = selectedPolygonId;
            }
        }
    }
}
vectorAddControl = new OpenLayers.Control.DrawFeature(vectorLayer, OpenLayers.Handler.Path,vDrawOptions);

however, the "skecthcomplete" can still be used to capture the ending point (and thus polygon) 但是,“ skecthcomplete”仍然可以用于捕获终点(因此可以捕获多边形)

function vSketchComplete(evt) {
    endingPolygonId = selectedPolygonId;
};
vectorLayer.events.register('sketchcomplete', vectorLayer, vSketchComplete);

Hopefully this will help someone else, in a similar situation. 希望这会在类似情况下帮助其他人。

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

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