[OpenLayers-Users] How to use more than one 'SelectFeature' controls
hz20040
hz20040 at 126.com
Mon Jun 16 23:34:25 EDT 2008
Dear List!
I have got a problem about 'SelectFeature' control.
There are two gml layers.I want to use two 'SelectFeature' to select them.
But I found only the SelectFeature control which's gml layer is added last
will work.
In the code,if I use myMap.addLayers([gmlLayer1,gmlLayer2]),the gml2Control will
work well,but gml1Control will not work. If I use myMap.addLayers([gmlLayer2,gmlLayer1]), the gml1Control will work well,but gml2 not.
It looks like which gml layer is added last , the select control to it will work.
Can I use more then one 'SelectFeature' controls to more then one gml layers?
Thank you !
My code is:
function init()
{
myMap = new OpenLayers.Map('map3d');
var opt= {numZoomLevels:1};
var graphic = new OpenLayers.Layer.Image(
'name',
'/Images/Maps/chunxi.jpg',
//new OpenLayers.Bounds(-450, -289, 450, 289),
new OpenLayers.Bounds(-320, -240, 320, 240),
new OpenLayers.Size(1600, 1200),
opt);
var userstyle = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['userselect']);
//add an image layer
myMap.addLayers([graphic]);
//one gml layer
var gmlOption = {
style:userstyle
};
var gmlLayer1= new OpenLayers.Layer.GML("GML1", "url",gmlOption);
//another gml layer
var toolTipsOption = {
//style:userstyle
};
var gmlLayer2 = new OpenLayers.Layer.GML("GML2","url",toolTipsOption);
myMap.addLayers([gmlLayer2,gmlLayer1]);
// myMap.addLayers([gmlLayer1,gmlLayer2]);
//one SelectFeature control:gml1Control
gml1Control = new OpenLayers.Control.SelectFeature(gmlLayer1,
{onSelect: onFeatureSelect,
onUnselect:onFeatureUnselect,
hover:false
});
myMap.addControl(gml1Control);
gml1Control.activate();
//another SelectFeature control:gml2Control
gml2Control = new OpenLayers.Control.SelectFeature(gmlLayer2,
{
onSelect:onToolTipsFeatureSelect,
onUnselect:onToolTipsFeatureUnselect,
hover:false
}
);
myMap.addControl(gml2Control );
gml2Control.activate();
myMap.setCenter(new OpenLayers.LonLat(0, 0), 1);
myMap.zoomToMaxExtent();
}
function onToolTipsFeatureSelect(feature)
{
alert("onToolTipsFeatureSelect");
}
function onToolTipsFeatureUnselect(feature)
{
alert("onToolTipsFeatureUnselect");
}
function onFeatureSelect(feature)
{
alert("onFeatureSelect");
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20080617/0779b7e0/attachment.html
More information about the Users
mailing list