feature event / highlight a feature

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

feature event / highlight a feature

Christine Spietz
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?

Thanks for your help!

Christine


_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: feature event / highlight a feature

Christopher Schmidt-2
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
_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: feature event / highlight a feature

Christine Spietz
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" <[hidden email]>
To: "Christine Spietz" <[hidden email]>
Cc: <[hidden email]>
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
>

_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: feature event / highlight a feature

Tim Schaub-2
Hello Christine-

Christine Spietz wrote:

> 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>
> ... GML nonsense
> </gml:featureMember>
>

If you want use GML to create vector features see:

http://openlayers.org/dev/examples/gml-layer.html

and

http://openlayers.org/dev/examples/GMLParser.html

The first example uses a Layer.GML - a subclass of Layer.Vector.  With
the GML layer, you construct it with a title and the path to your GML.
All the features in the GML will be added to your layer.

The second example uses the Format.GML - a GML parser.  In this example,
you can see how to construct a Format.GML and call the read method to
get an array of features.  Then you can do whatever you want with these
features (like add them to a vector layer to have them displayed).

Hope that helps,

Tim
_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: feature event / highlight a feature

Christine Spietz
Hi Tim,

I "just" want to register some kind of EventListener to each feature.
The features are all drawn in a layer (it is no matter for me if it is a
Vector-Layer or a GML-Layer or a WFS-Layer or something else).
I want them to be highlighted when they are clicked and to tell me their
fid.

So I tried the following two ways:

###################################1######################################
var polygonLayer = new OpenLayers.Layer.GML("Polygon Layer");

map.addLayer(polygonLayer);


...... //getting the points for the geometry an getting the fid for the
feature

polygonFeature = new OpenLayers.Feature.Vector(new
OpenLayers.Geometry.Polygon([linearRing]));
polygonFeature.setFid(slnr.firstChild.nodeValue);
polygonLayer.addFeatures([polygonFeature]);
drawControls = {
    select: new OpenLayers.Control.SelectFeature(polygonLayer),
    hover: new OpenLayers.Control.SelectFeature(polygonLayer,{hover: true})
};
for(key in drawControl)
    map.addControl(drawControls[key]);
    var control = drawControls[key];
    control.activate();
}

In drawControls the select should call a function which highlights the field
as long as no other field is selected and which makes for example an alert
which shows the fid of the feature. If I call a function this way:

drawControls = {
    select: myFunctionToHandleSelection(polygonLayer),
    hover: new OpenLayers.Control.SelectFeature(polygonLayer,{hover: true})
};

I get the following error:

control has no properties
control.outsideViewport = (control.div != null);


Besides that
- I do not know how to get the fid of the selected feature in the function
myFunctionToHandleSelection(polygonLayer)
- the selected feature only is highlighted for a view seconds and the has
again his default color.


###################################2
approach######################################
//in initMap:

url ="/xy?getAllFeatures";
schlaege = new OpenLayers.Layer.GML("GML", url);
map.addLayer(schlaege);
OpenLayers.loadURL(url, "", null, parseData);

...

//in parseData:

function parseData(req) {
g = new OpenLayers.Format.GML();
features = g.read(req.responseText);
for(var feat in features) {
    feature = features[feat];
    feature.events.register("click", feature, function(evt) {
        alert('something');
        Event.stop(evt);}
    );
}
}


There must be an error in code, because the event is not registered, but
unfortunately there also is no error shown on console.

So neither my first nor my second approach is succesfull. The main point is,
that I am not able to register event-listener (onclick highlight AND give
some  information) to the several features.


Christine







----- Original Message -----
From: "Tim Schaub" <[hidden email]>
To: <[hidden email]>
Sent: Friday, March 30, 2007 7:44 PM
Subject: Re: [OpenLayers-Dev] feature event / highlight a feature


> Hello Christine-
>
> Christine Spietz wrote:
>> 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>
>> ... GML nonsense
>> </gml:featureMember>
>>
>
> If you want use GML to create vector features see:
>
> http://openlayers.org/dev/examples/gml-layer.html
>
> and
>
> http://openlayers.org/dev/examples/GMLParser.html
>
> The first example uses a Layer.GML - a subclass of Layer.Vector.  With
> the GML layer, you construct it with a title and the path to your GML.
> All the features in the GML will be added to your layer.
>
> The second example uses the Format.GML - a GML parser.  In this example,
> you can see how to construct a Format.GML and call the read method to
> get an array of features.  Then you can do whatever you want with these
> features (like add them to a vector layer to have them displayed).
>
> Hope that helps,
>
> Tim
> _______________________________________________
> Dev mailing list
> [hidden email]
> http://openlayers.org/mailman/listinfo/dev
>

_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev