選択したレイヤのフィーチャの作成(draw)と編集(modify, delete)と、属性の編集ができるようにします。
3.2. Editing Features and Their Attributes(http://workshops.boundlessgeo.com/geoext/wfs/editing.html)の「Bonus Task」を参考に、一部を修正します。
---
function reconfigure(store, url) { var fields = [], columns = [], geometryName, geometryType; // regular expression to detect the geometry column var geomRegex = /gml:(Multi)?(Point|Line|Polygon|Surface|Geometry).*/;
// mapping of xml schema data types to Ext JS data types var types = { "xsd:int": "int", "xsd:short": "int", "xsd:long": "int", "xsd:string": "string", "xsd:dateTime": "string", "xsd:double": "float", "xsd:decimal": "float", "Line": "Path", "Surface": "Polygon" };
store.each(function(rec) { var type = rec.get("type"); var name = rec.get("name"); var match = geomRegex.exec(type);
if (match) { // we found the geometry column geometryName = name; // Geometry type for the sketch handler: // match[2] is "Point", "Line", "Polygon", "Surface" or "Geometry" geometryType = types[match[2]] || match[2]; // 追加 } else { // we have an attribute column fields.push({ name: name, type: types[type] });
columns.push({ xtype: types[type] == "string" ? "gridcolumn" : "numbercolumn", dataIndex: name, header: name, // ここから追加 // textfield editor for strings, numberfield for others editor: { xtype: types[type] == "string" ? "textfield" : "numberfield" } // ここまで }); } });
app.featureGrid.reconfigure(new GeoExt.data.FeatureStore({ autoLoad: true, proxy: new GeoExt.data.ProtocolProxy({ protocol: new OpenLayers.Protocol.WFS({ url: url, version: "1.1.0", featureType: rawAttributeData.featureTypes[0].typeName, featureNS: rawAttributeData.targetNamespace, // srsName: "EPSG:4326", srsName: "EPSG:2451", geometryName: geometryName, maxFeatures: 250 }) }), fields: fields
}), new Ext.grid.ColumnModel(columns)); app.featureGrid.store.bind(vectorLayer); app.featureGrid.getSelectionModel().bind(vectorLayer); // ここから追加 // Set the correct sketch handler according to the geometryType drawControl.handler = new OpenLayers.Handler[geometryType]( drawControl, drawControl.callbacks, drawControl.handlerOptions ); // ここまで }
function setLayer(model, node) { if(!node || node.layer instanceof OpenLayers.Layer.Vector) { return; } vectorLayer.removeAllFeatures(); app.featureGrid.reconfigure( new Ext.data.Store(), new Ext.grid.ColumnModel([]) ); var layer = node.layer; var url = layer.url.split("?")[0]; // the base url without params
var schema = new GeoExt.data.AttributeStore({ url: url, // request specific params baseParams: { "SERVICE": "WFS", "REQUEST": "DescribeFeatureType", "VERSION": "1.1.0", "TYPENAME": layer.params.LAYERS }, autoLoad: true, listeners: { "load": function(store) { app.featureGrid.setTitle(layer.name); reconfigure(store, url); } } }); }
Ext.onReady(function() { app.tree.getSelectionModel().on( "selectionchange", setLayer ); });
</script>
---
参考 HTML ファイル
0 件のコメント:
コメントを投稿