Hi David, you can also request json from Geoserver when using GetFeature. I find it easier to parse than GML, but that is only my opinion. I can provide you an example if you like.
- mika - Kimball, David (DCR) kirjoitti: > Thanks for your help everyone...you're right Chris, I'm using GeoServer > not Mapserver. So on Ivan's suggestion (and with Aleda's help) I went > with a WFS GetFeature request with a +/- 5 pixel BBOX (to make the > points and lines easier to select) and a custom list of fields (not > including the geometry), and parsed the GML2 response into what I > needed. Actually easier-to-code and more functional than before! > > Here's the URL and some code snippets...there are actually separate > loadURL requests for the line and point layer queries now; this is just > the code for querying the line layer... > > http://maps.massgis.state.ma.us/dcr/trails/DCR_RoadTrail12.html > > > // ======== THE EVENT CODE (PART OF THE INIT FUNCTION): > > map.events.register('click', map, function (e) { > exy = e.xy; > > llMin = map.getLonLatFromPixel(new > OpenLayers.Pixel(e.xy.x - 5,e.xy.y + 5)); > // don't know why these have to be backwards on > the Y coordinates... > llMax = map.getLonLatFromPixel(new > OpenLayers.Pixel(e.xy.x + 5,e.xy.y - 5)); > // don't know why these have to be backwards on > the Y coordinates... > > var url2 = map.layers[0].getFullRequestString( > { > SERVICE: 'WFS', > VERSION: '1.0.0', > REQUEST: "GetFeature", > TYPENAME: 'massgis:DCR.ROADS_TRAILS_LINE', > OUTPUTFORMAT: 'GML2', > PROPERTYNAME: lineFieldListString, > MAXFEATURES: 20, > SRSNAME: 'EPSG:26986', > BBOX: llMin.lon + "," + llMin.lat + "," + > llMax.lon + "," + llMax.lat > }, > > "http://giswebservices.massgis.state.ma.us/geoserver/wfs"); > OpenLayers.loadURL(url2, '', this, setHTMLLine, > setHTMLLine); > > OpenLayers.Event.stop(e); > }); > > > > > // ======== AND THE FUNCTION THAT IS CALLED WHEN THE GML IS RETURNED > (most of this is specific to placing the values on the web page): > > function setHTMLLine(response) { > > var myGMLFormat = new OpenLayers.Format.GML(); > var myGML = myGMLFormat.read(response.responseText); > > // ---- IF A LINE WAS CLICKED, FILL THE LINE BOX > if ((myGML.length > 0) && (map.getScale() <= maxLineScale)) { > for (var k in myGML[0].attributes) { // only uses the > attributes of the first Line returned for now... > > // ----- This places the value into a new variable and truncates it if > it's a long URL; this variable is used only for placing the text on the > screen, not for href values. This way you can have a link with its > actual href string separate from its truncated presentation on-screen > var thisIsTheValue = myGML[0].attributes[k]; > > // ----- PLACE THE VALUES INTO THE CORRECT AREAS IN THE ATTRIBUTE > DISPLAY AREA (if a place for them exists) > > // ----- This places the value onto the page > if ((document.getElementById("LINE_" + k)) && > (document.getElementById("LINEROW_" + k))) { // if a row for this > attribute exists in the line table-box > document.getElementById("LINE_" + > k).innerHTML = thisIsTheValue; // write the attribute value into the > table-box > document.getElementById("LINEROW_" + > k).style.display = ''; // make this table-box row visible > } // end if > } // end for (k) > document.getElementById("lineTableHeader").innerHTML = > "Road & Trail Line Attributes"; > } // end of GPS LINE section > else { > document.getElementById("lineTableHeader").innerHTML = > "No Road/Trail clicked"; > } > } // end of function setHTMLLine > > > > > --David > > ||||||| David Kimball > ||||||| GIS Specialist > ||||||| MA Department of Conservation and Recreation > ||||||| http://www.mass.gov/dcr/stewardship/gis/ > ||||||| [email protected] > ||||||| 617.626.1447 phone > ||||||| 617.626.1349 fax > > -----Original Message----- > From: Ivan Grcic [mailto:[email protected]] > Sent: Friday, January 30, 2009 5:09 AM > To: Christopher Schmidt > Cc: Richard Greenwood; [email protected]; Kimball, David (DCR) > Subject: Re: [OpenLayers-Users] WMS GetFeatureInfo - difficult to click > exactly on a point > > Hi, > i think its 2px default in Geoserver and cant be configured still. You > have to write ur own WFS request where u calculate BBOX.. > > Take a look at wfsgetfeature control, might help > http://dev.openlayers.org/sandbox/topp/wfs/examples/wfs-getfeature.html > > > cheers > On Fri, Jan 30, 2009 at 5:36 AM, Christopher Schmidt > <[email protected]> wrote: > >> On Thu, Jan 29, 2009 at 07:20:38PM -0700, Richard Greenwood wrote: >> >>>> Kimball, David (DCR) wrote: >>>> >>>>> Hi everyone, >>>>> >>>>> I'm using a WMS GetFeatureInfo to simultaneously query the >>>>> > attributes of > >>>>> a line layer and a point layer (from GeoServer). Unfortunately >>>>> > you have > >>>>> to click *exactly* on the center of a point to get it to send you >>>>> > the > >>>>> point attributes. >>>>> >>> Look at TOLERANCE in http://www.mapserver.org/mapfile/layer.html >>> >> The original poster said he was using GeoServer. Although MapServer >> does have a TOLERANCE parameter, I do not believe that there is a >> corresponding functionality in GeoServer. >> >> Regards, >> -- >> Christopher Schmidt >> MetaCarta >> _______________________________________________ >> Users mailing list >> [email protected] >> http://openlayers.org/mailman/listinfo/users >> >> > > > > -- --------------------------------------- Mika Lehtonen XML-Scanning Littoinen Ky Lankakatu 2 E 13, 20660 Littoinen [email protected] mbl +358 (0)44 2908259 --------------------------------------- _______________________________________________ Users mailing list [email protected] http://openlayers.org/mailman/listinfo/users
