[Users] How to add WFS and local Vector data ?

Stefan Schwarzer stefan.schwarzer at unepgrid.ch
Thu Aug 12 08:34:00 CEST 2010


Hmm... searched quite a bit on the net, found a couple of WFS examples (again), and did this to add a WFS layer:



var wfsLayer = new OpenLayers.Layer.Vector("vector", {
	strategies: [new OpenLayers.Strategy.Fixed()],
	protocol: new OpenLayers.Protocol.WFS({
		url: "http://myserver:8080/geoserver/wfs?service=wfs",
		version: "1.1.0",
		featureType: "bafu_ind:mylayer",
		featureNS: "",
		geometryName: "SHAPE", 
		srsName: "EPSG:21781"
	}),
	projection: new OpenLayers.Projection("EPSG:4326")
});

var store = new GeoExt.data.FeatureStore({
    fields: [
        {name: "name", type: "string"}
    ],
    layer: wfsLayer
});



But it's still not working. It's not doing a connection, it seems... Is anything wrong with that code?

Thanks for any hints!

Stef


On Aug 10, 2010, at 12:24 PM, Stefan Schwarzer wrote:

> Hi there,
> 
> I am trying to use different services - and trying to figure out which one would be best to use -, including locally stored KML as well as WFS layers.
> 
> Now, I am not really getting through with it. I've looked around how the examples work, but as soon as it goes down to adapting my existing script, I don't succeed. And I guess this is (partially) due to the fact that I haven't really understood the concepts behind....
> 
> What I have so far is this:
> 
> ______________________________________________________________________
> 
> 	    // create map instance
> 	    var map = new OpenLayers.Map();
> 
> 
> 		// get background WMS layer
> 	        var wmsLayer = new OpenLayers.Layer.WMS(
> 	        "Global Imagery",
> 	        "http://maps.opengeo.org/geowebcache/service/wms",
> 	        {
> 	        	layers: "bluemarble"
> 	        },
> 	        {
> 		        isBaseLayer: true,
> 		        displayInLayerSwitcher: true
> 			}
> 	    );
> 
> 
> 		// get raster 100m WMS layer
> 	        var wmsLayer100m = new OpenLayers.Layer.WMS(
> 	        "Wohnfläche Raster 100m",
> 	        "http://212.203.125.185:8080/geoserver/wms",
> 	        {
> 	        	layers: "bafu_ind:surface_habitation_personne_geneve_100m", 
> 	        	transparent: "true"
> 	        },
> 	        {
> 	        	visibility: false
> 	        }
> 	    );
> 
> 
> 		var vecLayer = new OpenLayers.Layer.Vector("Wohnfläche");
> 
> 		// create feature store, binding it to the vector layer
> 		var store = new GeoExt.data.FeatureStore({
> 		    layer: vecLayer,
> 		    proxy: new GeoExt.data.ProtocolProxy({
> 		        protocol: new OpenLayers.Protocol.HTTP({
> 		            url: "data/surf_21.kml",
> 		            format: new OpenLayers.Format.KML({
> 			            extractStyles: true, 
> 			            extractAttributes: true
> 		            })
> 		        })
> 		    }),
> 		    fields: [
> 		        {name: 'name', type: 'string'},
> 		        {name: 'Avg_GRIDCO', type: 'string'},
> 		        {name: 'query', type: 'string'}
> 		    ],
> 		    autoLoad: true
> 		});
> 	
> 		store.setDefaultSort('name', 'asc');
> 	
> 	
> 
> 		var vecLayer2 = new OpenLayers.Layer.Vector("Wohnfläche Kantone");
> 
> 		// create feature store, binding it to the vector layer
> 		var store = new GeoExt.data.FeatureStore({
> 		    layer: vecLayer2,
> 		    proxy: new GeoExt.data.ProtocolProxy({
> 		        protocol: new OpenLayers.Protocol.HTTP({
> 		            url: "data/kantone_wohnflaeche.kml",
> 		            format: new OpenLayers.Format.KML({
> 			            extractStyles: true, 
> 			            extractAttributes: true
> 		            })
> 		        })
> 		    }),
> 		    fields: [
> 		        {name: 'name', type: 'string'},
> 		        {name: 'wohnfl_per', type: 'string'}
> 		    ],
> 		    autoLoad: true
> 		});
> 	
> 		store.setDefaultSort('name', 'asc');
> 
> 
> 	     // add layers
> 	    map.addLayers([wmsLayer, wmsLayer100m, vecLayer, vecLayer2]); 
> 	
> 
> ______________________________________________________________________
> 
> Concerning the stores, I can link two different layers to the same GridPanel, no? Guess that they need to have the same attributes though...
> 
> And how can I add a WFS layer now?
> 
> I have seen this somewhere:
> 
> var wfsLayer = new OpenLayers.Layer.Vector("vector", {
> strategies: [new OpenLayers.Strategy.Fixed()],
> protocol: new OpenLayers.Protocol.WFS({
> url: "http://greenway:8399/arcgis/services/SFAFNR00/soil_wfs/GeoDataServer/WFSServer",
> version: "1.1.0",
> featureType: "SoilDatabase_wgs84",
> featureNS: "http://greenway:8399/arcgis/services/SFAFNR00/soil_wfs/GeoDataServer/WFSServer",
> featurePrefix : "soil_wfs",
> geometryName: "Shape",
> srsName: "EPSG:4326"
> })
> });
> 
> 
> I tried it out with my parameters, but it doesn't work....
> 
> Thanks a lot for any tips!
> 
> Stef
> 
> _______________________________________________
> Users mailing list
> Users at geoext.org
> http://www.geoext.org/cgi-bin/mailman/listinfo/users



More information about the Users mailing list