From: Edwin C. <com...@gm...> - 2010-02-05 09:21:35
|
Hi Bob and Dave and GWT-OL devls, For all on the gwt-openlayers-devl list: IF NO ONE OBJECTS I WILL REMOVE THE WFS LAYER CLASSES FROM THE CODEBASE, AND CREATE A WFSPROTOCOL EXAMPLE, WHICH DOCUMENTS WHY WFS SHOULD BE DONE THAT WAY. (see below) First of all, great that it' s working now. Dave, thanks for your clever analysis of the problem. WFS indeed extends the Vector class. This was done, because in OpenLayers the WFS class inherits both from the Markers Layer and from the Vector Layer, but it seemed to me to have more Vector Layer qualities than Marker Layer qualities and since multiple inheritance is not possible in Java I let WFS extend VectorFeature. See the OL UML diagram about this: http://trac.openlayers.org/attachment/wiki/UML/ClassDiagram_OL2.7RC2-20080916.pdf Notice that according to the way it is organized in OpenLayers the WFS class indeed inherits the event "featureselected" from the Vector Layer. This is the same event the SelectFeature control will register itself for, as you pass it the Vector Layer. All of the OpenLayers WFS examples on dev seem to use the WFSProtocol (http://openlayers.org/dev/examples/ and filter on WFS), also the wfs-states example, which uses a WFS layer in the examples bundled with 2.8. The WFSProtocol should cover everything that you want to do with WFS. I am now on the track that we should deliberately not implement the WFS layer at all, especially since the dev example don't seem to use it also and an OpenLayers committer I know confided to me that the WFS layer is indeed a legacy construct that is superseded by WFSProtocol. Added bonus: It makes the libary leaner if we can omit WFS layer and use WFSProtocol. The issue you are describing with the SelectFeature Control listener versus the Vector Layer listener could also occur with a plain Vector layer it seems, as there are apparently two ways to add a "featureselected" listener. I did indeed add some classes for WFS, but hadn't come round to really wrapping the WFS stuff. Sorry, about the confusion around that. Bob, in the example code you send I saw you created a WFSParam object and a WFSOptions object, which are just empty stubs in the current Hg repo. So that's why I assumed you filled in the WFS stubs (even though it has my name above it). Sorry for putting you on the wrong track by including the WFS stubs. Greetings, Edwin On 5 February 2010 07:38, Robert Light <rob...@ve...> wrote: > Dave, > > Thanks for the analysis...this seems to explain the behavior I was seeing > from my side. I ultimately did as you suggested and created the WFS layer > with the SelectFeature control... with the SelectFeatureOptions setup > properly. > > Things are good now ...but clearly I managed to step into a tarpit which was > sort of "mystical" on why it behaved the way it did. > > We too will be having a huge number of features and will shift to using a > WMS server to paint the tiles and download it to the client... this makes it > easy to pass selection events back to the server and have the server figure > out what got clicked. > > - Bob > > Dave Koberstein wrote: > > Hi Guys, > > Sorry for the slow response. > > I haven't actually used WFS layer. In our case we have tons of features. > So I use a WMS layer to get an image of the features. Then I recently > implemented Control.GetFeature to request via WFSProtocol the features the > server returns in a bbox as described by the WMS layer. Upon callback one > can do as they wish, include adding VectorFeature()'s to a Vector Layer > (which I've done). I'm currently using markers and popups but maybe I > should look at a vector layer and vectorfeature. > > I think there may be a combination that shouldn't be allowed in the > gwt-openlayers. It looks like VectorFeatureSelected ultimately is looking > for a 'featureselected' event in OpenLayers. Layer/Vector.js will generate > that but Layer/WFS.js will not (looking at the openlayers source). > > I see that SelectFeature also can generate 'featureselected'. So apparently > when you have the SelectFeature control setup you then get 'featureselected' > events and you've got two listeners for that event. > > I think what you really want is WFS layer and SelectFeature control on that > layer. When your page loads the WFS layer gets loaded with features that > you can then select. > > VectorFeature seems only associated with vector layers. Perhaps our WFS > class shouldn't extend the Vector class like it does now. It's allowing > combinations that can't happen. > > Anyway, that's all I can come up with by looking at the code. > > Davek > > > > > On 2/4/2010 9:54 AM, Edwin Commandeur wrote: > > Hi Robert, > > The WFS functionality is a recent contribution by Dave, maybe he > recognizes the problem easily. I still need to get working on a Java > port of the Open Proxy that is necessary for the WFS functionality and > that is included in the OpenLayers examples. > > How are you running your code? Is the Python Open Proxy implementation up? > > The dev list is not publicly visible as far as I am aware, but I have > cc'd this reply to the devl list. > > Greetings, > Edwin > > > On 4 February 2010 16:54, Robert Light<rob...@ve...> wrote: > > > Edwin, > > I think I've found a bug either in openlayers or in gwt-openlayers code. > > if I create a WFS layer: > WFSParams wfsParams = new WFSParams(); > wfsParams.setTypename("topp:states"); > WFSOptions wfsLayerOptions = new WFSOptions(); > wfsLayerOptions.setTransitionEffect(TransitionEffect.RESIZE); > wfsLayerOptions.setExtractAttributes(true); > > WFS wfsLayer = new WFS( > "states", > "http://192.168.1.167:8080/geoserver/wfs", > wfsParams, > wfsLayerOptions); > > and then I want to get selection events so I do: > > wfsLayer.addVectorFeatureSelectedListener( new > VectorFeatureSelectedListener() { > > public void onFeatureSelected(FeatureSelectedEvent > eventObject) { > JSONObject map = new > JSONObject(eventObject.getVectorFeature().getJSObject().getProperty("attributes")); > System.out.println("Feature.id = > "+eventObject.getVectorFeature().getId()); > for( String key : map.keySet()) { > System.out.println(key+"="+map.get(key)); > } > } > }); > > This does not work... my VectorFeatureSelectListener never get's called. > > To make this work, I had to add the following: > SelectFeatureOptions selectFeatureOptions = new > SelectFeatureOptions(); > selectFeatureOptions.onSelect( new > SelectFeature.SelectFeatureListener() { > > public void onFeatureSelected(VectorFeature vectorFeature) > { > JSONObject map = new > JSONObject(vectorFeature.getJSObject().getProperty("attributes")); > for( String key : map.keySet()) { > System.out.println(key+"="+map.get(key)); > } > } > }); > > SelectFeature selfeature = new SelectFeature(wfsLayer, > selectFeatureOptions); > map.getMap().addControl(selfeature); > selfeature.activate(); > > > And now BOTH my VectureFeatureSelectListener AND my SelectFeatureListener > get called when I select a feature. > > To put another wrinkle in the puzzle....instead of adding the SelectFeature > Control as above, I do just the following: > > SelectFeature selfeature = new SelectFeature(wfsLayer); > map.getMap().addControl(selfeature); > selfeature.activate(); > > My VectorFeatureSelectListener does NOT get called. > > Any ideas? Is there a developer's list I should post this query to? > > Note, I'm working off the latest set of sources that I downloaded via > mercurial. > > many thanks. > > - Bob Light > > > > |