3

I'm so sorry for my english, it's not the best. I'm trying to modify my postgres geographic table with this code:

 Ext.onReady(function () {
    OpenLayers.ProxyHost = "proxy.ashx?url=";
    var saveStrategy = new OpenLayers.Strategy.Save();
    var layer = new OpenLayers.Layer.Vector("vector", {
        strategies: [new OpenLayers.Strategy.Fixed()],
        protocol: new OpenLayers.Protocol.WFS({
            version: "1.1.0",
            url: "http://localhost:8083/geoserver/wfs",
            featurePrefix: "ST",
            featureType: "geofenceprueba",
            featureNS: "http://www.safetracker.com/catalogLayer",
            geometryName: "geom"//,
            //maxFeatures:100,
            //schema: "http://localhost:8083/geoserver/wfs/DescribeFeatureType?version=1.1.0&;typename=ST:geofenceprueba",
            //srsName: "EPSG:4326"
        })
    });

    var store = new GeoExt.data.FeatureStore({
        fields: [
          {
              name: "name",
              type: "string"
          },
        {
            name: "aliases1",
            type: "string"
        },
        {
            name: "idtype",
            type: "string"
        },
        {
            name: "id",
            type: "int",
            defaultValue: 0
        }
        ],
        layer: layer,
        addFeatureFilter: function (feature) {
            return feature.state !== OpenLayers.State.DELETE;
        }
    });


    var modifyControl = new OpenLayers.Control.ModifyFeature(layer);


    var gridPanel = new Ext.grid.EditorGridPanel({
        title: "Feature Table - Medford Parks",
        region: "center",
        viewConfig: {
            forceFit: true
        },
        store: store,
        listeners: {
            afteredit: function (e) {
                var feature = e.record.get("feature");
                if (feature.state !== OpenLayers.State.INSERT) {
                    feature.state = OpenLayers.State.UPDATE;
                }
            }
        },
        sm: new GeoExt.grid.FeatureSelectionModel({
            selectControl: modifyControl.selectControl,
            singleSelect: true
        }),

        cm: new Ext.grid.ColumnModel({
            defaults: {
                sortable: true,
                editor: {
                    xtype: "textfield"
                }
            },
            columns: [
              {
                  header: "Name",
                  dataIndex: "name"
              },
            {
                header: "Owner",
                dataIndex: "aliases1"
            },
            {
                header: "Usage",
                dataIndex: "idtype",
                width: 35
            },
            {
                xtype: "id",
                header: "# of Facilities",
                dataIndex: "id",
                format: "1,000",
                align: "right",
                width: 55,
                editor: {
                    xtype: "numberfield"
                }
            }
            ]
        })
    });

    var drawControl = new OpenLayers.Control.DrawFeature(
    layer, OpenLayers.Handler.Polygon, {
        handlerOptions: {
            multi: true
        }
    });

    var mapPanel = new GeoExt.MapPanel({
        title: "Map",
        region: "west",
        width: 400,
        layers: [layer],
        extent: new OpenLayers.Bounds(-122.91, 42.28, -122.76, 42.41),
        bbar: [
          new GeoExt.Action({
              control: drawControl,
              text: "Create",
              enableToggle: true
          }),
        {
            text: "Delete",
            handler: function () {
                gridPanel.getSelectionModel().each(function (rec) {
                    var feature = rec.get("feature");
                    modifyControl.unselectFeature(feature);
                    gridPanel.store.remove(rec);
                    if (feature.state !== OpenLayers.State.INSERT) {
                        feature.state = OpenLayers.State.DELETE;
                        layer.addFeatures([feature]);
                    }
                })
            }
        }, "->",
        {
            text: "Save",
            handler: function () {
                store.commitChanges();
                saveStrategy.save();
            }
        }
        ]

    });

    mapPanel.map.addControl(modifyControl);
    modifyControl.activate();

    // var modifyControl = new OpenLayers.Control.ModifyFeature(layer);
    // mapPanel.map.addControl(modifyControl);
    // modifyControl.activate();
    mapPanel.map.addControl(drawControl);

    var mainPanel = new Ext.Panel({
        renderTo: "map-id",
        layout: "border",
        height: 450,
        width: 800,
        items: [gridPanel, mapPanel]
    });


});

I have a proxy in my .net web application:

using System; using System.Configuration; using System.IO; using System.Net; using System.Web;

/// /// adapted from: http://code.google.com/p/iisproxy /// public class proxy : IHttpHandler { public void ProcessRequest(HttpContext context) { string usuario = "admin"; HttpRequest request = context.Request; string remoteUrl = request.QueryString["url"];

    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(remoteUrl);
    req.AllowAutoRedirect = false;
    req.Method = request.HttpMethod;
    req.ContentType = request.ContentType;
    req.UserAgent = request.UserAgent;

    var basicPwd = "geoserver";
    req.Credentials = basicPwd == null ? CredentialCache.DefaultCredentials : new NetworkCredential(usuario, basicPwd);

    req.PreAuthenticate = true;
    req.Headers["Remote-User"] = usuario;
    foreach (string each in request.Headers)
        if (!WebHeaderCollection.IsRestricted(each) && each != "Remote-User")
            req.Headers.Add(each, request.Headers.Get(each));
    if (request.HttpMethod == "POST") {
        System.IO.Stream outputStream = req.GetRequestStream();
        CopyStream(request.InputStream, outputStream);
        outputStream.Close();
    }

    HttpWebResponse response;
    try {
        response = (HttpWebResponse)req.GetResponse();
    } catch (WebException we) {
        response = (HttpWebResponse)we.Response;
        if (response == null) {
            context.Response.StatusCode = 13;
            context.Response.Write("Could not contact back-end site");
            context.Response.End();
            return;
        }
    }

    context.Response.StatusCode = (int)response.StatusCode;
    context.Response.StatusDescription = response.StatusDescription;
    context.Response.ContentType = response.ContentType;
    foreach (string each in response.Headers)
        if (each != "Location" && !WebHeaderCollection.IsRestricted(each))
            context.Response.AddHeader(each, response.Headers.Get(each));

    CopyStream(response.GetResponseStream(), context.Response.OutputStream);
    response.Close();
    context.Response.End();
}

static public void CopyStream(Stream input, Stream output)
{
    //updated to read gzip compressed streams correctly
    byte[] buffer = new byte[32768];
    while (true) {
        int read = input.Read(buffer, 0, buffer.Length);
        if (read <= 0)
            return;
        output.Write(buffer, 0, read);
    }
}
public bool IsReusable {
    get { return false; }
}

}

I have already checked my namespace and workspace names, everything looks ok but I don't know what's wrong, Could somebody help me with this code?


The proxy works fine. The problem was at this code line:

            xtype: "id",
            header: "# of Facilities",
            dataIndex: "id",
            format: "1,000",
            align: "right",
            width: 55,
            editor: {
                xtype: "numberfield"
            }

xtype value have to be allowed feature (numbercolumn).

Right Now I'm trying to save changes for the new geometries but I got an exception here: saveStrategy.save(); Uncaught TypeError: Cannot read property 'features' of null

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.