ラベル Attributes の投稿を表示しています。 すべての投稿を表示
ラベル Attributes の投稿を表示しています。 すべての投稿を表示

2014年2月20日木曜日

36 - GeoEXT を使用した WFS-T 12 - 選択したレイヤの編集 2

36-12-2 選択したレイヤの属性の表示
3.1. Creating a Synchronized Grid and Map View of WFS Features(http://workshops.boundlessgeo.com/geoext/wfs/grid.html)の「Bonus Task」をコピーして貼り付け、一部を修正します。

---
// ここから追加
 var rawAttributeData;
 var read = OpenLayers.Format.WFSDescribeFeatureType.prototype.read;
 OpenLayers.Format.WFSDescribeFeatureType.prototype.read = function() {
  rawAttributeData = read.apply(this, arguments);
  return rawAttributeData;
 };
 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).*/;
  var types = {
   // mapping of xml schema data types to Ext JS data types
   "xsd:int": "int",
   "xsd:short": "int",
   "xsd:long": "int",
   "xsd:string": "string",
   "xsd:dateTime": "string",
   "xsd:double": "float",
   "xsd:decimal": "float",
   // mapping of geometry types
   "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;
   } 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
    });
   }
  });
  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);
 }
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>
---

レイヤの属性の中で、「name」が表示されません。コード中に使用されている「name」に影響されているのかもしれません。属性の「name」を「term」に変更したら表示されるようになりました。

nippon_bmi=> ALTER TABLE akiruno_polygon RENAME name to term;
ALTER TABLE
nippon_bmi=> ALTER TABLE akiruno_line RENAME name to term;
ALTER TABLE
nippon_bmi=> ALTER TABLE akiruno_point RENAME name to term;
ALTER TABLE


GeoServer で akiruno_polygon akiruno_line akiruno_point レイヤの「Feature Type Details」を確認します。表示されないときは「Reload feature type」をクリックします。

36 - GeoEXT を使用した WFS-T 12 - 選択したレイヤの編集 1

36-12-1 akiruno_point と akiruno_line に 属性を追加
Developing OGC Compliant Web Applications with GeoExt の
3.1. Creating a Synchronized Grid and Map View of WFS Features(http://workshops.boundlessgeo.com/geoext/wfs/grid.html)と3.2. Editing Features and Their Attributes(http://workshops.boundlessgeo.com/geoext/wfs/editing.html)の「Bonus Task」を参考に、「Add to Map」で追加したレイヤを tree で選択して編集します。
「ol017-nippon_bmi_akiruno_pgis.html」をコピーして名前を付けて(「ol017bonus-nippon_bmi_akiruno_pgis.html」など)使います。

最初に、akiruno_point と akiruno_line に akiruno_polygon と同じように属性を追加します。

既存の属性
fid
the_geom
追加の属性
id  charactor varying(32)
name  charactor varying(32)
address  charactor varying(32)
createdate  charactor varying(32)
lastupdate  charactor varying(32)
category1  charactor varying(32)
category2  charactor varying(32)
category3  charactor varying(32)

user@debian7-vmw:~$ psql nippon_bmi
psql (9.1.11)
"help" でヘルプを表示します.
nippon_bmi=> ALTER TABLE akiruno_point ADD COLUMN id varchar(32);
---
ALTER TABLE
nippon_bmi=> ALTER TABLE akiruno_line ADD COLUMN id varchar(32);
---

nippon_bmi=> \d akiruno_point
                                 テーブル "public.akiruno_point"
   カラム   |          型           |                           修飾語                           
------------+-----------------------+-------------------------------------------------------------
 fid        | integer               | not null default nextval('akiruno_point_fid_seq'::regclass)
 the_geom   | geometry              | 
 id         | character varying(32) | 
 name       | character varying(32) | 
 address    | character varying(32) | 
 createdate | character varying(32) | 
 lastupdate | character varying(32) | 
 category1  | character varying(32) | 
 category2  | character varying(32) | 
 category3  | character varying(32) | 

インデックス:
    "akiruno_point_pkey" PRIMARY KEY, btree (fid)
    "spatial_akiruno_point_the_geom" gist (the_geom)
CHECK 制約:
    "enforce_dims_the_geom" CHECK (st_ndims(the_geom) = 2)
    "enforce_geotype_the_geom" CHECK (geometrytype(the_geom) = 'MULTIPOINT'::text OR the_geom IS NULL)
    "enforce_srid_the_geom" CHECK (st_srid(the_geom) = 2451)

(END):q


nippon_bmi=> \d akiruno_line
                                 テーブル "public.akiruno_line"
   カラム   |          型           |                           修飾語                           
------------+-----------------------+------------------------------------------------------------
 fid        | integer               | not null default nextval('akiruno_line_fid_seq'::regclass)
 the_geom   | geometry              | 
 id         | character varying(32) | 
 name       | character varying(32) | 
 address    | character varying(32) | 
 createdate | character varying(32) | 
 lastupdate | character varying(32) | 
 category1  | character varying(32) | 
 category2  | character varying(32) | 
 category3  | character varying(32) | 

インデックス:
    "akiruno_line_pkey" PRIMARY KEY, btree (fid)
    "spatial_akiruno_line_the_geom" gist (the_geom)
CHECK 制約:
    "enforce_dims_the_geom" CHECK (st_ndims(the_geom) = 2)
    "enforce_geotype_the_geom" CHECK (geometrytype(the_geom) = 'MULTILINESTRING'::text OR the_geom IS NULL)
    "enforce_srid_the_geom" CHECK (st_srid(the_geom) = 2451)

(END):q


GeoServer で akiruno_point と akiruno_line レイヤの「Feature Type Details」を確認します。表示されないときは「Reload feature type」をクリックします。

仮の属性の値を追加します。

nippon_bmi=> SELECT fid, id, name, createdate, lastupdate, category1, category2, category3 from akiruno_point;
 fid | id | name | createdate | lastupdate | category1 | category2 | category3 
-----+----+------+------------+------------+-----------+-----------+-----------
   2 |    |      |            |            |           |           | 
(1 行)

nippon_bmi=> UPDATE akiruno_point SET id = 'a', name = '点2', address = 'aki', createdate = '2014-2-14', lastupdate = '2014-2-14', category1 = 'c1', category2 = 'c2', category3 = 'c3' where fid = 2;
UPDATE 1
nippon_bmi=> SELECT fid, id, name, address, createdate, lastupdate, category1, category2, category3 from akiruno_line;
 fid | id | name | address | createdate | lastupdate | category1 | category2 | category3 
-----+----+------+---------+------------+------------+-----------+-----------+-----------
   3 |    |      |         |            |            |           |           | 

(1 行)
(stdin):q

nippon_bmi=> UPDATE akiruno_line SET id = 'a', name = '線2', address = 'aki', createdate = '2014-2-14', lastupdate = '2014-2-14', category1 = 'c1', category2 = 'c2', category3 = 'c3' where fid = 3;
UPDATE 1

36 - GeoEXT を使用した WFS-T 9 - WFS レイヤの表示

36-9 WFS レイヤの表示
Developing OGC Compliant Web Applications with GeoExt の
3.1. Creating a Synchronized Grid and Map View of WFS Features(http://workshops.boundlessgeo.com/geoext/wfs/grid.html)を参考に WFS レイヤを表示します。
続けて「ol017-nippon_bmi_akiruno_pgis.html」を使います。

属性の一部を表示するようにしました。

user@debian7-vmw:~$ psql nippon_bmi
psql (9.1.11)
"help" でヘルプを表示します.
                                 テーブル "public.akiruno_kukaku"
  カラム   |          型           |                            修飾語                            
-----------+-----------------------+--------------------------------------------------------------
 gid       | integer               | not null default nextval('akiruno_kukaku_gid_seq'::regclass)
 id        | character varying(6)  | 
 uuid      | character varying(28) | 
 presences | double precision      | 
 presencef | double precision      | 
 finished  | double precision      | 
 orggilvl  | character varying(4)  | 
 orgmdid   | character varying(7)  | 
 category  | character varying(4)  | 
 flag      | character varying(4)  | 
 type      | character varying(16) | 
 name      | character varying(12) | 
 code      | character varying(5)  | 
 the_geom  | geometry              | 
インデックス:
    "akiruno_kukaku_pkey" PRIMARY KEY, btree (gid)
CHECK 制約:
    "enforce_dims_the_geom" CHECK (st_ndims(the_geom) = 2)
    "enforce_geotype_the_geom" CHECK (geometrytype(the_geom) = 'MULTIPOLYGON'::text OR the_geom IS NULL)
    "enforce_srid_the_geom" CHECK (st_srid(the_geom) = (-1))

nippon_bmi=> SELECT gid, id, uuid, orggilvl, orgmdid, category, flag, type, name, code from akiruno_kukaku where gid = '1';
 gid |  id  |             uuid             | orggilvl | orgmdid | category | flag |       type       |    name    | code  
-----+------+------------------------------+----------+---------+----------+------+------------------+------------+-------
   1 | K4_1 | fgoid:10-00200-11-6572-94188 | 2500     |         | 表示     | 既存 | 郡市・東京都の区 | あきる野市 | 13228
(1 行)
---
// ここから追加
items.push({
 xtype: "grid",
 ref: "featureGrid",
 title: "Feature Table",
 region: "south",
 height: 150,
 sm: new GeoExt.grid.FeatureSelectionModel(),
 store: new GeoExt.data.FeatureStore({
  fields: [
   {name: "gid", type: "int"},
   {name: "id", type: "string"},
   {name: "orggilvl", type: "string"},
   {name: "orgmdid", type: "string"}, 
   {name: "category", type: "string"},
   {name: "flag", type: "string"},
   {name: "type", type: "string"},
   {name: "name", type: "string"},
   {name: "code", type: "string"}
  ],
  proxy: new GeoExt.data.ProtocolProxy({
   protocol: new OpenLayers.Protocol.WFS({
    url: "/geoserver/ows",
    version: "1.1.0",
    featureType: "akiruno_kukaku",
    featureNS: "http://www.myhome.net/npn",
    srsName: "EPSG:2451"
   }),
  })
  autoLoad: true
 }),
 columns: [
  {header: "gid", dataIndex: "gid"},
  {header: "id", dataIndex: "id"},
  {header: "orggilvl", dataIndex: "orggilvl"},
  {header: "orgmdid", dataIndex: "orgmdid"},
  {header: "category", dataIndex: "category"},
  {header: "flag", dataIndex: "flag"},
  {header: "type", dataIndex: "type"},
  {header: "name", dataIndex: "name"},
  {header: "code", dataIndex: "code"}
 ],
 bbar: []
});
var vectorLayer = new OpenLayers.Layer.Vector("Editable features");
Ext.onReady(function() {
 app.mapPanel.map.addLayer(vectorLayer);
 app.featureGrid.store.bind(vectorLayer);
 app.featureGrid.getSelectionModel().bind(vectorLayer);
});
// ここまで
</script>
---

2009年11月9日月曜日

OpenLayers 24e Jugl Template Library Attributes編

jugl:attributes の例です。
jugl:reapeat の例にもありましたが、ここでは、画像を表示する例をみてみます。
前述の Repeat の処理コード2の続きに追加

<h2>Attributes</h2>
<!-- jugl:attributes を使うマークアップ3 -->
<div id="template_id3">
<img jugl:attributes="src source; alt description" />
<p jugl:attributes="class addClass && 'foo'">
This paragraph will only be given a class name if addClass is true.
<p>
</div>
<!-- 処理コード3 -->
<script type="text/javascript">
var source = "./img/marker-green.png";
var description = "my image";
var addClass = false;
// if true, the paragraph will get 'foo' class name
(new jugl.Template("template_id3")).process();
</script>
</body>
</html>

要素上(タグ中)の属性を設定するために、属性名(src, alt)と新しい属性値になる式(source, description)を用いて jugl:attribute 属性を追加します。
もし、式が偽なら、新しい属性は設定されません。
<img> タグの jugl:attributes="src source; alt description" は、タグの属性となるので、タグ中に処理されたデータが反映されます。
addClass && 'foo' の式は、addClass が真(true)のときだけ foo の値となります。
確認のため次のコードを <head> 内の <style> に追加してください。

<style>
---
p.foo {
background-color: #ffcccc;
}
</style>

<div id="template_id3">
<img jugl:attributes="src source; alt description" />
<p jugl:attributes="class addClass && 'foo'">
This paragraph will only be given a class name if addClass is true.
<p>
</div>
</body>
</html>

このテンプレートは次のコードで処理されます。

<script type="text/javascript">
var source = "path/to/image.png";
var description = "my image";
var addClass = false;
// if true, the paragraph will get 'foo' class name(背景が赤くなります)
(new jugl.Template("template_id3")).process();
</script>

テンプレートの処理をした後は、マークアップは次のようになります:
画像は、var addClass = true; にしてみました。

<div id="template_id3">
<img src="path/to/image.png" alt="my image" />
<p>
This paragraph will only be given a class name if addClass is true.
<p>
</div>




Animator.js については、

BernieCode Animator.js
http://berniecode.com/writing/animator.html

を参照してください。
英語がわからなくても、コードと効果のサンプルがあるので楽しく理解できると思います。