I have two OpenLayers.Layer.Vector, one with OpenLayers.Control.SelectFeature and the other without SelectFeature.
When I try to change the z-index the layers aren't shown properly because the RootContainer created by SelectFeature is always on top. I also changed the order of the layers into the stack but this didn't work.
Is there another way to control this without adding both layers into the SelectFeature control?
Here is a simulation:
<!DOCTYPE html>
<html>
<head>
<style>
.smallmap {
width: 512px;
height: 256px;
border: 1px solid #ccc;
}
</style>
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, controls;
OpenLayers.Feature.Vector.style['default']['strokeWidth'] = '2';
function init(){
map = new OpenLayers.Map('map');
var ol_wms = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0",
{layers: 'basic',
isBaseLayer: true,}
);
map.addLayers([ol_wms]);
var vectors1 = new OpenLayers.Layer.Vector("vector1");
map.addLayers([vectors1]);
var feature = new OpenLayers.Feature.Vector(
OpenLayers.Geometry.fromWKT(
"POLYGON((28.828125 0.3515625, 132.1875 -13.0078125, -1.40625 -59.4140625, 28.828125 0.3515625))"
),
{},
{
fillColor:"#00f"
}
);
vectors1.addFeatures([feature]);
var vectors2 = new OpenLayers.Layer.Vector("vector2");
map.addLayers([vectors2]);
var feature2 = new OpenLayers.Feature.Vector(
OpenLayers.Geometry.fromWKT(
"POLYGON((-120.828125 -50.3515625, -80.1875 -80.0078125, 50.40625 0.4140625, -120.828125 -50.3515625))"
),
{},
{
fillColor:"#0f0"
}
);
vectors2.addFeatures([feature2]);
var report = function(e) {
OpenLayers.Console.log(e.type, e.feature.id);
};
var highlightCtrl = new OpenLayers.Control.SelectFeature([vectors1], {
hover: true,
highlightOnly: true,
renderIntent: "temporary",
eventListeners: {
beforefeaturehighlighted: report,
featurehighlighted: function(e) {console.log("highlight")},
featureunhighlighted: function(e) {console.log("unhighlight")}
}
});
var selectCtrl = new OpenLayers.Control.SelectFeature([vectors1],
{clickout: true,
onSelect: function(e) {
console.log(" select ");
},
onUnselect: function(e) {console.log(" unselect ")}
}
);
map.addControl(highlightCtrl);
map.addControl(selectCtrl);
highlightCtrl.activate();
selectCtrl.activate();
map.setCenter(new OpenLayers.LonLat(0, 0), 1);
map.setLayerZIndex(vectors2, 0);
map.setLayerZIndex(vectors1, -1);
}
</script>
</head>
<body onload="init()">
<div id="map" class="smallmap"></div>
</body>
</html>
When you change the order with
map.setLayerZIndex(vectors2, 0);
map.setLayerZIndex(vectors1, -1);
never works because
var selectCtrl = new OpenLayers.Control.SelectFeature([vectors1],
do that the Features will be created into RootContainer at Z-index 725.
So I don't know how to keep into the map different vector layers. Some layers with over and click functionality and another without over or click handlers and be able to order properly the layers.
Thanks & regards, Rafael.