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

Stefan Schwarzer stefan.schwarzer at unepgrid.ch
Tue Aug 10 12:24:29 CEST 2010


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



More information about the Users mailing list