如何使用OpenLayers.Protocol.HTTP更改向量层?

时间:2013-12-10 08:18:33

标签: openlayers

我有:

     var saveStrategy = new OpenLayers.Strategy.Save();
     var vector = new OpenLayers.Layer.Vector("vector", {
                projection: mercator,
                strategies: [new OpenLayers.Strategy.Fixed(), saveStrategy],
                protocol:  new OpenLayers.Protocol.HTTP({
                    url: "/test/dtp_json.php",
                    format: new OpenLayers.Format.GeoJSON()
                })
           });


        var store = new GeoExt.data.FeatureStore({
            fields: [
                {name: "dtp", type: "string", convert: dtpname},
                {name: "date", type: "date"},
                {name: "fio", type: "string"},
                {name: "human", type: "long", defaultValue: 0},
                {name: "place", type: "string"},
                {name: "opisanie", type: "string"}
            ],
            layer: vector,
            addFeatureFilter: function(feature) {
                return feature.state !== OpenLayers.State.DELETE;
                }

        });

我在GeoExt.MapPanel上编辑(创建,删除...)这个图层使用:

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

       var drawControl = new OpenLayers.Control.DrawFeature(
                                vector,
                                OpenLayers.Handler.Point,
                                {handlerOptions: {multi: false}}
                            );

                ..........(new GeoExt.MapPanel)
                id: "mapPanel",
                bbar: [
                       new GeoExt.Action({
                               control: drawControl,
                               text: "Create",
                               enableToggle: true,
                      },
                      handler: function() {
                             var gV = gridPanel.getView();
                             gV.on('rowsinserted', function(view,firstRow,lastRow)
                             {
                              gridPanel.getSelectionModel().selectLastRow();
                              gridPanel.startEditing(lastRow,0);
                             });
                      }
                    }),
                    {
                    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;
                           vector.addFeatures([feature]);
                             };
                         })
                        }},
                    ............

如何保存(提交)所有更改? 这不保存:

          store.commitChanges();
          saveStrategy.save();

我想要没有protocol.WFS(Geoserver)。 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

1 个答案:

答案 0 :(得分:1)

所以,非常简单:

       var vector = new OpenLayers.Layer.Vector("vector", {
                projection: mercator,
                strategies: [new OpenLayers.Strategy.Fixed(), saveStrategy],
                protocol:  new OpenLayers.Protocol.HTTP({
                    url: "/test/dtp_json.php",
                    format: new OpenLayers.Format.GeoJSON(),
                    update: function(feature) {
                                               xmlhttp.open('GET', /test/dtp_pg_query.php?level=1&osm_id='+feature.attributes.osm_id, false);
                                               xmlhttp.send(null);
                                               if(xmlhttp.status == 200) {
                                                                          Ext.Msg.alert('Статус обновления',xmlhttp.responseText);
                                               };
                                              },
                    delete: function(feature) {
                                               xmlhttp.open('GET', '/test/dtp_pg_query.php?level=2&osm_id='+feature.attributes.osm_id,false);
                                               xmlhttp.send(null);
                                               if(xmlhttp.status == 200) {
                                                                          Ext.Msg.alert('Статус удаления',xmlhttp.responseText);
                                               };
                                              },
                    create: function(feature) {
                                               for (var i=0; i<feature.length; i++) //>
                                                  {
                                                   xmlhttp.open('GET', '/test/dtp_pg_query.php?level=3&osm_id='+feature[i].attributes.osm_id,false);
                                                   xmlhttp.send(null);
                                                   if(xmlhttp.status == 200) {
                                                                              Ext.Msg.alert('Статус создания',xmlhttp.responseText);
                                                   };
                                                  };
                                              },
                })
           });

然后只刷新矢量图层:

          store.commitChanges();
          saveStrategy.save();
          vector.refresh({force: true});