[OpenLayers-Users] Highlighting the selected geometry
Lehtonen, Mika
mika at digikartta.net
Wed Sep 10 17:10:01 EDT 2008
Hi Brad,
cool site you have!
You know, I went on with my own style, as stubborn is my middle name.. I
got my code working so far; to get JSON out of the selected polygon
(nice thing to move on .. ;-) ), but...
you don't happen to know how I'll get this working also in IE. Here is
the snippet. I guess it got something to do with the URL encoding ...?
Debugger blames the filter, which obviously is the guilty one. (IE excl.
:-) ).
map.events.register('click', null, function (e) {
OpenLayers.Util.getElement('nodelist').innerHTML = "Odota hetki...";
var hiiri = wfs.map.getLonLatFromPixel(e.xy);
var hiirixy = (hiiri.lat+','+hiiri.lon);
var url = wfs.getFullRequestString({
SERVICE: 'WFS',
VERSION: '1.1.0',
REQUEST: 'GetFeature',
OUTPUTFORMAT: 'json',
PROPERTYNAME: 'the_geom,LAYER',
MAXFEATURES: 5,
TYPENAME: 'dikanet:karsa_region',
SRSNAME: 'EPSG:2393',
FILTER: <wfs:FeatureCollection
xmlns:wfs="http://www.opengis.net/wfs"><gml:featureMember
xmlns:gml="http://www.opengis.net/gml"><Filter>
<Contains><PropertyName>the_geom</PropertyName><gml:Point><gml:coordinates>{hiirixy}</gml:coordinates></gml:Point></Contains>
</Filter></gml:featureMember></wfs:FeatureCollection>
},
"http://karsamaki.digikartta.net/asemakaavat/wfs"
);
..............................................
OpenLayers.loadURL(url,'',this,testJSON);
Event.stop(e);
});
............................................
function testJSON (response) {
// alert(response.responseText);
g = new OpenLayers.Format.JSON();
jsonni = g.read(response.responseText);
var rajat = new
OpenLayers.Bounds(jsonni.bbox[0],jsonni.bbox[1],jsonni.bbox[2],jsonni.bbox[3]);
map.zoomToExtent(rajat);
};
..........................................................
Doesn't do anything else so far than zooms into the selected polygon.
- mika -
Brad Spencer kirjoitti:
> Mika,
>
> I typically use getFeature when I need the geometry as well and one way to
> reduce the number of polygons returned is to set up a Shift-drag event that
> can be used to reduce the BBox of the GetFeature request to be limited to
> the user's discretion. However, this will be a rectangle and will probably
> still return more or less polygons than you need. The request I use
> typically looks something like this:
>
> &typename=MESHBLOCKS&datastore=ABS&service=wfs&request=GetFeature&filter=<Fi
> lter><BBOX><Box><coordinates>151.042611,-33.947448%20151.043,-33.9</coordina
> tes></Box></BBOX></Filter>&outputformat=BXFS
>
> This returns an GML file into DOM that I can parse to get all the
> coordinates of the polygons returned.
>
> However, if you are interacting via a single clicking process and do not
> need the geometry then all you need is a getFeatureInfo request. I have
> built an application that does this see
> http://demos.numaps.com.au/polypika.html. Just doubleclick any red polygon
> and what happens in the background is the click generates a getFeatureInfo
> request which looks something like:
>
> REQUEST=GetFeatureInfo&VERSION=1.1.3&SERVICE=WMS&SRS=EPSG:900913&BBOX=128495
> 99.340828,-3816959.290073,12980306.659172,-3708418.709927&X=474&Y=369&QUERY_
> LAYERS=INDIGENOUS_LOC:ABS&WIDTH=855&HEIGHT=710&RADIUS=0&FEATURE_COUNT=1&INFO
> _FORMAT=text/xml
>
> This returns a an XML file into the DOM which I can parse to get the Polygon
> Id. Then I do the SLD thing.
>
> Hope these suggestions help you.
>
> Cheers, Brad Spencer....
>
>
>
> -----Original Message-----
> From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org] On
> Behalf Of Lehtonen, Mika
> Sent: Tuesday, September 09, 2008 10:43 PM
> To: Openlayers Users List
> Subject: Re: [OpenLayers-Users] Highlighting the selected geometry
>
> Yep,
> thanks. I am using Geoserver so SLD approach is ok. One stupid question.
> I started to play around with GetFeature, but how can you get just the
> feature you clicked. I tried something similar like in OL example [1],
> but with GetFeature and WFS. So the following is what I tried:
>
> map.events.register('click', null, function (e) {
> OpenLayers.Util.getElement('nodelist').innerHTML = "Odota hetki...";
> var url = wfs.getFullRequestString({
> SERVICE: 'WFS',
> VERSION: '1.0.0',
> REQUEST: 'GetFeature',
> OUTPUTFORMAT: 'text/xml; subtype=gml/2.1.2',
> PROPERTYNAME: 'LAYER',
> MAXFEATURES: 3,
> TYPENAME: 'dikanet:karsa_region',
> SRSNAME: 'EPSG:2393',
> BBOX: wfs.map.getExtent().toBBOX()},
> "http://karsamaki.digikartta.net/asemakaavat/wfs"
> );
> OpenLayers.loadURL(url,'',this,setHTML);
> Event.stop(e);
> });
>
> function setHTML(response) {
> OpenLayers.Util.getElement('nodelist').innerHTML =
> response.responseText;
> };
>
> But this gives me all the feautures in the current viewport. How can I
> filter out the rest and just take the one I clicked?
>
> - mika -
>
> [1] http://www.openlayers.org/dev/examples/getfeatureinfo.html
>
> Brad Spencer kirjoitti:
>
>> Mika,
>>
>> Does the map server support (style Layer descriptors) SLDs? If so this is
>> the best way to highlight polygons in my experience. Vectors may misalign
>> depending on browsers/projections. Also there are capacity limits on
>>
> vectors
>
>> at the client which can be problematic. The easiest way to make sure this
>> does not happen is to have the layer render again via a new SLD. What I do
>> is run a GetFeatureinfo(WMS) or getfeaturte(WFS) bring back the list of
>> polygons (must have unique identifiers) then I build an SLD on the fly via
>>
> a
>
>> PHP script save it and then apply that to the current layer. Of course if
>> you have the polygon names already accessible in the client (e.g. in a
>> select box) then you can just jump to the SLD building part. Works a
>>
> treat.
>
>> Cheers, Brad....
>>
>> -----Original Message-----
>> From: users-bounces at openlayers.org [mailto:users-bounces at openlayers.org]
>>
> On
>
>> Behalf Of Lehtonen, Mika
>> Sent: Tuesday, September 09, 2008 5:02 PM
>> To: Openlayers Users List
>> Subject: [OpenLayers-Users] Highlighting the selected geometry
>>
>> Hi,
>>
>> is there any examples available which I could use with the following
>> task? Tried to google, but didn't find any good ones.
>>
>> I have two wms-layers in my map. The another one includes some polygons.
>> In order to get some info out when clicking the polygon, I built a
>> system which does that. But I would also like to get the selected
>> polygon to render with a different style, so that it'd be sort of
>> highlighted. I thought I could copy it into vector layer having
>> different style. But frankly said, I don't know how to do it. Just
>> learning OL.
>>
>> - mika -
>> _______________________________________________
>> Users mailing list
>> Users at openlayers.org
>> http://openlayers.org/mailman/listinfo/users
>>
>>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
More information about the Users
mailing list