Hi list,

I have a vector layer with some points, and when I create a new point, it is
added to the vector layer and saved correctly in the datasource.
But, if I do a zoom in, the only feature I can see is the last new one, the
other aren't displayed anymore.
After debuging the code, I've seen that when the success event of the save
strategy is raised, there is only the last feature in the layer.. And of
course, only that one is drawn.
When I reload the page, all the new faeatures are loaded and displayed ok in
the map.

I do the following to load and create points:

function init(){
oSaveStrategyPoint = new OpenLayers.Strategy.Save();
oSaveStrategyPoint.events.register('success', '', getSaveResult);
oSaveStrategyPoint.events.register('fail', '', getSaveResult);
 wfsPoints = new OpenLayers.Layer.Vector("WFS Points", {
    strategies: [new OpenLayers.Strategy.BBOX(),
            new OpenLayers.Strategy.Cluster({ distance: 20, threshold: 10
}),
            oSaveStrategyPoint],
    protocol: new OpenLayers.Protocol.WFS({
        url: "http://localhost:8080/geoserver/wfs";,
        featureType: "points",
        srsName: "EPSG:23031",
        featureNS: "http://www.mapmap.org/g4wd";,
        geometryName: "the_geom",
        extractAttributes: false
    }),
    styleMap: myPointStyle,
    displayInLayerSwitcher: false
});
map.addLayer(wfsPoints);
 controls = {
    drawPoint:new OpenLayers.Control.DrawFeature(wfsPoints,
OpenLayers.Handler.Point, { displayClass: 'olControlDrawFeaturePoint' }),
    selectPoint:new OpenLayers.Control.SelectFeature(wfsPoints, { onSelect:
onSelectFeat, onUnselect: onUnselectFeat }),
    modifyPoint: new OpenLayers.Control.ModifyFeature(wfsPoints)
}
 controls.drawPoint.featureAdded = function(feature) {
    controls.drawPoint.layer.eraseFeatures([feature]);
    selectedFeature = feature;
    onSelectFeat(feature);
    controls.drawPoint.layer.drawFeature(feature);
}
 for (var key in controls) {
    map.addControl(controls[key]);
}
}

function onSelectFeat(feature) {
    var szPopupContent;
    selectedFeature = feature;

feature.state = OpenLayers.State.UPDATE;
szPopupContent = "<div style='font-size:.8em;font-family:Verdana'>" +
"<table style='width: 80%;'>" +
"<tr><td>" +
"Element:</td><td>" + feature.id + "<br />" +
"</td></tr><tr><td>" +
"Position:</td><td>" + feature.geometry.getBounds().getCenterLonLat() + "<br
/>" +
"</td></tr><tr><td>" +
"att_1:</td><td><input id='txtAttribute1' type='text' /><br />" +
"</td></tr><tr><td>" +
"att_2:</td><td><input id='txtAttribute2' type='text' /><br />" +
"</td></tr></table>" +
"<input id='btnSave' type='button' value='Save Point' " +
"onclick='SaveFeatures()'>" +
"</div>";

    popup = new OpenLayers.Popup.FramedCloud("chicken",
feature.geometry.getBounds().getCenterLonLat(),
null,
szPopupContent,
null, true, onPopupClose);
    map.addPopup(popup);
}

function SaveFeatures() {
if (controls["drawPoint"].active) {
selectedFeature.state = OpenLayers.State.INSERT;
}
else {
selectedFeature.state = OpenLayers.State.UPDATE;
}
selectedFeature.attributes.att_1 =
document.getElementById("txtAttribute1").value;
selectedFeature.attributes.att_2 =
document.getElementById("txtAttribute2").value;
oSaveStrategyPoint.save();
}
_______________________________________________
Users mailing list
[email protected]
http://openlayers.org/mailman/listinfo/users

Reply via email to