[OpenLayers-Dev] feature event / highlight a feature

Christine Spietz spietz at fh-bingen.de
Fri Mar 30 12:04:34 EDT 2007


Hi Christopher,

I've looked at the link (thanks for hint), but I think that this
unfortunately can not solve my problem.

In the example is a vector-Layer and I'm able to paint polygons in the
Vector-layer and then select them.

But I do not only want to paint polygons, I want to paint "real" features
like:

<gml:featureMember>
<myFeature>
<gml:boundedBy>
<gml:Box srsName="epsg:31467">
<gml:coordinates>3408164.712000,5507840.904000
3408614.729000,5508072.195000</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<myGeometry>
<gml:MultiPolygon srsName="epsg:31467">
<gml:polygonMember>
<gml:Polygon>
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates>3408448.251000,5507873.652000 3408453.120000,5507855.352000
3408530.457000,5507875.125000 3408614.729000,5507917.478000
3408447.294000,5507873.301000 3408448.251000,5507873.652000
</gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
<gml:innerBoundaryIs>
<gml:LinearRing>
<gml:coordinates>3408423.685000,5507944.168000 3408410.433000,5507944.200000
3408361.516000,5507945.163000 3408316.234000,5507938.273000
3408311.640000,5507948.625000 3408307.446000,5507959.118000
3408315.911000,5507959.986000 3408362.976000,5507962.503000
3408414.480000,5507959.093000 3408423.685000,5507944.168000
</gml:coordinates>
</gml:LinearRing>
</gml:innerBoundaryIs>
</gml:Polygon>
</gml:polygonMember>
</gml:MultiPolygon>
</ms:myGeometry>
<myID>0026</myID>
</myFeature>
</gml:featureMember>

I can readout the coordinates of my features write them in a polygonfeature
and draw the polygons in the map in this way:

var pointList = [];
oModel = document.getElementById("myModel");
instance = oModel.getInstanceDocument("nameOfInstance");
linearRingArray=instance .getElementsByTagName("LinearRing");
if(linearRingArray.length>1){
    for (auja=0;auja<linearRingArray.length;auja++){
        if(linearRingArray[auja].childNodes.length>1){
            koord= linearRingArray[auja].childNodes[1].firstChild.nodeValue;
            koords= koord.split(" ");
            if(koords.length>1){
                for(aufein=0;aufein<koords.length;aufein++){
                    finalKoord= koords[aufein] ;
                    finalKoordFeld= finalKoord.split(",");
                    if (finalKoordFeld.length==2){
                        newPoint = new 
OpenLayers.Geometry.Point(finalKoordFeld[0],finalKoordFeld[1]);
                        pointList.push(newPoint);
                    }
                }
            }
        }
        linearRing = new OpenLayers.Geometry.LinearRing(pointList);
        polygonFeature = new OpenLayers.Feature.Vector(new 
OpenLayers.Geometry.Polygon([linearRing]));
        polygonLayer.addFeatures([polygonFeature]);
        pointList= [];
    }
}
drawControls = {
    select: new OpenLayers.Control.SelectFeature(polygonLayer),
    hover: new OpenLayers.Control.SelectFeature(polygonLayer,{hover: true})
};
for(key in drawControls) {
    map.addControl(drawControls[key]);
    var control = drawControls[key];
    control.activate();
}

BUT:

I have a selectbox with all featureIds in my form (Attribute myID of the 
featureMembers).If I click on the feature in the map, then the feature 
should highlight and the id should be selected in selectbox.And in the other 
direction: if user checks a special id in the selectbox, the feature in the 
map should be highlighted.

So what I need is at least
- the possibility to get the Id of the selected feature, if the polygon in 
the map is selected
- to select/highlight a feature in the map not only by click but also by id

Any ideas?


Christine




----- Original Message ----- 
From: "Christopher Schmidt" <crschmidt at metacarta.com>
To: "Christine Spietz" <spietz at fh-bingen.de>
Cc: <dev at openlayers.org>
Sent: Friday, March 30, 2007 2:45 PM
Subject: Re: [OpenLayers-Dev] feature event / highlight a feature


> On Fri, Mar 30, 2007 at 02:12:21PM +0200, Christine Spietz wrote:
>> Hi,
>>
>> I'm working with the actual trunk
>> (http://svn.openlayers.org/trunk/openlayers/lib) and try to register an
>> event on the features which are contained in a WFS-Layer.
>>
>> I want the feature to be highlighted/selected if a click-event happens on
>> the feature. If the click-event happens on another feature, this feature
>> should be highlighted and the previous feature should not be highlighted
>> anymore.
>> So the whole time only ONE feature is highlighted, if a click-event
>> appears
>> on this feature.
>>
>> Are there posibilities to do this with the actual trunk-code of
>> OpenLayers?
>
> See http://openlayers.org/dev/examples/select-feature.html
>
> Regards,
> -- 
> Christopher Schmidt
> MetaCarta
>




More information about the Dev mailing list