[OpenLayers-Users] Highlighting the selected geometry

Eric Lemoine eric.c2c at gmail.com
Thu Sep 11 12:55:42 EDT 2008


Hi. I don't know why it doesn't work on rc1. What i know is that
MapFish has on influence on this. Eric

2008/9/11, Lehtonen, Mika <mika at digikartta.net>:
> Updated version. This works with OL 2.6 but not with 2.7-RC1 (in IE6-7
> and FF2-3) if everything is written in one line without spaces. Why
> doesn't it work with 2.7-RC1?  Note the variable!
>
> FILTER: '<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs"
> xmlns:ogc="http://www.opengis.net/ogc" service="WFS" version="1.1.0"
> xmlns:gml="http://www.opengis.net/gml"><gml:featureMember><ogc:Filter><ogc:Contains><ogc:PropertyName>the_geom</ogc:PropertyName><gml:Point><gml:coordinates>*'+hiirixy+'*</gml:coordinates></gml:Point></ogc:Contains></ogc:Filter></gml:featureMember></wfs:FeatureCollection>'
>
> I am using MapFish. Does it infuence on this somehow?
>
> mika
>
> Lehtonen, Mika kirjoitti:
>> Shouldn't be braging about too early. Now I get this:
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <ows:ExceptionReport version="1.0.0"
>>   xsi:schemaLocation="http://www.opengis.net/ows
>> http://karsamaki.digikartta.net:80/asemakaavat/schemas/ows/1.0.0/owsExceptionReport.xsd"
>>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xmlns:ows="http://www.opengis.net/ows">
>>   <ows:Exception exceptionCode="NoApplicableCode"
>> locator="org.vfny.geoserver.util.requests.readers.XmlRequestReader">
>>     <ows:ExceptionText>org.xml.sax.SAXParseException:
>>       Content is not allowed in prolog. Content is not
>>       allowed in prolog.</ows:ExceptionText>
>>   </ows:Exception>
>> </ows:ExceptionReport>
>>
>> Maybe a geoserver issue, but any thoughts..?
>>
>> - mika -
>>
>> Lehtonen, Mika kirjoitti:
>>
>>> I got it working. Not the highlighting, but GetFeature. Those of you who
>>> don't know what I have been up to, I've been trying to do what is done
>>> in http://www.openlayers.org/dev/examples/getfeatureinfo.html , but with
>>> GetFeature. With this code I get feature's data by clicking it like in
>>> that example. You can decode the filter e.g. in
>>> http://meyerweb.com/eric/tools/dencoder/ . What was wrong with other
>>> browsers than FF3, was that I forgot apostrophes off around the filter
>>> declaration. In FF3, I noticed that it doesn't care about URL encoding,
>>> just stick your staff into it as it is.
>>>
>>> cheers,
>>> mika
>>>
>>> map.events.register('click', null, function (e) {
>>> OpenLayers.Util.getElement('nodelist').innerHTML = "Please wait...";
>>> 	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:
>>> '%3Cwfs%3AFeatureCollection%20xmlns%3Awfs%3D%22http%3A//www.opengis.net/wfs%22%3E%3Cgml%3AfeatureMember%20xmlns%3Agml%3D%22http%3A//www.opengis.net/gml%22%3E%3CFilter%3E%3CContains%3E%3CPropertyName%3Ethe_geom%3C/PropertyName%3E%3Cgml%3APoint%3E%3Cgml%3Acoordinates%3E%7Bhiirixy%7D%3C/gml%3Acoordinates%3E%3C/gml%3APoint%3E%3C/Contains%3E%3C/Filter%3E%3C/gml%3AfeatureMember%3E%3C/wfs%3AFeatureCollection%3E'
>>> },"http://karsamaki.digikartta.net/asemakaavat/wfs"
>>>                            );
>>>
>>> 			OpenLayers.loadURL(url,'',this,yourFunction);				
>>> 			Event.stop(e);
>>> 			});
>>>
>>> function yourFunction(response) { // this will only zoom into selected
>>> feature..
>>> 					// 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);
>>>
>>>                                                                  };
>>>
>>> Lehtonen, Mika kirjoitti:
>>>
>>>
>>>> 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
>>>>>
>>>>>
>>>>>
>>>>>
>>>> _______________________________________________
>>>> 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
>>>
>>>
>> _______________________________________________
>> 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