#1 Tue 12 July 2011 17:54
- lcros
- Participant occasionnel
- Lieu: toulouse
- Date d'inscription: 12 Oct 2009
- Messages: 20
openlayers layer WFS features array vide
Bonjour,
J'utilise openlayers et geoserver.
Sur geoserver j'ai créé une couche WFS basé sur oracle.
Sur la partie client, j'ai une page utilisant openlayers dans laquelle je déclare mon layer WFS :
Code:
var geoserver_wf_layerOpenLayers = new OpenLayers.Layer.WFS( "wfs", "http://localhost:8080/geoserver/wfs", { typename: 'catsat:catsat_wf_vector_layer', featureNS: "http://localhost:8080/geoserver/catsat", LAYERS: 'catsat:catsat_wf_vector_layer' } , { //styleMap: styleMap, extractAttributes: true, featureNS: "http://localhost:8080/geoserver/catsat" ,styleMap : oWheatherForecastStyleMap //,featureClass: OpenLayers.Feature.WFS } );
L'affichage de mon layer est bonne il m'affiche mes features qui sont remontés de ma base Orcale.
mais j'ai la propriété features de mon layer qui est vide !
Que j'utilise un layer vector a la place du layer WFS ne change rien.
Si quelqu'un a une idée.
Merci,
laurent.
Hors ligne
#2 Wed 13 July 2011 08:29
- Tony VINCENT
- Participant actif
- Lieu: Poitiers
- Date d'inscription: 13 Jan 2010
- Messages: 86
Re: openlayers layer WFS features array vide
Bonjour,
Peux-tu tester ton serveur WFS (Geoserver) avec une requête du type GetFeature ?
Afin de voir si cela vient de la couche WFS qui est mal configuré ou bien si c'est du côté d'OpenLayers qu'il manque quelque chose.
Voici un exemple de requête avec GetFeautre :
http://www.example.com/wfs?service=wfs& … eaturetype
Adapte cet exemple à ton besoin.
Je crois que tu peux le faire directement à partir de GeoServeur en prévisualisant ta couche.
Choisir dans Tous les formats - WFS - GeoJson.
Le serveur doit te renvoyer un fichier, dans lequel tu dois trouver la géométrie et les attributs de la couche.
Tony
Hors ligne
#3 Wed 13 July 2011 10:34
- lcros
- Participant occasionnel
- Lieu: toulouse
- Date d'inscription: 12 Oct 2009
- Messages: 20
Re: openlayers layer WFS features array vide
Bonjour,
J'ai fait la requête coté serveur :
<wfs:FeatureCollection xmlns:ogc="http://www.opengis.net/ogc" xmlns:tiger="http://www.census.gov" xmlns:cite="http://www.opengeospatial.net/cite" xmlns:nurc="http://www.nurc.nato.int" xmlns:sde="http://geoserver.sf.net" xmlns:wfs="http://www.opengis.net/wfs" xmlns:catsat="http://localhost:8080/geoserver/catsat" xmlns:topp="http://www.openplans.org/topp" xmlns:it.geosolutions="http://www.geo-solutions.it" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sf="http://www.openplans.org/spearfish" xmlns:ows="http://www.opengis.net/ows" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink" numberOfFeatures="534" timeStamp="2011-07-13T10:12:22.241+02:00" xsi:schemaLocation="http://localhost:8080/geoserver/catsat http://localhost:8080/geoserver/wfs?service=WFS&version=1.1.0&request=DescribeFeatureType&typeName=catsat%3Acatsat_wf_vector_layer http://www.opengis.net/wfs http://localhost:8080/geoserver/schemas/wfs/1.1.0/wfs.xsd">
<gml:featureMembers>
<catsat:catsat_wf_vector_layer gml:id="catsat_wf_vector_layer.58">
<catsat:LATITUDE_MINIMALE>-15</catsat:LATITUDE_MINIMALE>
<catsat:LATITUDE_MAXIMALE>-5</catsat:LATITUDE_MAXIMALE>
<catsat:LONGITUDE_MINIMALE>-40</catsat:LONGITUDE_MINIMALE>
<catsat:LONGITUDE_MAXIMALE>-30</catsat:LONGITUDE_MAXIMALE>
<catsat:NOM_ZONE>1S32</catsat:NOM_ZONE>
<catsat:VERSION_NUM>0</catsat:VERSION_NUM>
<catsat:GEOMETRY>
<gml:Polygon srsDimension="2" srsName="urn:x-ogc:def:crs:EPSG:4326">
<gml:exterior>
<gml:LinearRing>
<gml:posList>
-15.0 -40.0 -15.0 -30.0 -5.0 -30.0 -5.0 -40.0 -15.0 -40.0
</gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</catsat:GEOMETRY>
</catsat:catsat_wf_vector_layer>
<catsat:catsat_wf_vector_layer gml:id="catsat_wf_vector_layer.59">
<catsat:LATITUDE_MINIMALE>-15</catsat:LATITUDE_MINIMALE>
<catsat:LATITUDE_MAXIMALE>-5</catsat:LATITUDE_MAXIMALE>
<catsat:LONGITUDE_MINIMALE>-30</catsat:LONGITUDE_MINIMALE>
<catsat:LONGITUDE_MAXIMALE>-20</catsat:LONGITUDE_MAXIMALE>
<catsat:NOM_ZONE>1S33</catsat:NOM_ZONE>
<catsat:VERSION_NUM>0</catsat:VERSION_NUM>
<catsat:GEOMETRY>
<gml:Polygon srsDimension="2" srsName="urn:x-ogc:def:crs:EPSG:4326">
<gml:exterior>
<gml:LinearRing>
<gml:posList>
-15.0 -30.0 -15.0 -20.0 -5.0 -20.0 -5.0 -30.0 -15.0 -30.0
</gml:posList>
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</catsat:GEOMETRY>
</catsat:catsat_wf_vector_layer>
....
Je pense que c'est correct coté serveur.
Il y a une chose etrange quand je logge des infos :
au niveau javascript je logge le nombre d'objets contenu dans l objet features de mon layer et il me rend 0
si je fais un console.log de mon layer le tableau features contient 534 objets ce qui est nomal et par contre si je je mets un point d'arret à la ligne où je logge mon layer il y a 0 objets dans le tableau features.
J'ai peut être un soucis dans mon code :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>OpenLayers map preview</title>
<!-- Import OL CSS, auto import does not work with our minified OL.js build -->
<link rel="stylesheet" type="text/css" href="http://localhost:8080/geoserver/openlayers/theme/default/style.css"/>
<!-- Basic CSS definitions -->
<style type="text/css">
/* General settings */
body {
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
font-size: small;
}
/* Toolbar styles */
#toolbar {
position: relative;
padding-bottom: 0.5em;
display: none;
}
#toolbar ul {
list-style: none;
padding: 0;
margin: 0;
}
#toolbar ul li {
float: left;
padding-right: 1em;
padding-bottom: 0.5em;
}
#toolbar ul li a {
font-weight: bold;
font-size: smaller;
vertical-align: middle;
color: black;
text-decoration: none;
}
#toolbar ul li a:hover {
text-decoration: underline;
}
#toolbar ul li * {
vertical-align: middle;
}
/* The map and the location bar */
#map {
clear: both;
position: relative;
width: 1500px;
height: 800px;
border: 1px solid black;
}
#wrapper {
width: 660px;
}
#location {
float: right;
}
#options {
position: absolute;
left: 13px;
top: 7px;
z-index: 3000;
}
/* Styles used by the default GetFeatureInfo output, added to make IE happy */
table.featureInfo, table.featureInfo td, table.featureInfo th {
border: 1px solid #ddd;
border-collapse: collapse;
margin: 0;
padding: 0;
font-size: 90%;
padding: .2em .1em;
}
table.featureInfo th {
padding: .2em .2em;
text-transform: uppercase;
font-weight: bold;
background: #eee;
}
table.featureInfo td {
background: #fff;
}
table.featureInfo tr.odd td {
background: #eee;
}
table.featureInfo caption {
text-align: left;
font-size: 100%;
font-weight: bold;
text-transform: uppercase;
padding: .2em .2em;
}
</style>
<!-- Import OpenLayers, reduced, wms read only version -->
<script src="js/OpenLayers-2.10/lib/OpenLayers.js" type="text/javascript">
</script>
<script type="text/javascript">
pureCoverage = false;
// pink tile avoidance
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 5;
// make OL compute scale according to WMS spec
OpenLayers.DOTS_PER_INCH = 25.4 / 0.28;
OpenLayers.ProxyHost = "http://localhost/cgi-bin/proxy.cgi?url=";
//OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
function init(){
// if this is just a coverage or a group of them, disable a few items,
// and default to jpeg format
format = 'image/png';
bounds = new OpenLayers.Bounds(
-180, -90,
180, 90
);
options = {
controls: [],
maxExtent: bounds,
maxResolution: 1.40625,
projection: "EPSG:4326",
units: 'degrees'
};
map = new OpenLayers.Map('map', options);
oBLParams = { // Base Layer common params
layers: 'basic'
};
oBLOptions = { // Base Layer common options
isBaseLayer: true
//,wrapDateLine: true
};
// setup tiled layer
tiled = new OpenLayers.Layer.WMS(
"Base",
"http://vmap0.tiles.osgeo.org/wms/vmap0?",
oBLParams,
oBLOptions
);
context = {
getName: function(feature) {
//console.log('getName fired');
if (map.zoom > 2){
var result = feature.attributes["NOM_ZONE"];
//console.log('result '+result);
return result;
} else {
return '';
}
}
};
template = {
fillColor: '#ffffff',
fillOpacity: 0,
strokeColor: 'grey',
strokeWidth: 1,
label : "${getName}",
labelAlign: "cm",
fontColor: "black",
fontSize: "10px",
fontFamily: "Verdana",
fontWeight: "bold"
};
defaultStyle = new OpenLayers.Style(template, {context: context});
orderSelectedStyle = new OpenLayers.Style(
{
strokeColor:'red',
fontColor: "red",
fontWeight: "bold",
strokeWidth: 1,
fillOpacity: 0.4,
fillColor: 'red'
}
);
wheatherForecastSelectedStyle = new OpenLayers.Style(
{
strokeColor:'green',
fontColor: "green",
fontWeight: "bold",
strokeWidth: 1,
fillOpacity: 0.4,
fillColor: 'green'
}
);
oOrderStyleMap = new OpenLayers.StyleMap(
{
"default": defaultStyle,
"select": orderSelectedStyle
}
);
oWheatherForecastStyleMap = new OpenLayers.StyleMap(
{
"default": defaultStyle,
"select": wheatherForecastSelectedStyle
}
);
/*var geoserver_wf_layerOpenLayers = new OpenLayers.Layer.Vector("vector", {
strategies: [new OpenLayers.Strategy.BBOX()],
projection: new OpenLayers.Projection("EPSG:4326"),
protocol: new OpenLayers.Protocol.WFS({
version: "1.1.0"
,srsName: "EPSG:4326"
,url: "http://localhost:8080/geoserver/wfs"
,featureType: "catsat_wf_vector_layer"
,featureNS: "http://localhost:8080/geoserver/catsat"
,geometryName: "GEOMETRY",
})
,styleMap : oWheatherForecastStyleMap
});
*/
//http://localhost:8080/geoserver/wfs?service=WFS&version=1.1.0&request=DescribeFeatureType&typeName=catsat:catsat_wf_vector_layer
var geoserver_wf_layerOpenLayers = new OpenLayers.Layer.WFS(
"wfs",
"http://localhost:8080/geoserver/wfs",
{
typename: 'catsat:T_ZONE_GEOGRAPHIQUE',
featureNS: "http://localhost:8080/geoserver/catsat",
LAYERS: 'catsat:T_ZONE_GEOGRAPHIQUE'
} ,
{
//styleMap: styleMap,
extractAttributes: true,
featureNS: "http://localhost:8080/geoserver/catsat"
,styleMap : oWheatherForecastStyleMap
//,featureClass: OpenLayers.Feature.WFS
}
);
console.log(geoserver_wf_layerOpenLayers);
console.log(geoserver_wf_layerOpenLayers.features.length);
console.log(geoserver_wf_layerOpenLayers.unrenderedFeatures);
//console.log(geoserver_wf_layerOpenLayers.features.length)
/*console.log(geoserver_wf_layerOpenLayers.featureNS);
for (i=0;i<geoserver_wf_layerOpenLayers.features.length;i++){
feature = geoserver_wf_layerOpenLayers.features[i];
console.log('value '+feature);
}
*/
map.addLayers([tiled,geoserver_wf_layerOpenLayers]);
//console.log(geoserver_wf_layerOpenLayers)
/* map.events.register('click', map, function (e) {
document.getElementById('nodelist').innerHTML = "Loading... please wait...";
var params = {
REQUEST: "GetFeatureInfo",
EXCEPTIONS: "application/vnd.ogc.se_xml",
BBOX: map.getExtent().toBBOX(),
SERVICE: "WMS",
VERSION: "1.1.1",
X: e.xy.x,
Y: e.xy.y,
INFO_FORMAT: 'text/html',
QUERY_LAYERS: map.layers[1].params.LAYERS,
FEATURE_COUNT: 50,
Layers: 'catsat:catsat_wf_vector_layer',
WIDTH: map.size.w,
HEIGHT: map.size.h,
format: format,
styles: map.layers[1].params.STYLES,
srs: map.layers[1].params.SRS};
// merge filters
if(map.layers[1].params.CQL_FILTER != null) {
params.cql_filter = map.layers[1].params.CQL_FILTER;
}
if(map.layers[1].params.FILTER != null) {
params.filter = map.layers[1].params.FILTER;
}
if(map.layers[1].params.FEATUREID) {
params.featureid = map.layers[1].params.FEATUREID;
}
OpenLayers.loadURL("http://localhost:8080/geoserver/catsat/wfs", params, this, setHTML, setHTML);
OpenLayers.Event.stop(e);
});
function setHTML(response){
document.getElementById('nodelist').innerHTML = response.responseText;
};
*/
// build up all controls
/*map.addControl(new OpenLayers.Control.PanZoomBar({
position: new OpenLayers.Pixel(2, 15)
}));
map.addControl(new OpenLayers.Control.Scale($('scale')));
map.addControl(new OpenLayers.Control.MousePosition({element: $('location')}));
// map.zoomToExtent(bounds);
// wire up the option button
options = document.getElementById("options");
*/
map.zoomTo(3);
map.addControl(new OpenLayers.Control.Navigation());
}
</script>
</head>
<body onload="init()">
<div id="map">
<img id="options" title="Toggle options toolbar" src="http://localhost:8080/geoserver/options.png"/>
</div>
<div id="wrapper">
<div id="location">location</div>
<div id="scale">
</div>
</div>
<div id="nodelist">
<em>Click on the map to get feature info</em>
</div>
</body>
</html>
Merci d'avance,
laurent.
Dernière modification par lcros (Wed 13 July 2011 10:39)
Hors ligne
#4 Fri 22 July 2011 14:03
- lcros
- Participant occasionnel
- Lieu: toulouse
- Date d'inscription: 12 Oct 2009
- Messages: 20
Re: openlayers layer WFS features array vide
Bonjour,
J'ai eu ce problème car le log que je faisais était avant que le layer oracle ait eu le temps de se charger.
Ce post est à clore.
Désolé pour le dérangement et merci à Tony pour avoir pris la peine de me répondre.
Bon week end ou bonnes vacances
laurent.
Dernière modification par lcros (Fri 22 July 2011 14:05)
Hors ligne