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

2016年2月15日月曜日

GeoExt3-dev 8 - Popup Example 2

8-2 JavaScript ファイルの作成
「gx-popup.js(8-geoext3.js)」は、マップを表示するための JavaScript ファイルです。

「8-geoext3.js」
Ext.require([
/** require( expressions, [fn], [scope] )
 * Loads all classes by the given names and all their 
 * direct dependencies; optionally executes the given 
 * callback function when finishes, within the optional 
 * scope.
 * 指定された名前とそのすべての直接依存によって、すべて
 * のクラスをロードします。任意の範囲内で、終了するとき
 * に任意で与えられたコールバック関数を実行します。
 * (GeoExt doc[w/ext])
 */
 'GeoExt.component.Map',
 /** GeoExt.component.Map
  * The map component and a panel side by side
  * map component(マップコンポーネント)とパネルの位置関
  * 係(並び)。
  * (GeoExt doc[w/ext])
  */
]);
var olMap,
 mapComp,
 popup;
Ext.application({
/** Ext.app.Application
 * Represents an Ext JS application, which is typically 
 * a single page app using a Viewport.
 * An application consists of one or more Views. The 
 * behavior of a View is managed by its corresponding 
 * ViewController and ViewModel.
 * Global activities are coordinated by Controllers 
 * which are ultimately instantiated by an instance 
 * of this (or a derived) class.
 * 通常、ビューポートを使用して1つのページの app である 
 * ExtJS アプリケーションを表します。
 * アプリケーションは、1つまたは複数の View で構成されて
 * います。View の動作は、その対応する ViewController 
 * と ViewModel によって管理されます。
 * グローバルな動作は、このインスタンス(または派生)
 * クラスで最終的にインスタンス化されている Controller 
 * によって調整されます。(GeoExt doc[w/ext])
 */
 name: 'Popup',
 /** name : String
  * The name of your application. This will also be the 
  * namespace for your views, controllers models and 
  * stores. Don't use spaces or special characters in 
  * the name. Application name is mandatory.
  * アプリケーションの名前。これはまた、views、controllers 
  * models と stores の名前空間になります。name には
  * スペースや特殊文字を使用しないでください。アプリケー
  * ション名は必須です。初期値は、''。
  * (GeoExt doc[w/ext])
  */
 launch: function() {
 /** launch( profile ) : Booleantemplate
  * Called automatically when the page has completely 
  * loaded. This is an empty function that should be 
  * overridden by each application that needs to take 
  * action on page load.
  * ページが完全にロードされたときに自動的に呼び出されます。
  * これは、ページのロード時にアクションを実行する必要があ
  * る各アプリケーションによって上書きされなければならない
  * 空の関数です。(GeoExt doc[w/ext])
  */
  var description;
  olMap = new ol.Map({
   layers: [
    new ol.layer.Tile({
    /** ol.layer.Tile 
     * For layer sources that provide pre-rendered, tiled 
     * images in grids that are organized by zoom levels 
     * for specific resolutions. 
     * プリレンダリング(事前描画)を提供するレイヤソースの
     * ための、特定の解像度でのズームレベルによって編成され
     * ているグリッドのタイルイメージ。(ol3 API)
     */
     source: new ol.source.Stamen({
     /** ol.source.Stamen
      * Layer source for the Stamen tile server.
      * Stamen タイルサーバのレイヤソース。(ol3 API)
      * (2 - ol3ex 24b - Stamen example 1 参照)
      */
      layer: 'watercolor'
     })
    }),
    new ol.layer.Tile({
     source: new ol.source.Stamen({
      layer: 'terrain-labels'
     })
    })
   ],
   view: new ol.View({
    center: ol.proj.fromLonLat( [-122.416667, 37.783333] ),
    /** ol.proj.fromLonLat(coordinate, opt_projection)
     * Transforms a coordinate from longitude/latitude to a 
     * different projection.
     * 緯度/経度座標から異なる投影に変換します。(ol3 API)
     */
    zoom: 12
   })
  });
  popup = Ext.create('GeoExt.component.Popup', {
  /** create( [name], [args] ) : Object
   * Instantiate a class by either full name, alias or 
   * alternate name.
   * If Ext.Loader is enabled and the class has not been 
   * defined yet, it will attempt to load the class via 
   * synchronous loading.
   * 完全な名前、別名または代替名のいずれかによってクラスを
   * インスタンス化します。
   * Ext.Loader が有効になっており、クラスがまだ定義されて
   * いない場合は、同期ロードを経由してクラスをロードしよう
   * とします。(GeoExt doc[w/ext)
   */
  /** GeoExt.component.Popup
   * An GeoExt.component.Popup can be used to displays a 
   * popup over the map.
   * GeoExt.component.Popup はマップ(map)上にポップアップ
   * を表示するために使用されます。
   * (GeoExt doc[w/ext])
   */
   map: olMap,
   width: 140
   /** width : Number|String
    * The width of this component. A numeric value will be 
    * interpreted as the number of pixels; a string value 
    * will be treated as a CSS value with units.
    * このコンポーネントの幅。数値は、ピクセル数として解釈され
    * ます。文字列値は単位でCSS値として扱われます。
    * (GeoExt doc[w/ext])
    */
  });
  mapComp = Ext.create('GeoExt.component.Map', {
   title: 'GeoExt.component.Map Example',
   /** title : String
    * The title text to be used to display in the Panel 
    * Header. Or a config object for a Panel Title.
    * Panel Header に表示するために使用される title テキ
    * スト。または Panel Title のための config オブジェ
    * クト。(GeoExt doc[w/ext)
    */
   map: olMap,
   region: 'center',
   /** region : "north"/"south"/"east"/"west"/"center"
    * Defines the region inside border layout.
    * ボーダレイアウト内の領域を遅疑します。
    * (GeoExt doc[w/ext])
    */
   pointerRest: true,
   /** pointerRest : Boolean
    * A boolean flag to control whether the map component 
    * will fire the events pointerrest and pointerrestout. 
    * If this is set to false (the default), no such events 
    * will be fired.Whether the component shall provide the 
    * pointerrest and pointerrestout events.
    * Defaults to: false
    * マップコンポーネントが pointerrest と pointerrestout 
    * イベントを発生するかどうかを制御するための boolean フラ
    * グ。これが false に設定されている(デフォルト)場合は、
    * コンポーネントが pointerrest と pointerrestoutイベント
    * を提供しなければならないかどうかというようなイベントは発
    * 生されません。
    * デフォルト:false
    * (GeoExt doc[w/ext])
    */
   pointerRestInterval: 750,
   /** pointerRestInterval : Number
    * The amount of milliseconds after which we will 
    * consider a rested pointer as pointerrest. Only 
    * relevant if pointerRest is true.The interval in 
    * milliseconds.
    * Defaults to: 1000
    * pointerrest として停止ポインタを考慮した後のミリ秒単位の
    * 量。pointerRest が true の場合のみ関連性があります。ミリ
    * 秒単位の間隔。
    * デフォルト: 1000
    * (GeoExt doc[w/ext])
    */
   pointerRestPixelTolerance: 5
   /** pointerRestPixelTolerance : Number
    * The amount of pixels that a pointer may move in both 
    * vertical and horizontal direction, and still be 
    * considered to be a pointerrest. Only relevant if 
    * pointerRest is true.The tolerance in pixels.
    * Defaults to: 3
    * ポインタはまだ両方の垂直および水平方向に移動でき、そして 
    * pointerrest であると考られるピクセルの量。pointerRest 
    * が true の場合のみ関連性がある。ピクセル単位の許容範囲。
    * デフォルト:3
    * (GeoExt doc[w/ext])
    */
  });
  // Add a pointerrest handler to the map component to 
  // render the popup.
  // ポップアップをレンダリングするためにマップコンポーネント
  // にpointerrestハンドラを追加します。
  mapComp.on('pointerrest', function(evt) {
  /** on( eventName, [fn], [scope], [options], [order] ) : 
   * Object
   * The on method is shorthand for addListener.
   * on メソッドは addListener の短縮形。
   * (GeoExt doc[w/ext])
   */
   var coordinate = evt.coordinate,
   /** coordinate{ol.Coordinate}
    * The coordinate of the original browser event.
    * オリジナルブラウザイベントの coordinate。(ol3 API)
    */
   hdms = ol.coordinate.toStringHDMS(ol.proj.transform(
    coordinate, 'EPSG:3857', 'EPSG:4326'));
   /** ol.coordinate.toStringHDMS(coordinate)
    * Format a geographic coordinate with the hemisphere, 
    * degrees, minutes, and seconds.
    * 半球、度、分、秒で地理座標をフォーマットします。
    * (ol3 API)
    */
   /** ol.proj.transform(coordinate, source, destination)
    * Transforms a coordinate from source projection to 
    * destination projection. This returns a new coordinate 
    * (and does not modify the original).
    * ソース投影から変換先投影に座標変換します。これは、新しい座
    * 標を返します(オリジナルを変更しません)。(ol3 API)
    */
   // Insert a linebreak after either N or S in hdms
   // hdms の N または S いずれかの後に改行を挿入します。
   hdms = hdms.replace(/([NS])/, '$1<br>');
   /** String.prototype.replace()
    * replace() メソッドは、pattern にマッチした文字列の一部ま
    * たは全てを replacement で置き換えた新しい文字列を返しま
    * す。pattern は文字列または RegExp、replacement は文字列
    * または各マッチで呼び出される関数です。
    * str.replace(pattern, replacement[, flags])
    * (MDN[https://developer.mozilla.org/ja/docs/Web/
    * JavaScript/Reference/Global_Objects/String/replace])
    */
   // set content and position popup
   // コンテンツを設定しポップアップを配置します。
   popup.setHtml('<p><strong>Pointer rested on</strong>' +
    '<br /><code>' + hdms + '</code></p>');
   /** setHtml( html )private
    * Parameters - html : Object(GeoExt doc[w/ext])
    */
   popup.position(coordinate);
   /** position(coordinate)
    * (Re-)Positions the popup to the given coordinates.
    * 指定された座標にポップアップを配置します。
    * (GeoExt doc[w/ext])
    */
   popup.show();
   /** show( this, eOpts )
    * Fires after the component is shown when calling the 
    * show method.
    * show メソッドを呼び出すときにコンポーネントが表示された
    * 後発生します。
    * (GeoExt doc[w/ext])
    */
  });
  // hide the popup once it isn't on the map any longer
  //それがマップ(map)上にすでにないときポップアップを隠します。
  mapComp.on('pointerrestout', popup.hide, popup);
  description = Ext.create('Ext.panel.Panel', {
  /** Ext.panel.Panel
   * Panel is a container that has specific functionality 
   * and structural components that make it the perfect 
   * building block for application-oriented user interfaces.
   * Panels are, by virtue of their inheritance from 
   * Ext.container.Container, capable of being configured 
   * with a layout, and containing child Components.
   * パネルは、特定の機能とそれアプリケーション指向のユーザ
   * インターフェイスに最適なビルディングブロックにする構造
   * 的要素を持っているコンテナです。パネルは、
   * Ext.container.Container からの継承のおかげで、layout 
   * で構成し、子コンポーネントを含むことができます。
   * (GeoExt doc[w/ext])
   */
   contentEl: 'description',
   /** contentEl : String
    * Specify an existing HTML element, or the id of an 
    * existing HTML element to use as the content for this 
    * component.
    * This config option is used to take an existing HTML 
    * element and place it in the layout element of a new 
    * component (it simply moves the specified DOM element 
    * after the Component is rendered to use as the content.
    * 既存のHTMLエレメントを指定するか、既存のHTMLエレメン
    * トの id は、このコンポーネントのコンテンツとして使用
    * します。
    * Component(コンポーネント)が 、content(コンテンツ)
    * として使用するためにレンダリングされた後に、この設定オ
    * プションは、既存のHTMLエレメントを取得し、新しい 
    * component(コンポーネント)の layout(レイアウト)エレ
    * メントでそれを配置するために使用されます(それは単に指定
    * された DOM エレメントを移動させます)。
    * (GeoExt doc[w/ext)
    */
   title: 'Description',
   region: 'east',
   width: 300,
   border: false,
   /** border : Boolean
    * Specify as false to render the Panel with zero width 
    * borders.
    * Leaving the value as true uses the selected theme's 
    * $panel-border-width.
    * Defaults to false when using or extending Neptune.
    * Defaults to: true.
    * ゼロ幅の border(境界線)でパネルを描画するため false 
    * を指定します。
    * true として値を残すためには、選択されたテーマ 
    * $panel-border-width を使用します。
    * ネプチューン(Neptune Theme)を使用するか拡張すると
    * き、デフォルトは false です。
    * デフォルトは:true。
    * (GeoExt doc[w/ext)
    */
   bodyPadding: 5
   /** bodyPadding : Number/String
    * A shortcut for setting a padding style on the body 
    * element. The value can either be a number to be 
    * applied to all sides, or a normal css string 
    * describing padding.
    * bodyエレメントにパディングスタイルを設定するための
    * ショートカット。値は、すべての側面に適用される数字、
    * または通常のCSSの文字列記述パディングのいずれかにで
    * きます。
    * (GeoExt doc[w/ext)
    */
  });
  Ext.create('Ext.Viewport', {
  /** Ext.Viewport (Ext.container.Viewport)
   * A specialized container representing the viewable 
   * application area (the browser viewport).
   * The Viewport renders itself to the document body, 
   * and automatically sizes itself to the size of the 
   * browser viewport and manages window resizing. There 
   * may only be one Viewport created in a page.
   * 表示可能なアプリケーション領域(ブラウザのビューポート)
   * を表す特殊なコンテナ。
   * Viewport は、document body にそれ自身をレンダリングし、
   * 自動的に自身のサイズをブラウザのビューポートのサイズにし、
   * ウィンドウのサイズ変更を管理します。1ページに作成した
   * ビューポートは一つだけ設定できます。
   * (GeoExt doc[w/ext])
   */
   layout: "border",
   /** layout : Ext.enums.Layout/Object
    * Important: In order for child items to be correctly 
    * sized and positioned, typically a layout manager must 
    * be specified through the layout configuration option.
    * The sizing and positioning of child items is the 
    * responsibility of the Container's layout manager 
    * which creates and manages the type of layout you have 
    * in mind. 
    * 重要:子アイテムが正しいサイズと配置されるためには、
    * 一般的にレイアウトマネージャは、layout configuration 
    * option(レイアウト設定オプション)を使用して指定する
    * 必要があります。
    * 子アイテムのサイズと位置は、レイアウトの種類を管理す
    * るContainer's layout manager(コンテナレイアウトマ
    * ネージャ)の役割です。
    * (GeoExt doc[w/ext)
    */
   items: [
   /** items : Object/Object[]
    * A single item, or an array of child Components to be 
    * added to this container
    * Unless configured with a layout, a Container simply 
    * renders child Components serially into its 
    * encapsulating element and performs no sizing or 
    * positioning upon them.
    * 単一の item(アイテム)、または子 Compornents(コン
    * ポーネント)の配列は、このコンテナに追加します。
    * layout(レイアウト)で構成されていない限り、Container
    * (コンテナ)は単に、子 Compornents(コンポーネント)
    * をそのカプセル化要素に直列にレンダリングし、それらに
    * サイズや位置調整も実行しません。
    * (GeoExt doc[w/ext)
    */
    mapComp,
    description
   ]
  });
 }
});

GeoExt3-dev 8 - Popup Example 1

GeoExt3(https://geoext.github.io/geoext3/)の例(Examoles)をみていきます。

8 - Popup Example
「Popup(gx-popup.html)」(「Examples」の「Popup」)を参考に地図を表示してみます。
説明に次のようにあります。

This example shows a simple popup showing the position that was hovered.

To achieve this effect, the GeoExt.component.Map is instantiated with pointerRest: true, so that the events pointerrest and pointerout become available. Whenever pointerrest is fired, an instance of GeoExt.panel.Popup is positioned and its HTML updated.

この例では、ホバーした位置を示す簡単なポップアップが表示されます。

この効果を達成するために、GeoExt.component.Map は pointerRest:true でインスタンス化され、それによって イベント pointerrest と pointerout は利用可能になります。pointerrest が起動されるたびに、 GeoExt.panel.Popup のインスタンスが配置され、そのHTMLが更新されます。
8-1 HTML ファイルの作成
1 NetBeans を起動します。









2 「プロジェクト」ペインでツリーを geoext3proj -> サイト・ルート -> js -> libs -> geoext3-master -> examples -> popup とクリックして展開し gx-popup.html をダブルクリックして開きます。gx-popup.js もダブルクリックして開きます。



3 「新規ファイル」ボタンをクリックします。

4 ステップ「1.ファイル・タイプを選択」の「カテゴリ」で「HTML5」、「ファイルタイプ」で「HTMLファイル」を選択して「次>」ボタンをクリックします。






5 「new HTML ファイル」ダイアログで「ファイル名」を「8-geoext3」と入力して「終了」ボタンをクリックします。







保存フォルダを変更するときは、「フォルダ」右の「参照」ボタンをクリックして「フォルダを参照」で「geoext3proj-サイト・ルート」をクリックして選択し「フォルダを選択」ボタンをクリックします。









6 「gx-popup.html」の内容をコピーして「8-geoext3.html」に貼り付け、修正します。

7 同じように、「新規ファイル」ボタンをクリックし、ステップ「1.ファイル・タイプを選択」の「カテゴリ」で「HTML5」、「ファイルタイプ」で「JavaScriptファイル」をクリックして選択し「次>」ボタンをクリック。「ファイル名」を「8-geoext3」と入力して「終了」ボタンをクリック。「gx-popup.js」の内容をコピーして貼り付け、修正します。



「index.html」
<html>
 <head>
  <title>TODO supply a title</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
 </head>
 <body>
  <div>TODO write content</div>
  <div><a href="./3-geoext3.html">3-geoext3.html</a></div>
  <div><a href="./4-geoext3.html">4-geoext3.html</a></div>
  <div><a href="./5-geoext3.html">5-geoext3.html</a></div>
  <div><a href="./6-geoext3.html">6-geoext3.html</a></div>
  <div><a href="./7-geoext3.html">7-geoext3.html</a></div>
  <div><a href="./8-geoext3.html">8-geoext3.html</a></div>
 </body>
</html>


「8-geoext3.html」
<!DOCTYPE HTML>
<html>
 <head>
  <meta charset=utf-8" />
  <title>Popup Example</title>
  <link rel="stylesheet" type="text/css" href="http://openlayers.org/en/master/css/ol.css" />
  <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/classic/theme-crisp/resources/theme-crisp-all.css" />
  <!-- <link rel="stylesheet" type="text/css" href="../../resources/css/gx-popup.css" /> -->
  <link rel="stylesheet" type="text/css" href="./js/libs/geoext3-master/resources/css/gx-popup.css" />
  <style>
   .gx-popup p {
    padding: 5px 5px 0 5px;
    border-radius: 7px;
    background-color: rgba(255,255,255,0.85);
    border: 3px solid white;
    margin: 0;
    text-align: center;
   }
  </style>
 </head>
 <body>
  <div id='description'>
   <p>This example shows a simple popup showing the position 
    that was hovered.</p>
   <p>To achieve this effect, the 
    <code>GeoExt.component.Map</code> is instantiated with 
    <code>pointerRest: true</code>, so that the events 
    <code>pointerrest</code> and <code>pointerout</code> 
    become available. Whenever <code>pointerrest</code> 
    is fired, an instance of <code>GeoExt.panel.Popup</code> 
    is positioned and its HTML updated.</p>
   <p>Have a look at 
    <!-- <a href="gx-popup.js">gx-popup.js</a> --> 
    <a href="8-geoext3.js">8-geoext3.js</a> 
    to see how this is done.</p>
  </div>
  <script src="http://openlayers.org/en/master/build/ol.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/extjs/6.0.0/ext-all.js"></script>
  <script>
   Ext.Loader.setConfig({
   /** ExtLoader
    * This class provides dynamic loading support for 
    * JavaScript classes. Application code does not 
    * typically need to call Ext.Loader except perhaps 
    * to configure path mappings when not using Sencha 
    * Cmd.
    * このクラスは、JavaScript クラスの動的ローディン
    * グサポートを提供します。アプリケーションコードは、
    * Sencha Cmd を使用しないでパスマッピングを設定する
    * 大方の場合以外 通常、Ext.Loader を呼び出す必要は
    * ありません。
    * (GeoExt doc[w/ext])
    */
   /** setConfig(config) 
    * Set the configuration for the loader. This should 
    * be called right after ext-(debug).js is included 
    * in the page, and before Ext.onReady. i.e:
    * ローダの設定を設定します。これは、ext-(debug).js 
    * がページに読み込まれる後と Ext.onReady の前に正し
    * く呼び出さなければなりません。
    * (GeoExt doc[w/ext])
    */
    enabled: true,
    /** nabled : Boolean
     * Whether or not to enable the dynamic dependency 
     * loading feature. Defaults to: true.
     * 動的依存関係のロード機能の有効または無効。
     * デフォルト: true
     * (GeoExt doc[w/ext])
     */
    paths: {
    /** paths : Object
     * The mapping from namespaces to file paths.
     * Note that all relative paths are relative to the 
     * current HTML document. If not being specified, 
     * for example, Other.awesome.Class will simply be 
     * loaded from "./Other/awesome/Class.js".
     * 名前空間からファイルパスへのマッピング。すべて
     * の相対パスは、現在のHTMLドキュメントに対して相
     * 対的であることに注意してください。指定されてい
     * ない場合には、例えば、Other.awesome.Class は単
     * に「./Other/awesome/Class.js」からロードされま
     * す。
     * (GeoExt doc[w/ext])
     */
     // 'GeoExt': '../../src/'
     'GeoExt': './js/libs/geoext3-master/src/'
    }
   });
  </script>
  <!-- <script src="gx-popup.js"></script> -->
  <script src="8-geoext3.js"></script>
 </body>
</html>

2014年11月30日日曜日

2 - ol3ex 39b - Vector labels example 2

「vector-labels.js(239-ol3ex.js)」は、マップを表示するための JavaScript ファイルです。

「239-ol3ex.js」の内容
var myDom = {
 points: {
  text: document.getElementById('points-text'),
  align: document.getElementById('points-align'),
  baseline: document.getElementById('points-baseline'),
  rotation: document.getElementById('points-rotation'),
  font: document.getElementById('points-font'),
  weight: document.getElementById('points-weight'),
  size: document.getElementById('points-size'),
  offsetX: document.getElementById('points-offset-x'),
  offsetY: document.getElementById('points-offset-y'),
  color: document.getElementById('points-color'),
  outline: document.getElementById('points-outline'),
  outlineWidth: document.getElementById('points-outline-width'),
  maxreso: document.getElementById('points-maxreso')
 },
 lines: {
  text: document.getElementById('lines-text'),
  align: document.getElementById('lines-align'),
  baseline: document.getElementById('lines-baseline'),
  rotation: document.getElementById('lines-rotation'),
  font: document.getElementById('lines-font'),
  weight: document.getElementById('lines-weight'),
  size: document.getElementById('lines-size'),
  offsetX: document.getElementById('lines-offset-x'),
  offsetY: document.getElementById('lines-offset-y'),
  color: document.getElementById('lines-color'),
  outline: document.getElementById('lines-outline'),
  outlineWidth: document.getElementById('lines-outline-width'),
  maxreso: document.getElementById('lines-maxreso')
 },
 polygons: {
  text: document.getElementById('polygons-text'),
  align: document.getElementById('polygons-align'),
  baseline: document.getElementById('polygons-baseline'),
  rotation: document.getElementById('polygons-rotation'),
  font: document.getElementById('polygons-font'),
  weight: document.getElementById('polygons-weight'),
  size: document.getElementById('polygons-size'),
  offsetX: document.getElementById('polygons-offset-x'),
  offsetY: document.getElementById('polygons-offset-y'),
  color: document.getElementById('polygons-color'),
  outline: document.getElementById('polygons-outline'),
  outlineWidth: document.getElementById('polygons-outline-width'),
  maxreso: document.getElementById('polygons-maxreso')
 }
};
var getText = function(feature, resolution, dom) {
 var type = dom.text.value;
 var maxResolution = dom.maxreso.value;
 var text = feature.get('name');
 /** get(key)
  * Gets a value.
  * (ol3 API[説明は Stable Only のチェックを外すと表示])
  */
 if (resolution > maxResolution) {
  text = '';
 } else if (type == 'hide') {
  text = '';
 } else if (type == 'shorten') {
  text = text.trunc(12);
 } else if (type == 'wrap') {
  text = stringDivider(text, 16, '\n');
 }
 return text;
};
var createTextStyle = function(feature, resolution, dom) {
 var align = dom.align.value;
 var baseline = dom.baseline.value;
 var size = dom.size.value;
 var offsetX = parseInt(dom.offsetX.value, 10);
 /** parseInt(string, radix)
  * str: 文字列, radix: 基数(進法)
  * 文字列の引数をパースし、指定された基数の整数を返します。
  * (MDN[https://developer.mozilla.org/ja/docs/Web/
  * JavaScript/Reference/Global_Objects/parseInt])
  */
 var offsetY = parseInt(dom.offsetY.value, 10);
 var weight = dom.weight.value;
 var rotation = parseFloat(dom.rotation.value);
 /** parseFloat()
  * 引数として与えられた文字列を解析し、浮動小数点数を返します。
  * (MDN[https://developer.mozilla.org/ja/docs/Web/
  * JavaScript/Reference/Global_Objects/parseFloat])
  */ 
 var font = weight + ' ' + size + ' ' + dom.font.value;
 var fillColor = dom.color.value;
 var outlineColor = dom.outline.value;
 var outlineWidth = parseInt(dom.outlineWidth.value, 10);
 return new ol.style.Text({
 /** ol.style.Text
  * Set text style for vector features.
  * ベクタフィーチャの文字列のスタイルを設定します。(ol3 API)
  */
  textAlign: align,
  textBaseline: baseline,
  font: font,
  text: getText(feature, resolution, dom),
  fill: new ol.style.Fill({color: fillColor}),
  /** ol.style.Fill 
   * Set fill style for vector features.
   * ベクタフィーチャの塗りつぶしスタイルを設定。(ol3 API)
   */
  stroke: new ol.style.Stroke({color: outlineColor, width: outlineWidth}),
  /** ol.style.Stroke 
   * Set stroke style for vector features. 
   * Note that the defaults given are the Canvas defaults, 
   * which will be used if option is not defined. 
   * The get functions return whatever was entered 
   * in the options;  they will not return the default.
   * ベクタフィーチャのためのストロークスタイルの設定。
   * デフォルトは、オプションが定義されていない場合に使用される
   * Canvas のデフォルトを与えられることに注意してください。 
   * GET機能は、オプションで入力されたものはすべて返します。
   * それらはデフォルトを返しません。(ol3 API)
   */
  offsetX: offsetX,
  offsetY: offsetY,
  rotation: rotation
 });
};
// Polygons
var createPolygonStyleFunction = function() {
 return function(feature, resolution) {
  var style = new ol.style.Style({
  /** ol.style.Style 
   * Base class for vector feature rendering styles.
   * ベクタフィーチャがスタイルを描画するための基本クラス。
   * (ol3 API)
   */
   stroke: new ol.style.Stroke({
   color: 'blue',
   width: 1
  }),
   fill: new ol.style.Fill({
    color: 'rgba(0, 0, 255, 0.1)'
   }),
   text: createTextStyle(feature, resolution, myDom.polygons)
  });
  return [style];
 };
};
var vectorPolygons = new ol.layer.Vector({
/** ol.layer.Vector
 * Vector data that is rendered client-side.
 * クライアント側で描画されるベクタデータ。(ol3 API)
 */
 source: new ol.source.GeoJSON({
 /** ol.source.GeoJSON 
  * Static vector source in GeoJSON format
  * GeoJSON フォーマットの静的ベクタソース。(ol3 API)
  */
  projection: 'EPSG:3857',
  // url: 'data/geojson/polygon-samples.geojson'
  url: 'v3.0.0/examples/data/geojson/polygon-samples.geojson' // 修正
 }),
 style: createPolygonStyleFunction()
});
// Lines
var createLineStyleFunction = function() {
 return function(feature, resolution) {
  var style = new ol.style.Style({
   stroke: new ol.style.Stroke({
    color: 'green',
    width: 2
   }),
   text: createTextStyle(feature, resolution, myDom.lines)
  });
  return [style];
 };
};
var vectorLines = new ol.layer.Vector({
 source: new ol.source.GeoJSON({
  projection: 'EPSG:3857',
  // url: 'data/geojson/line-samples.geojson' // 修正
  url: 'v3.0.0/examples/data/geojson/line-samples.geojson'
 }),
 style: createLineStyleFunction()
});
// Points
var createPointStyleFunction = function() {
 return function(feature, resolution) {
  var style = new ol.style.Style({
   image: new ol.style.Circle({
   /** ol.style.Circle
    * Set circle style for vector features.
    * ベクタフィーチャの円のスタイルを設定。(ol3 API)
    */
    radius: 10,
    fill: new ol.style.Fill({color: 'rgba(255, 0, 0, 0.1)'}),
    stroke: new ol.style.Stroke({color: 'red', width: 1})
   }),
   text: createTextStyle(feature, resolution, myDom.points)
  });
  return [style];
 };
};
var vectorPoints = new ol.layer.Vector({
 source: new ol.source.GeoJSON({
  projection: 'EPSG:3857',
  // url: 'data/geojson/point-samples.geojson' // 修正
  url: 'v3.0.0/examples/data/geojson/point-samples.geojson'
  }),
  style: createPointStyleFunction()
});
var map = new ol.Map({
 layers: [
  new ol.layer.Tile({
  /** ol.layer.Tile 
   * For layer sources that provide pre-rendered, tiled 
   * images in grids that are organized by zoom levels for 
   * specific resolutions. 
   * プリレンダリング(事前描画)を提供するレイヤソースのための、
   * 特定の解像度でのズームレベルによって編成されているグリッドの
   * タイルイメージ。(ol3 API)
   */
   source: new ol.source.MapQuest({layer: 'osm'})
   /** ol.source.MapQuest
    * Layer source for the MapQuest tile server.
    * MapQuest タイルサーバのレイヤソース。(ol3 API
    * 2 - ol3ex 23b - MapQuest example 2 参照)
    */
  }),
  vectorPolygons,
  vectorLines,
  vectorPoints
 ],
 target: 'map',
 view: new ol.View({
  center: [-8161939, 6095025],
  zoom: 8
 })
});
$('#refresh-points').click(function() {
/** .click()
 * Bind an event handler to the "click" JavaScript event, 
 * or trigger that event on an element.
 * "click" JavaScript イベントにイベントハンドラをバインド、
 * または要素の上でのイベントをトリガします。
 * (jQuery API Doc.[http://api.jquery.com/click/])
 */
 vectorPoints.setStyle(createPointStyleFunction());
});
$('#refresh-lines').click(function() {
 vectorLines.setStyle(createLineStyleFunction());
});
$('#refresh-polygons').click(function() {
 vectorPolygons.setStyle(createPolygonStyleFunction());
});
/**
 * @param {number} n The max number of characters to keep.
 *  (保持する最大文字数)
 * @return {string} Truncated string.
 *  (切り捨てられた文字列)
 */
/** 「@param」
 * The @param tag provides the name, type, and 
 * description of a function parameter.
 * The @param tag requires you to specify the name of 
 * the parameter you are documenting. You can also 
 * include the parameter's type, enclosed in curly 
 * brackets, and a description of the parameter.
 * @paramタグは、関数パラメータの名前と型、説明を提供します。
 * @paramタグを使用すると、文書化されたパラメータの名前を
 * 指定する必要があります。また、パラメータのタイプと、中括弧
 * で囲まれたおよびパラメータの説明を含めることができます。
 * (@use JSDoc [http://usejsdoc.org/tags-param.html])
 */
/** @return(@returns と同義)
 * The @returns tag documents the value that a function 
 * returns.
 * @returns タグは、関数が返す値について説明します。
 * (@use JSDoc [http://usejsdoc.org/tags-returns..html])
 */
String.prototype.trunc = String.prototype.trunc ||
 function(n) {
  return this.length > n ? this.substr(0, n - 1) + '...' : this.substr(0);
  /** String.prototype.substr()
   * The substr() method returns the characters in a 
   * string beginning at the specified location through 
   * the specified number of characters.
   * substr()メソッドは、文字列内の指定した位置から始まり、指定
   * した文字数のまでの文字を返します。
   * (MDN[https://developer.mozilla.org/en-US/docs/Web/
   * JavaScript/Reference/Global_Objects/String/substr])
   */
};
// http://stackoverflow.com/questions/14484787/wrap-text-in-javascript
function stringDivider(str, width, spaceReplacer) {
 if (str.length > width) {
  var p = width;
  for (; p > 0 && (str[p] != ' ' && str[p] != '-'); p--) {
  }
  if (p > 0) {
   var left;
   if (str.substring(p, p + 1) == '-') {
   /** String.prototype.substring()
    * The substring() method returns a subset of a string 
    * between one index and another, or through the end of 
    * the string.
    * substring()メソッドは、インデックス間の文字列のサブセッ
    * ト、または、文字列の終わりまでを返します。
    */
    left = str.substring(0, p + 1);
   } else {
    left = str.substring(0, p);
   }
   var right = str.substring(p + 1);
   return left + spaceReplacer + stringDivider(right, width, spaceReplacer);
  }
 }
 return str;
}

2 - ol3ex 38b - Popup example 2

「popup.js(238-ol3ex.js)」は、マップを表示するための JavaScript ファイルです。

「238-ol3ex.js」の内容
/**
 * Elements that make up the popup.
 * ポップアップを作成するエレメント。
 */
var container = document.getElementById('popup');
var content = document.getElementById('popup-content');
var closer = document.getElementById('popup-closer');
/**
 * Add a click handler to hide the popup.
 * @return {boolean} Don't follow the href.
 * ポップアップを隠すクリックハンドラを追加。
 * @return {boolean}(戻り値{Boolean 型}) 
 *     href の後にt付けないでください。
 */
/** @return(@returns と同義)
 * The @returns tag documents the value that a function 
 * returns.
 * @returns タグは、関数が返す値について説明します。
 * (@use JSDoc [http://usejsdoc.org/tags-returns..html])
 */
closer.onclick = function() {
/** GlobalEventHandlers.onclick
 * The onclick property returns the click event 
 * handler code on the current element.
 * onclick プロパティは、現在の要素の click イベント
 * ハンドラのコードを返します。
 * (MDN[https://developer.mozilla.org/en-US/
 * docs/Web/API/GlobalEventHandlers.onclick])
 */
 container.style.display = 'none';
 closer.blur();
 /** HTMLElement.blur()
  * The HTMLElement.blur() method removes 
  * keyboard focus from the current element.
  * HTMLElement.blur()メソッドは、現在の要素から
  * キーボードフォーカスを削除します。
  * (MDN[https://developer.mozilla.org/en-US/
  * docs/Web/API/HTMLElement.blur])
  */
 return false;
};
/**
 * Create an overlay to anchor the popup to the map.
 * マップにポップアップを固定するためのオーバーレイを作成します。
 */
var overlay = new ol.Overlay({
/** ol.Overlay 
 * Like ol.control.Control, Overlays are visible widgets. 
 * Unlike Controls, they are not in a fixed position on 
 * the screen, but are tied to a geographical coordinate, 
 * so panning the map will move an Overlay but not a Control.
 * ol.control.Controlと同じように、オーバーレイは、目に見える
 * ウィジェットです。コントロールとは異なり、それらは画面上の
 * 固定された位置にありませんが、地理座標に関連付けられている
 * ので、オーバーレイを移動しますが、コントロールできない
 * マップをパンします。(ol3 API)
 */
 element: container
});
/**
 * Create the map.
 */
var map = new ol.Map({
 layers: [
  new ol.layer.Tile({
  /** ol.layer.Tile 
   * For layer sources that provide pre-rendered, tiled 
   * images in grids that are organized by zoom levels for 
   * specific resolutions. 
   * プリレンダリング(事前描画)を提供するレイヤソースのための、
   * 特定の解像度でのズームレベルによって編成されているグリッドの
   * タイルイメージ。(ol3 API)
   */
   source: new ol.source.TileJSON({
   /** ol.source.TileJSON 
    * Layer source for tile data in TileJSON format.
    * TileJSON フォーマットのタイルデータのためのレイヤソース。
    *(ol3 API)
    */
    url: 'http://api.tiles.mapbox.com/v3/' +
     'mapbox.natural-earth-hypso-bathy.jsonp',
    crossOrigin: 'anonymous'
   })
  })
 ],
 renderer: exampleNS.getRendererFromQueryString(),
 //'example-behavior.js' により URL にある renderer を返します
 overlays: [overlay],
 target: 'map',
 view: new ol.View({
  center: [0, 0],
  zoom: 2
 })
});
/**
 * Add a click handler to the map to render the popup.
 * ポップアップをレンダリングするためにマップにクリックハンドラ
 * を追加します。
 */
map.on('click', function(evt) {
/** on
 * Listen for a certain type of event.
 * あるタイプのイベントをリッスンします。(ol3 API)
 */
 var coordinate = evt.coordinate;
 var hdms = ol.coordinate.toStringHDMS(ol.proj.transform(
 /** ol.coordinate.toStringHDMS()
  * Returns: Hemisphere, degrees, minutes and seconds.
  * (ol3 API)
  */
 /** ol.proj.transform(coordinate, source, destination)
  * Transforms a coordinate from source projection to 
  * destination projection. This returns a new coordinate 
  * (and does not modify the original).
  * ソース投影から変換先投影に座標変換します。これは、新しい座標
  * を返します(オリジナルを変更しません)。(ol3 API)
  */
  coordinate, 'EPSG:3857', 'EPSG:4326'));
  overlay.setPosition(coordinate);
  /** setPosition
   * Set the position for this overlay.
   * このオーバーレイに位置を設定します。(ol3 API)
   */
  content.innerHTML = '<p>You clicked here:</p><code>' + hdms +
  '</code>';
  container.style.display = 'block';
});

2 - ol3ex 38a - Popup example 1

「Popup example(popup.html)」を参考に地図を表示してみます。

HTML ファイルの作成
a Eclipse のメニューの「ファイル」->「ファイルを開く」をクリックします。





b 「ファイルを開く」ウィンドウで、「user」->「mapsite」->「ol3proj」->「v3.0.0」->「examples」->「popup.html」をクリックして選択し、「OK」ボタンをクリックします。
同じように「popup.js」を開きます。





c メニューの「ファイル」->「新規」 -> 「ファイル」をクリックします。



d 「ファイル」ウィンドウで「ol3proj」をクリックして選択し、「ファイル名」を「238-ol3ex.html」と入力し、「次へ」ボタンをクリックします。








e 「File Template」ウィンドウで「HTML 5 Template」をクリックして選択し、「OK」ボタンをクリックします。











f 「popup.html」の内容をコピーして「238-ol3ex.html」に貼り付け、修正します。
g 同じように、新規に「238-ol3ex.js」ファイルを作成し、「File Template」ウィンドウで「JavaScript Template」をクリックして選択し、「完了」ボタンをクリックして、「popup.js」の内容をコピーして貼り付け、修正します。「popup-require.js」も「238-ol3ex-require.js」に貼り付けます。


「238-ol3ex.html」
<!doctype html>
<html lang="en">
 <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="chrome=1">
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<!--
  <link rel="stylesheet" href="../css/ol.css" type="text/css">
  <link rel="stylesheet" href="../resources/bootstrap/css/bootstrap.min.css" type="text/css">
  <link rel="stylesheet" href="../resources/layout.css" type="text/css">
  <link rel="stylesheet" href="../resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
-->
  <!-- ディレクトリ修正 -->
  <link rel="stylesheet" href="v3.0.0/css/ol.css" type="text/css">
  <link rel="stylesheet" href="v3.0.0/resources/bootstrap/css/bootstrap.min.css" type="text/css">
  <link rel="stylesheet" href="v3.0.0/resources/layout.css" type="text/css">
  <link rel="stylesheet" href="v3.0.0/resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
  <title>Vector Icon example</title>
  <style type="text/css">
   .ol-popup {
    display: none;
    position: absolute;
    background-color: white;
    -moz-box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    -webkit-filter: drop-shadow(0 1px 4px rgba(0,0,0,0.2));
    filter: drop-shadow(0 1px 4px rgba(0,0,0,0.2));
    padding: 15px;
    border-radius: 10px;
    border: 1px solid #cccccc;
    bottom: 12px;
    left: -50px;
   }
   .ol-popup:after, .ol-popup:before {
    top: 100%;
    border: solid transparent;
    content: " ";
    height: 0;
    width: 0;
    position: absolute;
    pointer-events: none;
   }
   .ol-popup:after {
    border-top-color: white;
    border-width: 10px;
    left: 48px;
    margin-left: -10px;
   }
   .ol-popup:before {
    border-top-color: #cccccc;
    border-width: 11px;
    left: 48px;
    margin-left: -11px;
   }
   .ol-popup-closer {
    text-decoration: none;
    position: absolute;
    top: 2px;
    right: 8px;
   }
   .ol-popup-closer:after {
    content: "✖";
   }
  </style>
 </head>
 <body>
  <!-- 
  bootstrap.min.css, bootstrap-responsive.min.css で設定されたセレクタを使用。
  -->
  <div class="navbar navbar-inverse navbar-fixed-top">
   <div class="navbar-inner">
    <div class="container">
<!--
     <a class="brand" href="./"><img src="../resources/logo.png"> OpenLayers 3 Examples</a>
-->
      <!-- ディレクトリ修正 -->
     <a class="brand" href="v3.0.0/examples/"><img src="v3.0.0/resources/logo.png"> OpenLayers 3 Examples</a>
    </div>
   </div>
  </div>
  <div class="container-fluid">
   <div class="row-fluid">
    <div class="span12">
     <div id="map" class="map">
      <div id="popup"></div>    
     </div>
    </div>
   </div>
   <div class="row-fluid">
    <div class="span12">
     <h4 id="title">Popup example</h4>
     <p id="shortdesc">Uses an overlay to create a popup.</p>
     <div id="docs">
       <p>Click on the map to get a popup.  The popup is composed
        of a few basic elements: a container, a close button, and
        a place for the content.  To anchor the popup to the map,
        an <code>ol.Overlay</code> is created with the popup 
        container.  A listener is registered for the map's <code>
        click</code> event to display the popup, and another 
        listener is set as the <code>click</code> handler for the 
        close button to hide the popup.</p>
<!--
      <p>See the <a href="popup.js" target="_blank">popup.js source</a> to see how this is done.</p>
-->
       <!-- ファイル修正 -->
      <p>See the <a href="238-ol3ex.js" target="_blank">238-ol3ex.js source</a> to see how this is done.</p>
     </div>
     <div id="tags">overlay, popup, mapquest, openaerial</div>
    </div>
   </div>
  </div>
<!--
  <script src="jquery.min.js" type="text/javascript"></script>
  <script src="../resources/example-behaviour.js" type="text/javascript"></script>
-->
  <!-- ディレクトリ修正
   jQuery Minified版と
   example-behaviour.js(Examples用 JSコード[文字コードなど])
  -->
  <script src="v3.0.0/examples/jquery.min.js" type="text/javascript"></script>
  <script src="v3.0.0/resources/example-behaviour.js" type="text/javascript"></script>
<!--
  <script src="loader.js?id=popup" type="text/javascript"></script>
-->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=238-ol3ex" type="text/javascript"></script>

 </body>
</html>

2014年2月20日木曜日

36 - GeoEXT を使用した WFS-T 7 - WMS GetFeatureInfo Popup

36-7 WMS GetFeatureInfo Popup
Developing OGC Compliant Web Applications with GeoExt の
2.4. Explore Map Features with a WMS GetFeatureInfo Popup(http://workshops.boundlessgeo.com/geoext/stores/getfeatureinfo.html)を参考に WMS レイヤの属性をポップアップ表示します。
続けて「ol017-nippon_bmi_akiruno_pgis.html」を使います。

---
<link rel="stylesheet" type="text/css" href="GeoExt/resources/css/geoext-all-debug.css" />
<link rel="stylesheet" type="text/css" href="GeoExt/resources/css/popup.css"><!-- 追加 -->
<script type="text/javascript" src="GeoExt/lib/GeoExt.js"></script>
<script type="text/javascript">
 OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url="; // 追加
---
// ここから追加
 items.push({
  xtype: "gx_legendpanel",
  region: "east",
  width: 200,
  autoScroll: true,
  padding: 5
 });
  controls.push(new OpenLayers.Control.WMSGetFeatureInfo({
  autoActivate: true,
  infoFormat: "application/vnd.ogc.gml",
  maxFeatures: 3,
  eventListeners: {
   "getfeatureinfo": function(e) {
    var items = [];
    Ext.each(e.features, function(feature) {
     items.push({
      xtype: "propertygrid",
      title: feature.fid,
      source: feature.attributes
     });
    });
    new GeoExt.Popup({
     title: "Feature Info",
     width: 200,
     height: 200,
     layout: "accordion",
     map: app.mapPanel,
     location: e.xy,
     items: items
    }).show();
   }
  }
 }));

// ここまで
</script>
---

2013年12月23日月曜日

32 - KML データの読込 3 - KML データのポップアップ表示

32-4 内容をポップアップ表示
KML Layer Example(sundials.html)を参考に、KML の「説明」に入力した内容をポップアップ表示させます。

a メニューの「ファイル」->「開く」をクリックします。







b 「ファイルを開く」ウィンドウで、「OpenLayers-2.13.1」->「examples」->「sundials.html」をクリックして選択し、「OK」ボタンをクリックします。






c 「sundials.html」の内容の一部をコピーして「ol013-nippon_bmi_akiruno_pgis.html」に貼り付け、次のように修正します。

---
<script type="text/javascript">
 var map, layer0, layer1, layer2, layer3, layer4, select; // "select" 追加
---
  map.addLayer(kml_layer); 
// ここから追加            
//  select = new OpenLayers.Control.SelectFeature(sundials);
  select = new OpenLayers.Control.SelectFeature(kml_layer); // 修正
//  sundials.events.on({
  kml_layer.events.on({ // 修正
   "featureselected": onFeatureSelect,
   "featureunselected": onFeatureUnselect
  });
  map.addControl(select);
  select.activate();   
// ここまで 
  map.addControl(new OpenLayers.Control.LayerSwitcher());
  map.addControl(new OpenLayers.Control.MousePosition());
  map.zoomToMaxExtent();
 } // End of function(init) 
// ここから追加
 function onPopupClose(evt) {
  select.unselectAll();
 } 
 function onFeatureSelect(event) {
  var feature = event.feature;
// Since KML is user-generated, do naive protection against
// Javascript.
  var content = "<h2>"+feature.attributes.name + "</h2>" +  feature.attributes.description;
  if (content.search("<script") != -1) {
   content = "Content contained Javascript! Escaped content below.<br>" +  content.replace(/</g, "<");
  }
  popup = new OpenLayers.Popup.FramedCloud("chicken", 
   feature.geometry.getBounds().getCenterLonLat(),
   new OpenLayers.Size(100,100),
   content,
   null, true, onPopupClose);
  feature.popup = popup;
  map.addPopup(popup);
 }
 function onFeatureUnselect(event) {
  var feature = event.feature;
  if(feature.popup) {
   map.removePopup(feature.popup);
   feature.popup.destroy();
   delete feature.popup;
  }
 }
// ここまで
</script>
---
例えば、「Point.xml」の次の部分を修正するとポップアップに画像が表示されます。
---
<Placemark>
 <name>Point</name>
 <description><![CDATA[あきる野市 Point<br /><img src="../img/marker.png" height="50" />]]></description>
  <LookAt>
---



2013年12月12日木曜日

30 - 情報がテキストファイルに保存されたマーカ

30-1 Layer.Text クラスを使ったマーカの設定
example フォルダにある「Using a Layer.Text to display markers(markersTextLayer.html)」を参考に情報をテキストファイルに保存したレイヤのマーカ設定をします。
最初に、HTML ファイルを準備します。

a メニューの「ファイル」->「開く」をクリックします。







b 「ファイルを開く」ウィンドウで、「OpenLayers-2.13.1」->「ol009-nippon_bmi_akiruno_pgis.html」をクリックして選択し、「OK」ボタンをクリックします。





c メニューの「ファイル」->「新規」 -> 「その他」をクリックします。




d 「ウィザードを選択」ウィンドウで、「Web」(複数あるときは展開して探してください。)->「HTMLファイル」をクリックして選択し、「次へ」ボタンをクリックします。






e 「HTML」ウィンドウで「openlayersTokyoproj」をクリックして選択し、「ファイル名」を「ol011-nippon_bmi_akiruno_pgis.html」と入力し、「完了」ボタンをクリックします。







f 「ol009-nippon_bmi_akiruno_pgis.html」の内容をコピーして「ol011-nippon_bmi_akiruno_pgis.html」ファイルに貼り付けます。

g メニューの「ファイル」->「開く」をクリックします。







h 「ファイルを開く」ウィンドウで、「OpenLayers-2.13.1」->「examples」->「markersTextLayer.html」をクリックして選択し、「OK」ボタンをクリックします。





i 「markersTextLayer.html」のjavascript の一部をコピーして「ol011-nippon_bmi_akiruno_pgis.html」に貼り付けて、次のように修正します。
(29-2 で追加したところは削除します。)

---
 map.addLayers([layer0, layer3, layer1, layer2, layer4]);
// ここから追加
 var newl = new OpenLayers.Layer.Text(
  "text",
  {
   projection: map.displayProjection, // 追加
   location: "./textfile.txt"
  });
 map.addLayer(newl);
// 追加ここまで
 map.addControl(new OpenLayers.Control.LayerSwitcher());
 map.addControl(new OpenLayers.Control.MousePosition());
 map.zoomToMaxExtent();
}
---

30-2 テキストファイルの作成
情報を書き込んだテキストファイルを準備します。

a メニューの「ファイル」->「新規」 -> 「ファイル」をクリックします。




b 「ファイル」ウィンドウで「openlayersTokyoproj」をクリックして選択し、「ファイル名」を「textfile.txt」と入力し、「完了」ボタンをクリックします。









f 内容は次のようにします。文字列の区切りはタブを使用します。
(examples フォルダの textfile.txt を参考にしました。)

point    title    description    icon
35.715,139.191    point     29章のポイント    
35.742,139.211    point2    29章のポイント2    
35.724,139.270    point3    29章のポイント3<br />外部マーカ    ../img/marker.png

マーカをクリックするとポップアップ表示されます。
ポップアップを閉じるときは、もう一度、マーカをクリックします。



2013年12月4日水曜日

28 - あきる野市の地図で属性のポップアップ表示(WFS)

WFS レイヤの属性のポップアップ表示
東京都の公共施設のレイヤ(tokyo_pf)の WFS レイヤの属性をポップアップ表示させる機能を追加します。

Geographic Information Systems の

How to collect data via WFS and Popup
http://gis.stackexchange.com/questions/34390/how-to-collect-data-via-wfs-and-popup

を参考に、WFS レイヤの属性をポップアップ表示します。

a メニューの「ファイル」->「開く」をクリックします。







b 「ファイルを開く」ウィンドウで、「OpenLayers-2.13.1」->「ol007-nippon_bmi_akiruno_pgis.html」をクリックして選択し、「OK」ボタンをクリックします。





c メニューの「ファイル」->「新規」 -> 「その他」をクリックします。




d 「ウィザードを選択」ウィンドウで、「Web」(複数あるときは展開して探してください。)->「HTMLファイル」をクリックして選択し、「次へ」ボタンをクリックします。






e 「HTML」ウィンドウで「openlayersTokyoproj」をクリックして選択し、「ファイル名」を「ol008-nippon_bmi_akiruno_pgis.html」と入力し、「完了」ボタンをクリックします。







f 「ol007-nippon_bmi_akiruno_pgis.html」の内容をコピーして「ol008-nippon_bmi_akiruno_pgis.html」ファイルに貼り付けます。
g javascript の一部を次のように修正します。

---
 map.addControl(new OpenLayers.Control.LayerSwitcher());
 map.addControl(new OpenLayers.Control.MousePosition());
 map.zoomToMaxExtent();


 // ここから追加
 var select = new OpenLayers.Control.SelectFeature(layer4);
 map.addControl(select);
 select.activate();


 function onPopupClose(evt) {
  selectControl.unselect(selectedFeature);
 }


 layer4.events.on({
  featureselected: function(event) {
   var feature = event.feature;


   var content = '<h1>' + feature.attributes.p02_004 + '</h1>'
    + '<hr>'
    + feature.attributes.p02_001 + '<br />'
    + feature.attributes.p02_002 + '<br />'
    + feature.attributes.p02_003 + '<br />'
    + feature.attributes.p02_005 + '<br />'
    + feature.attributes.p02_006 + '<br />'
    + feature.attributes.p02_007;


   feature.popup = new OpenLayers.Popup.FramedCloud(
    "pop",
    feature.geometry.getBounds().getCenterLonLat(),
    null,
    content,
    null,
    true
   );
   map.addPopup(feature.popup);
  },
  featureunselected: function(event) {
   var feature = event.feature;
   map.removePopup(feature.popup);
   feature.popup.destroy();
   feature.popup = null;
  }
 });
}
</script>
</head>
<body onload="init()">

---

ブラウザのアドレスバーに

http://192.168.1.200/mapsite/openlayersTokyoproj/ol008-nippon_bmi_akiruno_pgis.html

と入力して Enter キーを押します。
表示しない倍率で表示させてみました。

文字化けしてしまいました。
MapServer の WFS のエンコードが、ISO-8859-1 なのが理由です。




Javascript で文字化けを修正できなかった(私のスキルの問題)ので、MapServer の WFS サーバにエンコード「UTF-8」を設定しました。

nob61@debian7-vmw:~/mapfile$ vim nippon_nlni_tokyo_pgis.map

---
 WEB
   IMAGEPATH "/home/user/mapsite/ms_tmp/"
   IMAGEURL "/mapsite/ms_tmp/"
   METADATA
     "wms_title" "Nioopn NLNI Tokyo Map WMS Server" # WMS サーバ設定
     "wms_onlineresource" "http://192.168.1.200/cgi-bin/mapserv?map=/home/user/mapfile/nippon_nlni_tokyo_pgis.map&"
     "wms_srs" "EPSG 2451 EPSG:4326"
     "wms_enable_request" "*"
     "wfs_title" "Nippon NLNI Tokyo Map WFS Server" # WFS サーバ設定
     "wfs_onlineresource" "http://192.168.1.200/cgi-bin/mapserv?map=/home/user/mapfile/nippon_nlni_tokyo_pgis.map&"
     "wfs_srs" "EPSG:4326"
     "wfs_enable_request" "*"
     "wfs_encoding" "UTF-8" # 追加
   END
---


ブラウザのアドレスバーに

http://192.168.1.200/mapsite/openlayersTokyoproj/ol008-nippon_bmi_akiruno_pgis.html

と入力して Enter キーを押します。










GeoServer の WFS のエンコードは、UTF-8 なので日本語が表示されます。

2013年11月28日木曜日

26 - あきる野市の地図で属性のポップアップ表示(WMS)

WMS レイヤの属性のポップアップ表示
東京都の公共施設のレイヤ(tokyo_pf)の WMS レイヤの属性をポップアップ表示させる機能を追加します。GeoServer が配信したレイヤで動作します。

この機能は、proxy.cgi が実行されていないと動作しないので、24章で WFS で地図を表示して確認しました。また、クリックしやすいように25章でポイントのスタイルを設定しました。

Eclipse を起動して ol003-nippon_bmi_akiruno_pgis.html を開きます。
example フォルダにある getfeatureinfo-popup.html を参考にコードを編集します。

a メニューの「ファイル」->「開く」をクリックします。







b 「ファイルを開く」ウィンドウで、「OpenLayers-2.13.1」->「example」->「getfeatureinfo-popup.html」をクリックして選択し、「OK」ボタンをクリックします。




c 「ol003-nippon_bmi_akiruno_pgis.html」をコピーして、ファイル名「ol005-nippon_bmi_akiruno_pgis.html」にします。
d 「getfeatureinfo-popup.html」の53行目あたりの「info = ...」から71行目あたりの「info.active()」までをコピーします。
e 「ol005-nippon_bmi_akiruno_pgis.html」の「map.addLayers([...」の後に貼り付けます。
f javascriptの一部を次のように修正します。
---
<script type="text/javascript">
 var map, layer0, layer1, layer2, layer3, layer4, info; // info 追加
---
  layer4 = new OpenLayers.Layer.WMS( "Tokyo Public Facilities WMS",
   "http://192.168.1.200:8080/geoserver/wms",
   {
   layers: 'npn:tokyo_pf',
   transparent: true
  });
---
  info = new OpenLayers.Control.WMSGetFeatureInfo({
   url: 'http://192.168.1.200:8080/geoserver/wms',
   title: 'Identify features by clicking',
   queryVisible: true,
   eventListeners: {
    getfeatureinfo: function(event) {
     map.addPopup(new OpenLayers.Popup.FramedCloud(
      "chicken",
      map.getLonLatFromPixel(event.xy),
      null,
      event.text,
      null,
      true
     ));
    }
   }
  });
  map.addControl(info);
  info.activate();
---

レイヤが表示されないときは、url のドメイン部分の "localhost" を "192.168.1.200(GeoServer のときは 192.168.1.200:8080)" に変更します。
Eclipse の実行ボタンをクリックして地図を表示したときは、公共施設のポイントをクリックすると次のように表示されます。











正常に機能させるときは、Web ブラウザのアドレスバーに

http://192.168.1.200/mapsite/openlayersTokyoproj/ol005-nippon_bmi_akiruno_pgis.html

と入力して Enter キーを押します。公共施設のポイントをクリックすると次のように表示されます。

2010年12月5日日曜日

GeoExt17 Modified Popup Example

Modified Popu Example

Example サイト
http://www.geoext.org/examples.html

「Modifying Popups」リンクをクリックすると Modified Popup Example が表示されます。
popup-more.js. を参考にします。

説明を意訳すると、複数の場所(位置)のコンテンツを表示する単一のポップアップの使用方法を示します。

var mapPanel, popup;

Ext.onReady(function() {

function addToPopup(loc) {

// create the popup if it doesn't exist
if (!popup) {
popup = new GeoExt.Popup({
title: "Popup",
width: 200,
maximizable: true,
collapsible: true,
map: mapPanel.map,
anchored: true,
listeners: {
close: function() {
// closing a popup destroys it, but our reference is truthy
popup = null;
}
}
});
}


// プロジェクションの変更
var proj2 = new OpenLayers.Projection("EPSG:4326");
loc.transform(map.getProjectionObject(), proj2); // 数値表示のための投影法の変更

// add some content to the popup (this can be any Ext component)
popup.add({
xtype: "box",
autoEl: {
html: "You clicked on (" + loc.lon.toFixed(2) + ", " + loc.lat.toFixed(2) + ")"
}
});


// reset the popup's location
loc.transform(proj2, map.getProjectionObject()); // 表示位置のため投影法を元に戻す
popup.location = loc;

popup.doLayout();

// since the popup is anchored, calling show will move popup to this location
popup.show();
}


// 東京都用マップ設定
var map = new OpenLayers.Map('map', {
controls: [
new OpenLayers.Control.PanZoom(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.MousePosition(),
new OpenLayers.Control.ScaleLine()
],
projection: new OpenLayers.Projection("EPSG:2456"),
maxResolution: 'auto', //'367.1875', '183.594'
maxExtent: new OpenLayers.Bounds(-279000,1054000,-185000,1104000),
units: 'meters',
displayProjection: new OpenLayers.Projection("EPSG:4326")
});


// create Ext window including a map panel
var mapPanel = new GeoExt.MapPanel({
title: "Map",
renderTo: "container",
width: 650, height: 356,
layers: [
/* レイヤを変更
new OpenLayers.Layer.WMS(
"Global Imagery",
"http://maps.opengeo.org/geowebcache/service/wms",
{layers: "bluemarble"}
)
*/
new OpenLayers.Layer.WMS( "Tokyo Height WMS",
"http://192.168.1.6/cgi-bin/mapserv?",
{
map: '/home/nob61/mapfile/tokyo_bmi_pgis_img2.map',
layers: 'height',
format: 'image/png'
}),
new OpenLayers.Layer.WMS( "Tokyo Kukaku Sen WMS",
"http://192.168.1.6/cgi-bin/mapserv?",
{
map: '/home/nob61/mapfile/tokyo_bmi_pgis_img2.map',
layers: 'kukaku',
transparent: true,
format: 'image/png'
})
],
// center: [0, 0],
// zoom: 2
map: map
});


var control = new OpenLayers.Control.Click({
trigger: function(evt) {
var loc = mapPanel.map.getLonLatFromViewPortPx(evt.xy);
addToPopup(loc);
}
});

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

});


// simple control to handle user clicks on the map

OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
single: true,
double: false,
pixelTolerance: 0,
stopSingle: true
},

initialize: function(options) {
this.handlerOptions = OpenLayers.Util.extend(
options && options.handlerOptions || {},
this.defaultHandlerOptions
);
OpenLayers.Control.prototype.initialize.apply(
this, arguments
);
this.handler = new OpenLayers.Handler.Click(
this,
{
click: this.trigger
},
this.handlerOptions
);
},
CLASS_NAME: "OpenLayers.Control.Click"
});

HTML ファイルを新規作成します。
「openlayersTokyoproj」 を右クリックして 新規 -> HTML ファイル をクリック。
「HTML ファイル」ウィンドウの「ファイル名(任意:geoext17_popup-more.html)」に入力して「完了」ボタンをクリック。
「charset」を「utf-8」にします。
以下のように HTML を作成します。
geoext16_popup.html をコピーし、外部 JavaScript 読み込みファイルを修正しマップのスタイルシートを修正し body タグ内に container を設定します。

---
<title>GeoExt17 Modified Popup</title>
---
<!-- popup-more.js 追加 -->
<script type="text/javascript" src="./popup-more.js"></script>
<!-- map スタイルシート追加 -->
<style type="text/css">
#container {
margin: 1em;
}
</style>

</head>
<body>
<h1 id="title">GeoExt 17 - Modified Popupp</h1>
<p id="shortdesc">
Modified Popup Example
</p>
<p>This example demonstrates the use of a single popup to display
content from multiple locations.<br />
Clicking on the map will open a popup displaying the click location.
Subsequent clicks will update the content and the position.
Close the popup to start over.</p>

<p>この例では、複数の場所(位置)のコンテンツを表示する単一のポップアップの使用方法を示します。<br />
地図をクリックすると、クリック位置を表示するポップアップを開きます。
続けてクリックするとコンテンツと位置を更新(追加)します。最初からやり直すにポップアップを閉じます。</p>
<div id="container"></div>
</body>
</html>

2010年12月2日木曜日

GeoExt16 Popup Example

Popup Example

Example サイト
http://www.geoext.org/examples.html

「Popup Example」リンクをクリックすると Popup Example が表示されます。
popup.js. を参考にします。

説明を意訳すると、マップパネル上でポイントをクリックしてポップアップを開く方法を示します。

var mapPanel, popup;

Ext.onReady(function() {

// 東京都用マップ設定
var map = new OpenLayers.Map('map', {
controls: [
new OpenLayers.Control.PanZoom(),
new OpenLayers.Control.LayerSwitcher(),
new OpenLayers.Control.MousePosition(),
new OpenLayers.Control.ScaleLine()
],
projection: new OpenLayers.Projection("EPSG:2456"),
maxResolution: 'auto',
maxExtent: new OpenLayers.Bounds(-279000,1054000,-185000,1104000),
units: 'meters',
displayProjection: new OpenLayers.Projection("EPSG:4326")
});


// create a vector layer, add a feature into it
var vectorLayer = new OpenLayers.Layer.Vector("vector");

// プロジェクションの変更
var proj1 = new OpenLayers.Projection("EPSG:4326");
var proj2 = new OpenLayers.Projection("EPSG:2456");
var point = new OpenLayers.Geometry.Point(139.4, 35.7);
point.transform(proj1, proj2);

vectorLayer.addFeatures(
new OpenLayers.Feature.Vector(
// new OpenLayers.Geometry.Point(-45, 5)
point// 修正
)
);


// create select feature control
var selectCtrl = new OpenLayers.Control.SelectFeature(vectorLayer);

// define "createPopup" function
// var bogusMarkup = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit.";
var bogusMarkup = "立川駅南口付近";
function createPopup(feature) {
popup = new GeoExt.Popup({
title: 'My Popup',
location: feature,
width:200,
html: bogusMarkup,
maximizable: true,
collapsible: true
});
// unselect feature when the popup
// is closed
popup.on({
close: function() {
if(OpenLayers.Util.indexOf(vectorLayer.selectedFeatures,
this.feature) > -1) {
selectCtrl.unselect(this.feature);
}
}
});
popup.show();
}


// create popup on "featureselected"
vectorLayer.events.on({
featureselected: function(e) {
createPopup(e.feature);
}
});


// create Ext window including a map panel
var mapwin = new Ext.Window({
layout: "fit",
title: "Map",
closeAction: "hide",
width: 650,
height: 356,
x: 50,
y: 100,
items: {
xtype: "gx_mappanel",
region: "center",
layers: [
/* レイヤを変更
new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0",
{layers: 'basic'}
),
*/
new OpenLayers.Layer.WMS( "Tokyo Height WMS",
"http://192.168.1.6/cgi-bin/mapserv?",
{
map: '/home/nob61/mapfile/tokyo_bmi_pgis_img2.map',
layers: 'height',
format: 'image/png'
}),
new OpenLayers.Layer.WMS( "Tokyo Kukaku Sen WMS",
"http://192.168.1.6/cgi-bin/mapserv?",
{
map: '/home/nob61/mapfile/tokyo_bmi_pgis_img2.map',
layers: 'kukaku',
transparent: true,
format: 'image/png'
}),
vectorLayer
],
map: map // 追加
}
});
mapwin.show();

mapPanel = mapwin.items.get(0);
mapPanel.map.addControl(selectCtrl);
selectCtrl.activate();
});


HTML ファイルを新規作成します。
「openlayersTokyoproj」 を右クリックして 新規 -> HTML ファイル をクリック。
「HTML ファイル」ウィンドウの「ファイル名(任意:geoext16_popup.html)」に入力して「完了」ボタンをクリック。
「charset」を「utf-8」にします。
以下のように HTML を作成します。
geoext15_permalink.html をコピーし、外部 JavaScript 読み込みファイルを修正しマップのスタイルシートを追加し body タグ内に container を設定します。

---
<title>GeoExt16 Popup</title>
---
<!-- permalink.js 追加 -->
<script type="text/javascript" src="./popup.js"></script>
<!-- map スタイルシート追加 -->
<style type="text/css">
div#map {
width: 650px;
height: 400px;
position: relative;
}
</style>

</head>
<body>
<h1 id="title">GeoExt 19 - Popup</h1>
<p id="shortdesc">
Popup Example
</p>
<p>Click on the point in the map panel to open a popup.</p>

<p>ポップアップを開くためにマップパネル上でポイントをクリックしてください。</p>
<div id="container"></div>
</body>
</html>