[OpenLayers-Users] Problem with Protocol HTTP and vector layer
Jérome Freyre
jerome.freyre at hispeed.ch
Tue Oct 21 07:41:18 EDT 2008
Hi all,
Firstly, sorry for my english...
I'm working since few month with Open Layer and I think it is really fun
Currently, I have a map with my own WMS server and a vector layer
based on strategies and protocol (HTTP) like that :
function init() {
.....
var myprotocol = new OpenLayers.Protocol.HTTP({
format: new OpenLayers.Format.GeoJSON(),
url: "getGeoJSON.php",
params: {idView: 169,model: 'startEnd'}
});
// setup tiled layer
var base = new OpenLayers.Layer.WMS(
"frj:world - Tiled", "http://localhost:8080/geoserver/wms",
{srs: 'EPSG:4326',layers: 'frj:world',format: 'image/
png',tiled: 'true'},
{buffer: 0}
);
// setup vector layer
view = new OpenLayers.Layer.Vector("View", {
strategies: [new OpenLayers.Strategies.Fixed()],
protocol: myprotocol,
styleMap: new OpenLayers.StyleMap({
"default": style,
"select": {fillColor: "#8aeeef",strokeColor: "#32a8a9"}
})
});
map.addLayers([base, view]);
...
}
When I refresh the page, the map and the layer with my features
corresponding on idView are correctly displayed.
The problem is that I have a xhtml select list with other views. When
I select an other view, I have to load features that corresponds to
the selected view.
Based on the example (http://openlayers.org/dev/examples/protocol-gears.html
), I create a method called sync :
function sync() {
resp = view.protocol.read();
if (!resp.success()) {
alert("reading failed");
return;
}
view.destroyFeatures();
if (!resp.features || resp.features.length <= 0) {
alert("No features to read");
return;
}
view.addFeatures(resp.features);
alert("features successfully read");
}
view.protocol.read() is correctly working (I saw the call to
getGeoJSON in firebug) and my getGeoJSON.php return the correct
GeoJSON. But my function always do the alert on the "reading failed"
and I don't understand why!?
I saw that resp.features is null.
So, I tried to create a new protocol and call the read() method but
the problem persist:
myprotocol = new OpenLayers.Protocol.HTTP({
format: new OpenLayers.Format.GeoJSON(),
url: "test4_.php",
params: {
idView: 169, //, callback: "changeClass"
model: 'startEnd'
}
});
resp = myprotocol.read();
Does anyone has an idea?
Thank a lot,
Jerome F.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20081021/b877396d/attachment.html
More information about the Users
mailing list