ラベル jsファイル の投稿を表示しています。 すべての投稿を表示
ラベル jsファイル の投稿を表示しています。 すべての投稿を表示

2017年11月28日火曜日

2 - ol4.5ex 175b - Vector Tile Info vector-tile-info 2

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

「2175-ol4ex.js」
var map = new ol.Map({
 target: 'map',
 view: new ol.View({
  center: [0, 0],
  zoom: 2
 }),
 layers: [new ol.layer.VectorTile({
 /** ol.layer.VectorTile
  * Layer for vector tile data that is rendered client-side. 
  * クライアント側にレンダリングされるベクタタイルデータのレイ 
  * ヤ。
  * (ol4 API)
  */
  source: new ol.source.VectorTile({
  /** ol.source.VectorTile
   * Class for layer sources providing vector data divided 
   * into a tile grid, to be used with ol.layer.VectorTile. 
   * Although this source receives tiles with vector 
   * features from the server, it is not meant for feature 
   * editing. Features are optimized for rendering, their 
   * geometries are clipped at or near tile boundaries and 
   * simplified for a view resolution. See ol.source.Vector 
   * for vector sources that are suitable for feature 
   * editing.
   * ol.layer.VectorTile で使用するタイルとグリッドに分割され
   * たベクタデータを提供するレイヤソースのクラス。このソース
   * はベクタフィーチャを持つタイルをサーバから受信しますが、
   * フィーチャの編集を意味したものではありません。フィーチャ
   * はレンダリングのために最適化され、そのジオメトリはタイル
   * の境界線、または、その近くでクリップされ、ビュー解像度の
   * ために単純化されます。フィーチャ編集に適したベクトルソー
   * スについては、ol.source.Vector を参照してください。
   * (ol4 API)
   */
   format: new ol.format.MVT(),
   /** format:
    * Feature format for tiles. Used and required by the 
    * default tileLoadFunction.
    * タイルのためのフィーチャフォーマット。デフォルトの 
    * tileLoadFunction によって使用され、必須とされます。
    * (ol4 API)
    */
   /** ol.format.MVT
    * Feature format for reading data in the Mapbox MVT 
    * format.
    * Mapbox MVT フォーマットの描画データのためのフィーチャ
    * フォーマット。(ol4 API)
    */
   url: 'https://basemaps.arcgis.com/v1/arcgis/rest/services/World_Basemap/VectorTileServer/tile/{z}/{y}/{x}.pbf'
   /** url:
    * URL template. Must include {x}, {y} or {-y}, and {z} 
    * placeholders. A {?-?} template pattern, for example 
    * subdomain{a-f}.domain.com, may be used instead of 
    * defining each one separately in the urls option.
    * URLテンプレート。 {x}、{y}、{-y}、{z} のプレースホル
    * ダーが必要です。 urlsオプションでそれぞれ個別に定義する
    * 代わりに、例えばサブドメイン {a-f}.domain.com の、
    * {?-?} テンプレートパターンを使用することができます。
    * (ol4 API)
    */
  })
 })]
});
map.on('pointermove', showInfo);
/** on
 * Listen for a certain type of event.
 * あるタイプのイベントをリッスンします。
 * (ol4 API)
 */
var info = document.getElementById('info');
/** document.getElementById()
 * Returns a reference to the element by its ID; the ID 
 * is a string which can be used to uniquely identify 
 * the element, found in the HTML id attribute.
 * ID によってエレメントに参照を返します。ID は、HTML id 
 * 属性に見られるエレメントを一意に識別するために使用される
 * 文字列です。
 * (MDN[https://developer.mozilla.org/en-US/docs/Web/
 * API/Document/getElementById])
 */
function showInfo(event) {
 var features = map.getFeaturesAtPixel(event.pixel);
 /** getFeaturesAtPixel(pixel, opt_options)
  * Get all features that intersect a pixel on the 
  * viewport.
  * viewport(ビューポート)上のピクセルと交差するすべての
  * フィーチャを取得します。(ol4 API)
  */
 if (!features) {
  info.innerText = '';
  /** Node.innerText
   * Node.innerText is a property that represents the 
   * "rendered" text content of a node and its descendants. 
   * As a getter, it approximates the text the user would 
   * get if they highlighted the contents of the element 
   * with the cursor and then copied to the clipboard. 
   * This feature was originally introduced by Internet 
   * Explorer, and was formally specified in the HTML 
   * standard in 2016 after being adopted by all major 
   * browser vendors.
   * Node.innerTextは、ノードと子孫の「描画された」テキス
   * トコンテンツを表すプロパティです。getter と、カーソル
   * でエレメントのコンテンツを強調表示し、それからクリッ
   * プボードにコピーした場合取得するテキストを近似しま
   * す。この機能は、元々、Internet Explorer によって導
   * 入され、主要なブラウザベンダーによって採用された後、
   * 2016年に HTML標準に正式に制定されました。
   * (MDN[https://developer.mozilla.org/en-US/docs/Web/
   * API/Node/innerText])
   */
  /** getter
   * The get syntax binds an oject property to a function 
   * that will be called when that property is looked up.
   * get 構文は、オブジェクトプロパティを、そのプロパティが
   * 検索されたときに呼び出される関数にバインドします。
   * (MDN[https://developer.mozilla.org/en-US/docs/Web/
   * JavaScript/Reference/Functions/get])
   */
  info.style.opacity = 0;
  return;
 }
 var properties = features[0].getProperties();
 /** getProperties()
  * Get an object of all property names and values.
  * オブジェクトの全ての属性名と値を取得します。(ol4 API)
  */
 info.innerText = JSON.stringify(properties, null, 2);
 /** JSON.stringify()
  * The JSON.stringify() method converts a JavaScript 
  * value to a JSON string, optionally replacing values 
  * if a replacer function is specified, or optionally 
  * including only the specified properties if a replacer 
  * array is specified.
  * JSON.stringify()メソッドは、JavaScript 値を JSON 
  * 文字列に変換します。replacer 関数が指定されている場合は、
  * オプションで値を置換するか、または、replacer 配列が指定さ
  * れている場合は、指定のプロパティのみをオプションで含みま
  * す。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/
  * JavaScript/Reference/Global_Objects/JSON/stringify])
  */
 info.style.opacity = 1;
}


2 - ol4.5ex 174b - Street Labels 2

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

「2174-ol4ex.js」
var style = new ol.style.Style({
/** ol.style.Style 
 * Container for vector feature rendering styles. Any 
 * changes made to the style or its children through 
 * set*() methods will not take effect until the feature 
 * or layer that uses the style is re-rendered.
 * ベクタフィーチャがスタイルを描画するためのコンテナ。
 * スタイルや set*() メソッドを通じてその子に加えられた変
 * 更は、スタイルを使用するフィーチャまたはレイヤが再レン
 * ダリングされるまで有効になりません。
 * (ol4 API)
 */
 text: new ol.style.Text({
 /** text:
  * Text style.(ol4 API)
  */
 /** ol.style.Text
  * Set text style for vector features.
  * ベクタフィーチャの文字列のスタイルを設定します。
  * (ol4 API)
  */
  font: 'bold 11px "Open Sans", "Arial Unicode MS", "sans-serif"',
  /** font:
   * Font style as CSS 'font' value, see: https://
   * developer.mozilla.org/en-US/docs/Web/API/
   * CanvasRenderingContext2D/font. Default is '10px 
   * sans-serif'
   * CSS「font」値と同じフォントスタイル。デフォルトは、
   * 「10px sans-serif」。(ol4 API)
   */
  placement: 'line',
  /** placement:
   * Text placement.(ol4 API)
   */
  fill: new ol.style.Fill({
  /** fill:
   * Fill style. If none is provided, we'll use a dark 
   * fill-style (#333).
   * 塗りつぶしスタイル。名前が提供されていなければダーク
   * フィルスタイル(#333)を使用します。(ol4 API)
   */
  /** ol.style.Fill 
   * Set fill style for vector features.
   * ベクタフィーチャの塗りつぶしスタイルを設定。
   * (ol4 API)
   */
   color: 'white'
   /** color:
    * A color, gradient or pattern. See ol.color and 
    * ol.colorlike for possible formats. Default null; 
    * if null, the Canvas/renderer default black will 
    * be used.
    * 色、グラデーション、または、パターン。可能なフォー
    * マットは、ol.color と ol.colorlike を参照して
    * ください。デフォルトは null。null の場合 
    * Canvas/renderer のデフォルト black(黒)が使
    * 用されます。(ol4 API)
    */
  })
 })
});
var viewExtent = [1817379, 6139595, 1827851, 6143616];
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. 
  * プリレンダリング(事前描画)を提供するレイヤソースのた
  * めの、特定の解像度でのズームレベルによって編成されてい
  * るグリッドのタイルイメージ。(ol4 API)
  */
  source: new ol.source.BingMaps({
  /** source:
   * Source for this layer. Required.
   * このレイヤのソース。必須。(ol4 API)
   */
  /** ol.source.BingMaps
   * Layer source for Bing Maps tile data.
   * Bing Maps タイルデータのレイヤソース。(ol4 API)
   */
  key: 'As1Hi...(省略)',
  /** key:
   * Bing Maps API key. Get yours at 
   * http://www.bingmapsportal.com/. Required.
   * (ol4 API)
   */
  imagerySet: 'Aerial'
  /** imagerySet:
   * Type of imagery. Required. 
   * 画像のタイプ。必須。(ol4 API)
   */
  })
 }), new ol.layer.Vector({
 /** ol.layer.Vector
  * Vector data that is rendered client-side.
  * クライアント側で描画されるベクタデータ。(ol4 API)
  */
  declutter: true,
  /** declutter:
   * Declutter images and text. Decluttering is 
   * applied to all image and text styles, and the 
   * priority is defined by the z-index of the style. 
   * Lower z-index means higher priority. Default is 
   * false.
   * 画像とテキストをぼかします。 ぼかし(デクラッタ)は、
   * すべての画像とテキストスタイルに適用され、優先順位は、
   * スタイルのZ-インデックスによって定義されます。 Z-イ
   * ンデックスが低いほど優先度が高くなります。デフォルト
   * は、false です。(ol4 API)
   */
  source: new ol.source.Vector({
  /** ol.source.Vector
   * Provides a source of features for vector layers. 
   * Vector features provided by this source are 
   * suitable for editing. See ol.source.VectorTile 
   * for vector data that is optimized for rendering.
   * ベクタレイヤのフィーチャのソースを提供します。このソー
   * スが提供するベクタフィーチャは、編集に適しています。レ
   * ンダリングのために最適化されたベクタデータのための 
   * ol.source.VectorTile を参照してください。
   * (ol4 API)
   */
  format: new ol.format.GeoJSON(),
  /** format: 
   * The feature format used by the XHR feature loader 
   * when url is set. Required if url is set, otherwise 
   * ignored. Default is undefined.
   * url が設定されたときに XHR フィーチャローダに使用さ
   * れるフィーチャフォーマット。url が設定された場合、必
   * 須で、それ以外は無視されます。デフォルトは、未定義です。
   * (ol4 API)
   */
  /** ol.format.GeoJSON 
   * Feature format for reading and writing data in the 
   * GeoJSON format.
   * GeoJSON フォーマットのデータを読み書きするためのフィー
   * チャフォーマット。(ol4 API)
   */
  url: 'data/geojson/vienna-streets.geojson'
  /** url
   * Setting this option instructs the source to load 
   * features using an XHR loader (see 
   * ol.featureloader.xhr). Use a string and an 
   * ol.loadingstrategy.all for a one-off download of 
   * all features from the given URL. Use a 
   * ol.FeatureUrlFunction to generate the url with 
   * other loading strategies. Requires format to be 
   * set as well. When default XHR feature loader is 
   * provided, the features will be transformed from 
   * the data projection to the view projection during 
   * parsing. If your remote data source does not 
   * advertise its projection properly, this 
   * transformation will be incorrect. For some formats, 
   * the default projection (usually EPSG:4326) can be 
   * overridden by setting the defaultDataProjection 
   * constructor option on the format. Note that if a 
   * source contains non-feature data, such as a 
   * GeoJSON geometry or a KML NetworkLink, these will 
   * be ignored. Use a custom loader to load these.
   * このオプションを設定すると、XHR ローダを
   * (ol.featureloader.xhr参照)を使用してフィーチャを
   * ロードするためのソースを指示します。指定された URL から
   * のすべてのフィーチャの1回限りのダウンロードのために 
   * string と ol.loadingstrategy.all を使用してくださ
   * い。他のローディングストラテジと共に URL を生成するため
   * に、ol.FeatureUrlFunctionを使用してください。format 
   * も同様に設定する必要があります。デフォルトの XHR フィー
   * チャローダが提供される場合、フィーチャは、解析中にデータ
   * 投影からビュー投影へ変換されます。リモート・データ・ソー
   * スが適切に投影を示していない場合は、この変換は不正確にな
   * ります。いくつかのフォーマットでは、デフォルトの投影(通
   * 常は EPSG:4326)は、フォーマット上の 
   * defaultDataProjection constructor オプションを設
   * 定することで上書きすることができます。ソースが、このよう
   * な GeoJSON ジオメトリ、または、 KML NetworkLink などの
   * 非フィーチャデータを含んでいる場合、これらは無視される
   * ことに注意してください。これらをロードするために、カス
   * タムローダを使用してください。
   * (ol4 API)
   */
  }),
  style: function(feature) {
  /** style:
   * Layer style. See ol.style for default style which 
   * will be used if this is not defined.
   * レイヤスタイル。これが定義されたいない場合、使用されるデ
   * フォルトスタイルについて ol.style を参照してください。
   * (ol4 API)
   */
   style.getText().setText(feature.get('name'));
   /** getText()
    * Get the text style.(ol4 API)
    */
   /** setText()
    * Set the text style.(ol4 API)
    */
   /** get(key)
    * Gets a value.(ol4 API)
    */
   return style;
  }
 })],
 target: 'map',
 view: new ol.View({
  extent: viewExtent,
  center: ol.extent.getCenter(viewExtent),
  /** ol.extent.getCenter(extent)
   * Get the center coordinate of an extent.
   * 範囲の中心座標を取得します。(ol4 API)
   */
  zoom: 17,
  minZoom: 14
 })
});
 
 

2017年10月10日火曜日

2 - ol4.4ex 173b - Tile Transitions 2

「tile-transitions.js(2173-ol4ex.js)」は、マップを表示するための JavaScript ファイルです。


「2173-ol4ex.js」
var url = 'https://{a-c}.tiles.mapbox.com/v3/mapbox.world-bright/{z}/{x}/{y}.png';
var withTransition = 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. 
 * プリレンダリング(事前描画)を提供するレイヤソースのた
 * めの、特定の解像度でのズームレベルによって編成されてい
 * るグリッドのタイルイメージ。(ol4 API)
 */
 source: new ol.source.XYZ({url: url})
 /** ol.source.XYZ
  * Layer source for tile data with URLs in a set XYZ 
  * format that are defined in a URL template. By 
  * default, this follows the widely-used Google grid 
  * where x 0 and y 0 are in the top left. Grids like 
  * TMS where x 0 and y 0 are in the bottom left can 
  * be used by using the {-y} placeholder in the URL 
  * template, so long as the source does not have a 
  * custom tile grid. In this case, ol.source.TileImage 
  * can be used with a tileUrlFunction such as:
  *
  * tileUrlFunction: function(coordinate) { 
  *  return 'http://mapserver.com/' 
  *  + coordinate[0] + '/' 
  *  + coordinate[1] + '/' 
  *  + coordinate[2] + '.png'; }
  * 
  * URL テンプレートで定義されているセット XYZ 形式の URL 
  * を持つタイルデータのレイヤソース。デフォルトでは、これは、
  * x0 と y0 が左上にある広く使用されている Google のグリッド
  * に従います。x0 と y0 が左下にある TMS のようなグリッドは、
  * ソースがカスタムタイルグリッドを持っていない限り、URL テ
  * ンプレートに {-y} プレースホルダを使用して使用することが
  * できます。この場合、ol.source.TileImage は tileUrlFunction 
  * で次のように使用できます。(ol4 API)
  */
 /** url
  * URL template. Must include {x}, {y} or {-y}, and 
  * {z} placeholders. A {?-?} template pattern, for 
  * example subdomain{a-f}.domain.com, may be used 
  * instead of defining each one separately in the 
  * urls option.
  * URLテンプレート。 {x}、{y} または {-y}、と {z} プレー
  * スホルダを含める必要があります。例えば 
  * subdomain{a-f}.domain.com の {?-?} テンプレートパ
  * ターンは、urls オプションでそれぞれを個別に定義する代
  * わりに、使用することができます。(ol4 API)
  */
});
var withoutTransition = new ol.layer.Tile({
 source: new ol.source.XYZ({url: url, transition: 0}),
 /** transition:
  * Duration of the opacity transition for rendering. 
  * To disable the opacity transition, pass 
  * transition: 0.
  * レンダリングのための不透明度遷移のデュレーション(期限)。
  *  不透明度の遷移を無効にするには、transition:0を渡します。
  * (ol4 API)
  */
 visible: false
 /** visible:
  * Visibility. Default is true (visible).(ol4 API)
  */
});
var map = new ol.Map({
 layers: [withTransition, withoutTransition],
 target: 'map',
 view: new ol.View({
  center: [0, 0],
  zoom: 2,
  maxZoom: 11
 })
});
document.getElementById('transition').addEventListener('change', function(event) {
/** EventTarget.addEventListener
 * The EventTarget.addEventListener() method adds the 
 * specified EventListener-compatible object to the 
 * list of event listeners for the specified event 
 * type on the EventTarget on which it is called. 
 * The event target may be an Element in a document, 
 * the Document itself, a Window, or any other object 
 * that supports events (such as XMLHttpRequest).
 * EventTarget.addEventListener() メソッドは、指定された
 * EventListener 互換オブジェクトを、呼び出される 
 * EventTarget の指定されたイベントタイプのイベントリスナのリ
 * ストに追加します。イベントターゲットは、ドキュメントの Element、
 * Document 自身、Window、または(XMLHttpRequest などの)
 * イベントをサポートしている他のオブジェクトです。
 * (MDN[https://developer.mozilla.org/en-US/docs/Web/
 * API/EventTarget/addEventListener])
 */
 var transition = event.target.checked;
 withTransition.setVisible(transition);
 /** setVisible(visible)
  * Set the visibility of the layer (true or false).
  * レイヤの可視性(true または false)を設定します。
  * (ol4 API)
  */
 withoutTransition.setVisible(!transition);
});
 
 

2017年8月30日水曜日

2 - ol4.3ex 172b - Vector Label Decluttering 2

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


「2172-ol4ex.js」
// Style for labels
function setStyle(context) {
 context.font = '12px Calibri,sans-serif';
 /** CanvasRenderingContext2D.font
  * The CanvasRenderingContext2D.font property of the 
  * Canvas 2D API specifies the current text style being 
  * used when drawing text. This string uses the same 
  * syntax as the CSS font specifier. The default font 
  * is 10px sans-serif.
  * Canvas 2D API の CanvasRenderingContext2D.font 
  * プロパティは、テキストを描画するときに使用される現在のテキ
  * ストスタイルを指定します。 この文字列は、CSSフォント記述子
  * と同じ構文を使用します。 デフォルトのフォントは 10px 
  * sans-serif です。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/
  * API/CanvasRenderingContext2D/font])
  */
 context.fillStyle = '#000';
 /** CanvasRenderingContext2D.fillStyle
  * The CanvasRenderingContext2D.fillStyle property of 
  * the Canvas 2D API specifies the color or style to 
  * use inside shapes. The default is #000 (black).
  * Canvas 2D API の CanvasRenderingContext2D.fillStyle 
  * プロパティは、図形の内側に使用する色やスタイルを指定します。
  * デフォルトでは、#000(黒)です。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/
  * API/CanvasRenderingContext2D/fillStyle])
  */
 context.strokeStyle = '#fff';
 /** CanvasRenderingContext2D.strokeStyle
  * The CanvasRenderingContext2D.strokeStyle property 
  * of the Canvas 2D API specifies the color or style 
  * to use for the lines around shapes. The default is 
  * #000 (black).
  * Canvas 2D API の 
  * CanvasRenderingContext2D.strokeStyle プロパティは、
  * 形状の周りの線に使用する色またはスタイルを指定します。 デ
  * フォルトは#000(黒)です。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/
  * API/CanvasRenderingContext2D/strokeStyle])
  */
 context.lineWidth = 3;
 /** CanvasRenderingContext2D.lineWidth
  * The CanvasRenderingContext2D.lineWidth property of 
  * the Canvas 2D API sets the thickness of lines in 
  * space units. When getting, it returns the current 
  * value (1.0 by default). When setting, zero, negative, 
  * Infinity and NaN values are ignored; otherwise the 
  * current value is set to the new value.
  * Canvas 2D API の CanvasRenderingContext2D.lineWidth 
  * プロパティは、スペース単位で線の太さを設定します。 取得する
  * と、現在の値(デフォルトでは 1.0)を返します。 0、負の値を
  * 設定すると、Infinity 値と NaN 値は無視されます。それ以外
  * の場合は、現在の値が新しい値に設定されます。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/
  * API/CanvasRenderingContext2D/lineWidth])
  */
 context.textBaseline = 'hanging';
 /** CanvasRenderingContext2D.textBaseline
  * The CanvasRenderingContext2D.textBaseline property 
  * of the Canvas 2D API specifies the current text 
  * baseline being used when drawing text.
  * Canvas 2D API の 
  * CanvasRenderingContext2D.textBaseline プロパティ
  * は、テキストを描画するとき使用される現在のテキストデフォル
  * トでは、#000(黒)です。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/
  * API/CanvasRenderingContext2D/textBaseline])
  */
 context.textAlign = 'start';
 /** CanvasRenderingContext2D.textAlign
  * The CanvasRenderingContext2D.textAlign property of 
  * the Canvas 2D API specifies the current text 
  * alignment being used when drawing text. Beware that 
  * the alignment is based on the x value of the 
  * CanvasRenderingContext2D.fillText method. So if 
  * textAlign="center", then the text would be drawn at 
  * x-50%*width.
  * Canvas 2D API の CanvasRenderingContext2D.textAlign 
  * プロパティは、テキストを描画するときに使用される現在のテキ
  * ストの配置を指定します。 配置は、
  * CanvasRenderingContext2D.fillText メソッドのx値に
  * 基づいていることに注意してください。 したがって、
  * textAlign = "center" の場合、テキストは 
  * x-50%*width の位置から描画されます。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/
  * API/CanvasRenderingContext2D/textAlign])
  */
}
// A separate canvas context for measuring label width 
// and height.
// ラベルの幅と高さを測定するための離れているキャンバスコンテキ
// スト
var textMeasureContext = document.createElement('CANVAS').getContext('2d');
/** Document.createElement()
 * In an HTML document, the Document.createElement() 
 * method creates the HTML element specified by 
 * tagName, or an HTMLUnknownElement if tagName isn't 
 * recognized. In a XUL document, it creates the 
 * specified XUL element. In other documents, it 
 * creates an element with a null namespace URI.
 * HTMLドキュメントでは、Document.createElement() メ
 * ソッドは tagName で指定された HTML 要素を作成し、tagName 
 * が認識されない場合に HTMLUnknownElement を作成します。 
 * XUL ドキュメントでは、指定されたXUL要素を作成します。 他
 * のドキュメントでは、nullの名前空間 URI を持つ要素を作成し
 * ます。
 * (MDN[https://developer.mozilla.org/en-US/docs/Web/
 * API/Document/createElement])
 */
/** HTMLCanvasElement.getContext()
 * The HTMLCanvasElement.getContext() method returns a 
 * drawing context on the canvas, or null if the 
 * context identifier is not supported.
 * HTMLCanvasElement.getContext()メソッドは、キャンバ
 * ス上の描画コンテキストを返すか、または コンテキスト識別
 * 子がサポートされていない場合、null を返します。
 * contextType Is a DOMString containing the context 
 * identifier defining the drawing context associated 
 * to the canvas.
 * "2d", leading to the creation of a 
 * CanvasRenderingContext2D object representing a 
 * two-dimensional rendering context.
 * contextTypeは canvas に関連する描画コンテキストを定義
 * するコンテキスト識別子を含む DOMString  です。
 * 「2d」、二次元のレンダリングコンテキストを表す
 * CanvasRenderingContext2D オブジェクトの作成につなが
 * ります。
 * (MDN[https://developer.mozilla.org/en-US/docs/Web/
 * API/HTMLCanvasElement/getContext])
 */
setStyle(textMeasureContext);
// The label height is approximated by the width of the 
// text 'WI'.
// ラベルの高さはテキスト 'WI' の幅で近似されます。
var height = textMeasureContext.measureText('WI').width;
/** CanvasRenderingContext2D.measureText()
 * The CanvasRenderingContext2D.measureText() method 
 * returns a TextMetrics object that contains information 
 * about the measured text (such as its width for example).
 * CanvasRenderingContext2D.measureText() メソッド
 * は、(例えば幅などの)測定されたテキストについて情報を含む 
 * TextMetrics オブジェクトを返します。
 * (MDN[https://developer.mozilla.org/en-US/docs/Web/
 * API/CanvasRenderingContext2D/measureText])
 */
// A cache for reusing label images once they have been 
// created.
// 一度作成された再利用するラベル画像のためのキャッシュ。
var textCache = {};

var map = new ol.Map({
 target: 'map',
 view: new ol.View({
  center: [0, 0],
  zoom: 1
 })
});
var emptyFn = function() {};
var labelEngine = new labelgun['default'](emptyFn, emptyFn);
/** labelgun(hideLabel, showLabel, entries)
 * Create a label gun instance with a hide and show label 
 * callback.
 * hide と show label コールバックで label gun インス
 * タンスを作成します。
 * (JSDoc[http://tech.geovation.uk/labelgun/documentation/
 * labelgun.html])
 */
function createLabel(canvas, text, coord) {
 var halfWidth = canvas.width / 2;
 /** HTMLCanvasElement.width
  * The HTMLCanvasElement.width property is a positive 
  * integer reflecting the width HTML attribute of 
  * the <canvas> element interpreted in CSS pixels. 
  * When the attribute is not specified, or if it is 
  * set to an invalid value, like a negative, the 
  * default value of 300 is used.
  * HTMLCanvasElement.width プロパティは CSS ピクセル
  * で解釈された <canvas> 要素の幅 HTML 属性を反映
  * する正の整数です。属性が指定されていない場合、または、
  * 負の値のように無効な値に設定されている場合、デフォルト
  * 値 300 が使用されます。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/
  * API/HTMLCanvasElement/width])
  */
 var halfHeight = canvas.height / 2;
 /** HTMLCanvasElement.height
  * A positive integer reflecting the height HTML attribute 
  * of the <canvas> element interpreted in CSS pixels. 
  * When the attribute is not specified, or if it is set 
  * to an invalid value, like a negative, the default value 
  * of 150 is used.
  * CSSピクセルで解釈された <canvas> 要素の高さ HTML 属
  * 性を反映する正の整数。属性が指定されていない場合、または、
  * 負の値のような、無効な値に設定されている場合、デフォルト
  * 値 150 が使用さます。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/
  * API/HTMLCanvasElement])
  */
 var bounds = {
  bottomLeft: [Math.round(coord[0] - halfWidth), Math.round(coord[1] - halfHeight)],
  /** Math.round()
   * The Math.round() function returns the value of a 
   * number rounded to the nearest integer.
   * Math.round() 関数は、最も近似の整数に四捨五入した数
   * の値を返します。
   * (MDN[https://developer.mozilla.org/en-US/docs/Web/
   * JavaScript/Reference/Global_Objects/Math/round])
   */
  topRight: [Math.round(coord[0] + halfWidth), Math.round(coord[1] + halfHeight)]
 };
 labelEngine.ingestLabel(bounds, coord.toString(), 1, canvas, text, false);
 /** ingestLabel
  * Creates a label if it does not already exist, then 
  * adds it to the tree, and renders it based on whether 
  * it can be shown.
  * ラベルがまだ存在しない場合は作成し、ツリーに追加し、表示可
  * 能かどうかに基づいてレンダリングします。
  * (JSDoc[http://tech.geovation.uk/labelgun/documentation/
  * module-labelgun.html])
  */
 /** Number.prototype.toString( [ radix ] )
  * The toString() method returns a string representing 
  * the specified Number object.
  * toString() メソッドは、指定された Number オブジェクトを
  * 表す文字列を返します。
  * radix: 数値を表すために使われる基数を指定する、2 から 36 
  * までの整数。省略したときは 10。
  * MDN([https://developer.mozilla.org/en-US/docs/Web/
  * JavaScript/Reference/Global_Objects/Number/toString])
  */
}
// For multi-polygons, we only label the widest polygon. 
// This is done by sorting by extent width in descending 
// order, and take the first from the array.
// マルチポリゴンの場合、最も幅の広いポリゴンにのみラベルを付
// けます。 これは、範囲の幅を降順でソートし、配列の先頭を取り出
// すことを実行します。
function sortByWidth(a, b) {
 return ol.extent.getWidth(b.getExtent()) - ol.extent.getWidth(a.getExtent());
 /** ol.extent.getWidth(extent)
  * Get the width of an extent.
  * 範囲の幅を取得します。(ol4 API)
  */
 /** getExtent(opt_extent)
  * Get the extent of the geometry.
  * ジオメトリの範囲を取得します。(ol4 API)
  */
}
var labelStyle = new ol.style.Style({
/** ol.style.Style 
 * Container for vector feature rendering styles. Any 
 * changes made to the style or its children through 
 * set*() methods will not take effect until the feature 
 * or layer that uses the style is re-rendered.
 * ベクタフィーチャがスタイルを描画するためのコンテナ。
 * スタイルや set*() メソッドを通じてその子に加えられた変
 * 更は、スタイルを使用するフィーチャまたはレイヤが再レン
 * ダリングされるまで有効になりません。
 * (ol4 API)
 */
 renderer: function(coords, state) {
 /** renderer:
  * Custom renderer. When configured, fill, stroke and 
  * image will be ignored, and the provided function will 
  * be called with each render frame for each geometry.
  * カスタムレンダラ。設定されたとき、fill と stroke、 image
  * は無視され、 提供されたファンクションは各ジオメトリに対する
  * 各描画フレームを呼び出します。
  * (ol4 API)
  */
  var text = state.feature.get('name');
  /** get(key)
   * Gets a value.(ol4 API)
   */
  createLabel(textCache[text], text, coords);
 }
});
var countryStyle = new ol.style.Style({
 fill: new ol.style.Fill({
 /** ol.style.Fill 
  * Set fill style for vector features.
  * ベクタフィーチャの塗りつぶしスタイルを設定。
  * (ol4 API)
  */
  color: 'rgba(255, 255, 255, 0.6)'
  /** color:
   * A color, gradient or pattern. See ol.color and 
   * ol.colorlike for possible formats. Default null; if 
   * null, the Canvas/renderer default black will be 
   * used.
   * 色、グラデーション、または、パターン。 可能な形式について
   * は、ol.color と ol.colorlike を参照してください。 デ
   * フォルト は null。 nullの場合、Canvas/renderer のデ
   * フォルトの黒が使用されます。(ol4 API)
   */
 }),
 stroke: new ol.style.Stroke({
 /** 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 関数は、オプションで入力されたものはすべて返
  * す。それらはデフォルトを返しません。
  * (ol4 API)
  */
  color: '#319FD3',
  /** color:
   * A color, gradient or pattern. See ol.color and 
   * ol.colorlike for possible formats. Default null; if 
   * null, the Canvas/renderer default black will be 
   * used.
   * 色、グラデーション、または、パターン。 可能な形式について
   * は、ol.color と ol.colorlike を参照してください。 デ
   * フォルト は null。 nullの場合、Canvas/renderer のデ
   * フォルトの黒が使用されます。(ol4 API)
   */
  width: 1
 })
});
var styleWithLabel = [countryStyle, labelStyle];
var styleWithoutLabel = [countryStyle];

var pixelRatio; 
// This is set by the map's precompose listener
// これはマップの precompose リスナによって設定されます。
var vectorLayer = new ol.layer.Vector({
/** ol.layer.Vector
 * Vector data that is rendered client-side.
 * クライアント側で描画されるベクタデータ。(ol4 API)
 */
 source: new ol.source.Vector({
 /** ol.source.Vector
  * Provides a source of features for vector layers. 
  * Vector features provided by this source are suitable 
  * for editing. See ol.source.VectorTile for vector 
  * data that is optimized for rendering.
  * ベクタレイヤのフィーチャのソースを用意します。このソース
  * が提供するベクタフィーチャは、編集に適しています。レンダ
  * リングのために最適化されたベクタデータの 
  * ol.source.VectorTile を参照してください。(ol4 API)
  */
  url: 'data/geojson/countries.geojson',
  /** url
   * Setting this option instructs the source to load 
   * features using an XHR loader (see 
   * ol.featureloader.xhr). Use a string and an 
   * ol.loadingstrategy.all for a one-off download of 
   * all features from the given URL. Use a 
   * ol.FeatureUrlFunction to generate the url with 
   * other loading strategies. Requires format to be 
   * set as well. When default XHR feature loader is 
   * provided, the features will be transformed from 
   * the data projection to the view projection during 
   * parsing. If your remote data source does not 
   * advertise its projection properly, this 
   * transformation will be incorrect. For some formats, 
   * the default projection (usually EPSG:4326) can be 
   * overridden by setting the defaultDataProjection 
   * constructor option on the format. Note that if a 
   * source contains non-feature data, such as a 
   * GeoJSON geometry or a KML NetworkLink, these will 
   * be ignored. Use a custom loader to load these.
   * このオプションを設定すると、XHR ローダーを
   * (ol.featureloader.xhr参照)を使用してフィーチャを
   * ロードするためのソースを指示します。指定された URL から
   * のすべてのフィーチャの1回限りのダウンロードのために 
   * string と ol.loadingstrategy.all を使用してくださ
   * い。他のローディングストラテジと共に URL を生成するため
   * に、ol.FeatureUrlFunctionを使用してください。format 
   * も同様に設定する必要があります。デフォルトの XHR フィー
   * チャローダが提供される場合、フィーチャは、解析中にデータ
   * 投影からビュー投影へ変換されます。リモート・データ・ソー
   * スが適切に投影を示していない場合は、この変換は不正確にな
   * ります。いくつかのフォーマットでは、デフォルトの投影(通
   * 常はEPSG:4326)は、フォーマット上の 
   * defaultDataProjection constructor オプションを設
   * 定することで上書きすることができます。ソースが、このよう
   * な GeoJSON ジオメトリ、または、 KML NetworkLink などの
   * 非フィーチャデータを含んでいる場合、これらは無視される
   * ことに注意してください。これらをロードするために、カス
   * タムローダーを使用してください。
   * (ol4 API)
   */
  format: new ol.format.GeoJSON()
  /** format
   * The feature format used by the XHR feature loader when 
   * url is set. Required if url is set, otherwise ignored. 
   * Default is undefined.
   * フィーチャのフォーマットは、url が設定されている場合、XHR
   * フィーチャローダーで使用されます。url が設定されている場
   * 合は必須で、それ以外の場合は無視されます。デフォルトは未
   * 定義です。(ol4 API)
   */
  /** ol.format.GeoJSON 
   * Feature format for reading and writing data in the 
   * GeoJSON format.
   * GeoJSON フォーマットのデータを読み書きするためのフィー
   * チャフォーマット。(ol4 API)
   */
 }),
 style: function(feature, resolution) {
  var text = feature.get('name');
  var width = textMeasureContext.measureText(text).width;
  var geometry = feature.getGeometry();
  /** getGeometry()
   * Get the feature's default geometry. A feature may 
   * have any number of named geometries. The "default" 
   * geometry (the one that is rendered by default) is 
   * set when calling ol.Feature#setGeometry.
   * フィーチャのデフォルトのジオメトリを取得します。フィーチャ
   * は、任意の数の指定のジオメトリのを有することができます。
   * 「デフォルト」のジオメトリ(デフォルトでレンダリングされ
   * るもの)が ol.Feature#setGeometry を呼び出すときに
   * 設定されています。(ol4 API)
   */
  if (geometry.getType() == 'MultiPolygon') {
  /** getType()
   * Get the type of this geometry.(ol4 API)
   */
   geometry = geometry.getPolygons().sort(sortByWidth)[0];
   /** getPolygons()
    * Return the polygons of this multipolygon.
    * このマルチポリゴンのポリゴンを返します。(ol4 API)
    */
   /** Array.prototype.sort()
    * The sort() method sorts the elements of an array in 
    * place and returns the array. The sort is not 
    * necessarily stable. The default sort order is 
    * according to string Unicode code points.
    * sort() メソッドは、配列の要素を所定の位置にソートし、
    * 配列を返します。 ソートは必ずしも安定しているとは限りま
    * せん。 デフォルトのソート順は、文字列の Unicode コード
    * ポイントに従います。
    * MDN([https://developer.mozilla.org/en-US/docs/Web/
    * JavaScript/Reference/Global_Objects/Array/sort])
    */
  }
  var extentWidth = ol.extent.getWidth(geometry.getExtent());
  /** ol.extent.getWidth(extent)
   * Get the width of an extent.
   * 範囲の幅を取得します。(ol4 API)
   */
  if (extentWidth / resolution > width) {
   // Only consider label when it fits its geometry's extent
   // ラベルがジオメトリの範囲と合ったときだけ考慮します。
   if (!(text in textCache)) {
    // Draw the label to its own canvas and cache it.
    // ラベルを canvas に描画し、キャッシュします。
    var canvas = textCache[text] = document.createElement('CANVAS');
    canvas.width = width * pixelRatio;
    canvas.height = height * pixelRatio;
    var context = canvas.getContext('2d');
    context.scale(pixelRatio, pixelRatio);
    /** CanvasRenderingContext2D.scale()
     * The CanvasRenderingContext2D.scale() method of the 
     * Canvas 2D API adds a scaling transformation to the 
     * canvas units by x horizontally and by y vertically.
     * Canvas 2D API の CanvasRenderingContext2D.scale()
     * メソッドは、x 水平方向、および y 垂直方向によってキャン
     * バス単位に伸縮変形を追加します。
     * (MDN[https://developer.mozilla.org/en-US/docs/Web/
     * API/CanvasRenderingContext2D/scale])
     */
    setStyle(context);
    context.strokeText(text, 0, 0);
    /** CanvasRenderingContext2D.strokeText()
     * The CanvasRenderingContext2D.strokeText() method of 
     * the Canvas 2D API strokes a given text at the given 
     * (x, y) position. If the optional fourth parameter for 
     * a maximum width is provided, the text will be scaled 
     * to fit that width.
     * Canvas 2D API のCanvasRenderingContext2D.strokeText() 
     * メソッドは、指定された(x、y)位置にテキストを描画します。 
     * 最大幅のオプションの4番目のパラメータを指定すると、テキス
     * トはその幅に合わせて拡大/縮小されます。
     * (MDN[https://developer.mozilla.org/en-US/docs/Web/
     * API/CanvasRenderingContext2D/strokeText])
     */
    context.fillText(text, 0, 0);
    /** CanvasRenderingContext2D.fillText()
     * The CanvasRenderingContext2D.fillText() method of the 
     * Canvas 2D API fills a given text at the given (x, y) 
     * position. If the optional fourth parameter for a 
     * maximum width is provided, the text will be scaled to 
     * fit that width.
     * Canvas 2D APIのCanvasRenderingContext2D.fillText() 
     * メソッドは、指定された(x、y)位置で指定されたテキストを
     * 塗りつぶします。 最大幅のオプションの4番目のパラメータを
     * 指定すると、テキストはその幅に合わせて拡大/縮小されます。
     * (MDN[https://developer.mozilla.org/en-US/docs/Web/
     * API/CanvasRenderingContext2D/fillText])
     */
   }
   labelStyle.setGeometry(geometry.getInteriorPoint());
   /** setGeometry()
    * Set the geometry for this feature. This will update 
    * the property with the current name eturned by 
    * rol.Feature#getGeometryName. 
    * このフィーチャのジオメトリを設定します。これは、
    * ol.Feature#getGeometryName によって返された、現在の
    * 名前とともにプロパティを更新します。
    * (ol4 API)
    */
   /** getInteriorPoints()
    * Return the interior points as multipoint.
    * 内部の点をマルチポイントとして返します。
    * (ol4 API)
    */
   return styleWithLabel;
  } else {
   return styleWithoutLabel;
  }
 }
});
vectorLayer.on('precompose', function(e) {
/** on(type, listener, opt_this)
 * Listen for a certain type of event.
 * ある型のイベントをリッスンします。(ol4 API)
 */
pixelRatio = e.frameState.pixelRatio;
/** frameState
 * An object representing the current render frame state.
 * 現在の描画フレームの状態を表すオブジェクト。(ol4 API)
 */
 labelEngine.destroy();
 /** destroy()
  * Destroy the collision tree and labels.
  * コリジョン(衝突)ツリーとラベルを破棄します。
  * (JSDoc[http://tech.geovation.uk/labelgun/documentation/
  * labelgun.html])
  */
});
vectorLayer.on('postcompose', function(e) {
 var labels = labelEngine.getShown();
 /** getShown()
  * Return an array of all shown labels.
  * 表示されたラベルすべての配列を返します。
  * (JSDoc[http://tech.geovation.uk/labelgun/documentation/
  * labelgun.html])
  */
 for (var i = 0, ii = labels.length; i < ii; ++i) {
  var label = labels[i];
  // Draw label to the map canvas
  // ラベルをマップ canvas に描画します。
  e.context.drawImage(label.labelObject, label.minX, label.minY);
  /** CanvasRenderingContext2D.drawImage()
   * The CanvasRenderingContext2D.drawImage() method of 
   * the Canvas 2D API provides different ways to draw 
   * an image onto the canvas.
   * Canvas 2D API の CanvasRenderingContext2D.drawImage() 
   * メソッドは、イメージをキャンバスに描画するさまざまな方法を提
   * 供します。
   * (MDN[https://developer.mozilla.org/en-US/docs/Web/
   * API/CanvasRenderingContext2D/drawImage])
   */
 }
});
map.addLayer(vectorLayer);
/** addLayer(layer)
 * Adds the given layer to the top of this map.
 * 与えられたレイヤをこのマップの一番上に追加します。(ol4 API)
 */
 
 

2017年4月22日土曜日

2 - ol4.1ex 170b - Custom Overview Map 2

「overviewmap-custom.js(2170-ol4ex.js)」は、マップを表示するための JavaScript ファイルです。

「2170-ol4ex.js」
var overviewMapControl = new ol.control.OverviewMap({
/** new ol.control.OverviewMap(opt_options)
 * Create a new control with a map acting as an overview 
 * map for an other defined map.
 * もうひとつの定義されたマップの概要マップとして動作するマッ
 * プで新しいコントロールを作成します。(ol4 API)
 */
 // see in overviewmap-custom.html to see the custom CSS 
 // used
 // 使用されたカスタム CSS を知るために 
 // overviewmap-custom.html をみてください。
 className: 'ol-overviewmap ol-custom-overviewmap',
 layers: [
 /** layers
  * Layers for the overview map. If not set, then all 
  * main map layers are used instead.
  * 概要マップのレイヤー。 設定されていない場合は、すべての
  * メインマップレイヤが代わりに使用されます。(ol4 API)
  */
  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. 
   * プリレンダリング(事前描画)を提供するレイヤソースのた
   * めの、特定の解像度でのズームレベルによって編成されてい
   * るグリッドのタイルイメージ。(ol4 API)
   */
   source: new ol.source.OSM({
   /** ol.source.OSM 
    * Layer source for the OpenStreetMap tile server.
    * OpenStreetMap タイルサーバのレイヤソース。(ol4 API)
    */
    'url': 'https://{a-c}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png' +
      '?apikey=0e6fc...(省略)'
   })
  })
 ],
  collapseLabel: '\u00BB',
  /** collapseLabel
   * Text label to use for the expanded overviewmap 
   * button. Default is «. Instead of text, also a Node 
   * (e.g. a span element) can be used.
   * 展開される overviewmap ボタンに使用するテキストラベル。 
   * デフォルトは « です。 テキストの代わりに、ノード(例え
   * ば、span 要素)も使用することができます。(ol4 API)
   */
  label: '\u00AB',
  /** label
   * Text label to use for the collapsed overviewmap 
   * button. Default is ». Instead of text, also a Node 
   * (e.g. a span element) can be used.
   * 折りたたまれる overviewmap ボタンに使用するテキストラベ
   * ル。 デフォルトは « です。 テキストの代わりに、ノード(例
   * えば、span 要素)も使用することができます。(ol4 API)
   */
  collapsed: false
  /** collapsed
   * Whether the control should start collapsed or not 
   * (expanded). Default to true.
   * コントロール(control)が折りたたみ(展開)を開始するか
   * どうか。デフォルトは true です。(ol4 API)
   */
});
var map = new ol.Map({
 controls: ol.control.defaults().extend([
 /** controls
  * Controls initially added to the map. 
  * If not specified, ol.control.defaults() is used.
  * 初期設定で、マップに追加されたコントロール。
  * 明示されていなければ、ol.control.defaults() が使用され
  * ます。(ol4 API)
  */
 /** ol.control.defaults(opt_options)
  * Set of controls included in maps by default. Unless 
  * configured otherwise, this returns a collection 
  * containing an instance of each of the following 
  * controls:
  * ol.control.Zoom, ol.control.Rotate, 
  * ol.control.Attribution
  * デフォルトでは、マップに含まれるコントロールのセット。
  * 特に設定しない限り、これは、次の各コントロールのインス
  * タンスを含むコレクションを返します。(ol4 API)
  */
  overviewMapControl
 ]),
 interactions: ol.interaction.defaults().extend([
 /** interactions
  * Interactions that are initially added to the map. 
  * If not specified, ol.interaction.defaults() is 
  * used.
  * 最初にマップに追加されるインタラクション。 指定しない場
  * 合、ol.interaction.defaults()が使用されます。
  * (ol4 API)
  */
  new ol.interaction.DragRotateAndZoom()
  /** ol.interaction.DragRotateAndZoom 
   * Allows the user to zoom and rotate the map by clicking 
   * and dragging on the map. By default, this interaction 
   * is limited to when the shift key is held down.
   * This interaction is only supported for mouse devices.
   * And this interaction is not included in the default 
   * interactions.
   * マップ上をクリックとドラッグすることで、マップをズーム
   * し、回転することを許可します。デフォルトでは、このイン
   * ターラクションは、シフトキーを押しているときに制限され
   * ています。
   * このインターラクションは、マウスデバイスだけサポートし
   * ます。
   * このインターラクションは、デフォルトのインターラクショ
   * ンに含まれません。(ol4 API)
   */
 ]),
 layers: [
  new ol.layer.Tile({
   source: new ol.source.OSM()
  })
 ],
 target: 'map',
 view: new ol.View({
  center: [500000, 6000000],
  zoom: 7
 })
});
 

2 - ol4.1ex 169b - View Min-Zoom 2

「min-zoom.js(2169-ol4ex.js)」は、マップを表示するための JavaScript ファイルです。

「2169-ol4ex.js」
var viewport = document.getElementById('map');
function getMinZoom() {
 var width = viewport.clientWidth;
 return Math.ceil(Math.LOG2E * Math.log(width / 256));
 /** Math.ceil()
  * The Math.ceil() function returns the smallest integer 
  * greater than or equal to a given number.
  * 引数として与えた数以上の最小の整数を返します。
  * (MDN[https://developer.mozilla.org/ja/docs/Web/
  * JavaScript/Reference/Global_Objects/Math/ceil])
  */
 /** Math.LOG2E()
  * The Math.LOG2E property represents the base 2 logarithm  
  * of e, approximately 1.442:
  * 2 を底とした E の対数。約 1.442 です。
  * (MDN[https://developer.mozilla.org/ja/docs/Web/
  * JavaScript/Reference/Global_Objects/Math/LOG2E])
  */
 /** Math.log()
  * The Math.log() function returns the natural logarithm  
  * (base e) of a number.
  * Math.log() 関数は、引数として与えた数の自然対数 (底は e) 
  * を返します。
  * (MDN[https://developer.mozilla.org/ja/docs/Web/
  * JavaScript/Reference/Global_Objects/Math/log])
  */
}
var initialZoom = getMinZoom();
var view = new ol.View({
 center: [0, 0],
 minZoom: initialZoom,
 zoom: initialZoom
});
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. 
   * プリレンダリング(事前描画)を提供するレイヤソースのため
   * の、特定の解像度でのズームレベルによって編成されているグ
   * リッドのタイルイメージ。(ol4 API)
   */
   source: new ol.source.OSM()
   /** ol.source.OSM 
    * Layer source for the OpenStreetMap tile server.
    * OpenStreetMap タイルサーバのレイヤソース。(ol4 API)
    */
  })
 ],
 target: 'map',
 view: view
});
window.addEventListener('resize', function() {
/** EventTarget.addEventListener
 * The EventTarget.addEventListener() method registers 
 * the specified listener on the EventTarget it's called 
 * on. The event target may be an Element in a document, 
 * the Document itself, a Window, or any other object 
 * that supports events (such as XMLHttpRequest).
 * EventTarget.addEventListener() メソッドは、それが呼び
 * 出される EventTarget に指定されたリスナを登録します。イベ
 * ントターゲットは、ドキュメントの Element、Document 自身、
 * Window、または(XMLHttpRequest などの)イベントをサポート
 * している他のオブジェクトです。
 * (MDN[https://developer.mozilla.org/en-US/docs/Web/
 * API/EventTarget/addEventListener])
 */
 var minZoom = getMinZoom();
 if (minZoom !== view.getMinZoom()) {
 /** getMinZoom()
  * Get the minimum zoom level for the view.
   * view の最小ズームレベルを取得します。(ol4 API)
  */
  view.setMinZoom(minZoom);
  /** setMinZoom(zoom)
   * Set a new minimum zoom level for the view.
   * view の最小ズームレベルを設定します。(ol4 API)
   */
 }
});
 
 

2017年2月28日火曜日

2 - ol4.0ex 168b - Magnify 2

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

「2168-ol4ex.js」

var key = 'As1Hi...(省略)';
var imagery = 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. 
 * プリレンダリング(事前描画)を提供するレイヤソースのため
 * の、特定の解像度でのズームレベルによって編成されているグ
 * リッドのタイルイメージ。(ol4 API)
 */
 source: new ol.source.BingMaps({key: key, imagerySet: 'Aerial'})
 /** ol.source.BingMaps
  * Layer source for Bing Maps tile data.
  * Bing Maps タイルデータのレイヤソース。(ol4 API)
  */
});
var container = document.getElementById('map');

var map = new ol.Map({
 layers: [imagery],
 target: container,
 view: new ol.View({
  center: ol.proj.fromLonLat([-109, 46.5]),
  zoom: 6
 })
});
var radius = 75;
document.addEventListener('keydown', function(evt) {
/** EventTarget.addEventListener
 * The EventTarget.addEventListener() method registers 
 * the specified listener on the EventTarget it's called 
 * on. The event target may be an Element in a document, 
 * the Document itself, a Window, or any other object 
 * that supports events (such as XMLHttpRequest).
 * EventTarget.addEventListener() メソッドは、それが呼び
 * 出される EventTarget に指定されたリスナを登録します。イベ
 * ントターゲットは、ドキュメントの Element、Document 自身、
 * Window、または(XMLHttpRequest などの)イベントをサポート
 * している他のオブジェクトです。
 * (MDN[https://developer.mozilla.org/en-US/docs/Web/
 * API/EventTarget/addEventListener])
 */
 if (evt.which === 38) {
 /** KeyboardEvent.which [Deprecated]
  * The KeyboardEvent.which read-only property returns the 
  * numeric keyCode of the key pressed, or the character 
  * code (charCode) for an alphanumeric key pressed.
  * KeyboardEvent.which 読み取り専用プロパティは、押されたキー
  * の数値 keyCode、または、押された英数字キーの文字コード
  * (charCode)を返します。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/
  * API/KeyboardEvent/which])
  */
  radius = Math.min(radius + 5, 150);
  /** Math.min() 
   * 引数として与えた複数の数の中で最小の数を返します。
   * (MDN[https://developer.mozilla.org/ja/docs/Web/
   * JavaScript/Reference/Global_Objects/Math/min])
   */
  map.render();
  /** render()
   * Request a map rendering (at the next animation 
   * frame).
   * (次のアニメーションフレームで)map 描画を要求します。
   * (ol4 API)
   */
  evt.preventDefault();
  /** Event.preventDefault()
   * Cancels the event if it is cancelable, without 
   * stopping further propagation of the event.
   * イベントのさらなる伝播を停止させることなく、解約された場合
   * に、イベントをキャンセルします。
   * (MDN[https://developer.mozilla.org/en-US/docs/Web/
   * API/Event/preventDefault])
   */
 } else if (evt.which === 40) {
  radius = Math.max(radius - 5, 25);
  /** Math.max() 
   * 引数として与えた複数の数の中で最大の数を返します。
   * (MDN[https://developer.mozilla.org/ja/docs/Web/
   * JavaScript/Reference/Global_Objects/Math/max])
   */
  map.render();
  evt.preventDefault();
 }
});
// get the pixel position with every move
// 移動時毎にピクセル位置を取得
var mousePosition = null;
container.addEventListener('mousemove', function(event) {
 mousePosition = map.getEventPixel(event);
 /** getEventPixel()
  * Returns the map pixel position for a browser event 
  * relative to the viewport.
  * ビューポートと相対的な、ブラウザイベントに対しするマップのピ
  * クセル位置を返します。
  * (ol4 API)
  */
 map.render();
});
container.addEventListener('mouseout', function() {
 mousePosition = null;
 map.render();
});
// after rendering the layer, show an oversampled 
// version around the pointer
// レイヤをレンダリング後、ポインタの周囲にオーバーサンプルされ
// たバージョンを表示
imagery.on('postcompose', function(event) {
/** on(type, listener, opt_this)
 * Listen for a certain type of event.
 * あるタイプのイベントをリッスンします。(ol4 API)
 */
 if (mousePosition) {
  var context = event.context;
  var pixelRatio = event.frameState.pixelRatio;
  /** frameState{olx.FrameState}
   * The frame state at the time of the event.
   * イベント時のフレームの状態。(ol4 API)
   */
  var half = radius * pixelRatio;
  var centerX = mousePosition[0] * pixelRatio;
  var centerY = mousePosition[1] * pixelRatio;
  var originX = centerX - half;
  var originY = centerY - half;
  var size = 2 * half + 1;
  var sourceData = context.getImageData(originX, originY, size, size).data;
  /** CanvasRenderingContext2D.getImageData()
   * The CanvasRenderingContext2D.getImageData() method of 
   * the Canvas 2D API returns an ImageData object 
   * representing the underlying pixel data for the area 
   * of the canvas denoted by the rectangle which starts 
   * at (sx, sy) and has an sw width and sh height. This 
   * method is not affected by the canvas transformation 
   * matrix.
   * Canvas 2D API の 
   * CanvasRenderingContext2D.getImageData() 
   * メソッドは、(sx、sy)で始まりsw幅とsh高さを有している
   * 四角形で示される、キャンバス(canvas)の領域の基礎となる
   * ピクセルデータを表す ImageData オブジェクトを返します。
   * このメソッドは、canvas 変換行列の影響を受けません。
   * Syntax
   * ImageData ctx.getImageData(sx, sy, sw, sh);
   * (MDN[https://developer.mozilla.org/en-US/docs/Web/
   * API/CanvasRenderingContext2D/getImageData])
   */
  var dest = context.createImageData(size, size);
  /** CanvasRenderingContext2D.createImageData()
   * The CanvasRenderingContext2D.createImageData() 
   * method of the Canvas 2D API creates a new, blank 
   * ImageData object with the specified dimensions. 
   * All of the pixels in the new object are transparent 
   * black.
   * Canvas 2D APIの 
   * CanvasRenderingContext2D.createImageData()メソッド
   * は、指定された大きさで新しい、空白の ImageData オブジェ
   * クトを作成します。新しいオブジェクトの全ての画素は透明
   * な黒です。
   * (MDN[https://developer.mozilla.org/en-US/docs/Web/
   * API/CanvasRenderingContext2D/createImageData])
   */
  var destData = dest.data;
  for (var j = 0; j < size; ++j) {
   for (var i = 0; i < size; ++i) {
    var dI = i - half;
    var dJ = j - half;
    var dist = Math.sqrt(dI * dI + dJ * dJ);
    /** Math.sqrt()
     * 引数として与えた数の平方根を返します。
     * (MDN[https://developer.mozilla.org/ja/docs/Web/
     * JavaScript/Reference/Global_Objects/Math/sqrt])
     */
    var sourceI = i;
    var sourceJ = j;
    if (dist < half) {
     sourceI = Math.round(half + dI / 2);
     /** Math.round()
      * 引数として与えた数を四捨五入して、最も近似の整数を返しま
      * す。
      * (MDN[https://developer.mozilla.org/ja/docs/Web/
      * JavaScript/Reference/Global_Objects/Math/round])
      */
     sourceJ = Math.round(half + dJ / 2);
    }
    var destOffset = (j * size + i) * 4;
    var sourceOffset = (sourceJ * size + sourceI) * 4;
    destData[destOffset] = sourceData[sourceOffset];
    destData[destOffset + 1] = sourceData[sourceOffset + 1];
    destData[destOffset + 2] = sourceData[sourceOffset + 2];
    destData[destOffset + 3] = sourceData[sourceOffset + 3];
   }
  }
  context.beginPath();
  /** CanvasRenderingContext2D.beginPath()
   * The CanvasRenderingContext2D.beginPath() method of the 
   * Canvas 2D API starts a new path by emptying the list 
   * of sub-paths. Call this method when you want to create 
   * a new path.
   * Canvas 2D API の CanvasRenderingContext2D.beginPath() 
   * メソッドは、サブパスのリストを空にすることによって新しいパ
   * スを開始します。新しいパスを作成したいときに、このメソッド
   * を呼び出します。
   * (MDN[https://developer.mozilla.org/en-US/docs/Web/
   * API/CanvasRenderingContext2D/beginPath])
   */
  context.arc(centerX, centerY, half, 0, 2 * Math.PI);
  /** CanvasRenderingContext2D.arc() 
   * The CanvasRenderingContext2D.arc() method of the 
   * Canvas 2D API adds an arc to the path which is 
   * centered at (x, y) position with radius r starting at 
   * startAngle and ending at endAngle going in the given 
   * direction by anticlockwise (defaulting to clockwise).
   * Canvas 2D API の CanvasRenderingContext2D.arc() メ
   * ソッドは、半径 r の位置(x、y)を中心とする反時計回り(初
   * 期値は時計回り)に startAngle で始まり endAngle で終わる
   * 弧をパスに追加します。
   * (MDN[https://developer.mozilla.org/en-US/docs/Web/
   * API/CanvasRenderingContext2D/arc])
   */
  /** Math.PI()
   * 円周率。約 3.14159 です。
  * (MDN[https://developer.mozilla.org/ja/docs/Web
  * /JavaScript/Reference/Global_Objects/Math/PI])
  */
  context.lineWidth = 3 * pixelRatio;
  /** CanvasRenderingContext2D.lineWidth
   * The CanvasRenderingContext2D.lineWidth property of 
   * the Canvas 2D API sets the thickness of lines in 
   * space units. When getting, it returns the current 
   * value (1.0 by default). When setting, zero, negative, 
   * Infinity and NaN values are ignored; otherwise the 
   * current value is set to the new value.
   * Canvas 2D API の CanvasRenderingContext2D.lineWidth
   * プロパティは、空間単位で線の太さを設定します。取得する
   * と、現在の値(デフォルトでは1.0)を返します。設定時、 
   * ゼロ、負、無限大とNaN値は無視されます。それ以外の場合、
   * 現在の値は新しい値に設定されてます。
   * (MDN[https://developer.mozilla.org/en-US/docs/Web/
   * API/CanvasRenderingContext2D/lineWidth])
   */
  context.strokeStyle = 'rgba(255,255,255,0.5)';
  /** CanvasRenderingContext2D.strokeStyle
   * The CanvasRenderingContext2D.strokeStyle property of 
   * the Canvas 2D API specifies the color or style to 
   * use for the lines around shapes. The default is #000 
   * (black).
   * Canvas 2D APIのCanvasRenderingContext2D.strokeStyle
   * プロパティは、図形の外周の線に使用する色やスタイルを指定
   * します。デフォルトは#000(黒)です。
   * (MDN[https://developer.mozilla.org/en-US/docs/Web/
   * API/CanvasRenderingContext2D/strokeStyle])
   */
  context.putImageData(dest, originX, originY);
  /** CanvasRenderingContext2D.putImageData()
   * The CanvasRenderingContext2D.putImageData() method 
   * of the Canvas 2D API paints data from the given 
   * ImageData object onto the bitmap. If a dirty 
   * rectangle is provided, only the pixels from that 
   * rectangle are painted.
   * Canvas 2D API の 
   * CanvasRenderingContext2D.getImageData() 
   * メソッドは、与えられたの ImageData オブジェクトからビッ
   * トマップにデータをペイントします。汚れた矩形が提供される
   * 場合、その長方形のピクセルのみが描かれています。
   * Syntax
   * void ctx.putImageData(imagedata, dx, dy);
   * void ctx.putImageData(imagedata, dx, dy, dirtyX, 
   *  dirtyY, dirtyWidth, dirtyHeight);
   * (MDN[https://developer.mozilla.org/en-US/docs/Web/
   * API/CanvasRenderingContext2D/putImageData])
   */
  context.stroke();
  /** CanvasRenderingContext2D.stroke()
   * The CanvasRenderingContext2D.stroke() method of the 
   * Canvas 2D API strokes the current or given path with 
   * the current stroke style using the non-zero winding 
   * rule.
   * Canvas 2D APIのCanvasRenderingContext2D.stroke()
   * メソッドは、ノンゼロワインディング規則を使用して、現在
   * の線のスタイルを持つ現在または与えられたパスを引きます。
   * (MDN[https://developer.mozilla.org/en-US/docs/Web/
   * API/CanvasRenderingContext2D/stroke])
   */
  context.restore();
  /** CanvasRenderingContext2D.restore()
   * The CanvasRenderingContext2D.restore() method of the 
   * Canvas 2D API restores the most recently saved canvas 
   * state by popping the top entry in the drawing state 
   * stack. If there is no saved state, this method does 
   * nothing.
   * Canvas 2D API の CanvasRenderingContext2D.restore()
   * メソッドは、描画状態のスタックの一番上のエントリを抜き
   * 出すことによって、最後に保存されたキャンバスの状態を復
   * 元します。全く保存された状態が存在しない場合、このメソッ
   * ドは何もしません。
   * (MDN[https://developer.mozilla.org/en-US/docs/Web/
   * API/CanvasRenderingContext2D/restore])
   */
 }
});
 
 

2 - ol4.0ex 167b - Hit Tolerance 2

「hit-tolerance.js(2167-ol4ex.js)」は、マップを表示するための JavaScript ファイルです。

「2167-ol4ex.js」
var raster = 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. 
  * プリレンダリング(事前描画)を提供するレイヤソースのため
  * の、特定の解像度でのズームレベルによって編成されているグ
  * リッドのタイルイメージ。(ol4 API)
  */
 source: new ol.source.OSM()
 /** ol.source.OSM 
  * Layer source for the OpenStreetMap tile server.
  * OpenStreetMap タイルサーバのレイヤソース。(ol4 API)
  */
});
var style = new ol.style.Style({
/** ol.style.Style 
 * Container for vector feature rendering styles. Any 
 * changes made to the style or its children through 
 * set*() methods will not take effect until the feature 
 * or layer that uses the style is re-rendered.
 * ベクタフィーチャがスタイルを描画するためのコンテナ。
 * スタイルや set*() メソッドを通じてその子に加えられた変
 * 更は、スタイルを使用するフィーチャまたはレイヤが再レン
 * ダリングされるまで有効になりません。
 * (ol4 API)
 */
 stroke: new ol.style.Stroke({
 /** 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 関数は、オプションで入力されたものはすべて返
  * します。それらはデフォルトを返しません。
  * (ol4 API)
  */
  color: 'black',
  /** color:
   * A color, gradient or pattern. See ol.color and 
   * ol.colorlike for possible formats. Default null; 
   * if null, the Canvas/renderer default black will 
   * be used.
   * 色、グラデーションまたはパターン。可能なフォーマットの対
   * する ol.color と oil.color を参照してください。デフォル
   * トは null; null の場合は、Canvas/renderer デフォルトの
   * 黒が使用されます。
   * (ol4 API)
   */
  width: 1
 })
});
var feature = new ol.Feature(new ol.geom.LineString([[-4000000, 0], [4000000, 0]]));
/** ol.Feature
 * A vector object for geographic features with a 
 * geometry and other attribute properties, similar 
 * to the features in vector file formats like 
 * GeoJSON.
 * GeoJSONのようなベクトルファイル形式のフィーチャに類
 * 似した、ジオメトリとその他の属性プロパティを持つ地物
 * フィーチャのためのベクトルオブジェクト。(ol4 API)
 */
/** ol.geom.LineString
 * Linestring geometry.(ol4 API)
 */
var vector = new ol.layer.Vector({
/** ol.layer.Vector
 * Vector data that is rendered client-side.
 * クライアント側で描画されるベクタデータ。(ol4 API)
 */
 source: new ol.source.Vector({
 /** ol.source.Vector
  * Provides a source of features for vector layers. 
  * Vector features provided by this source are suitable 
  * for editing. See ol.source.VectorTile for vector 
  * data that is optimized for rendering.
  * ベクタレイヤのフィーチャのソースを用意します。このソース
  * が提供するベクタフィーチャは、編集に適しています。レンダ
  * リングのために最適化されたベクタデータの 
  * ol.source.VectorTile を参照してください。(ol4 API)
  */
  features: [feature]
  /** features:
   * Features. If provided as ol.Collection, the features 
   * in the source and the collection will stay in sync.
   * フィーチャ。 ol.Collectionとして提供されている場合、ソー
   * スとコレクションのフィーチャは同期しています。(ol4 API)
   */
 }),
 style: style
});
var map = new ol.Map({
 layers: [raster, vector],
 target: 'map',
 view: new ol.View({
  center: [0, 0],
  zoom: 2
 })
});
var hitTolerance;

var statusElement = document.getElementById('status');
map.on('singleclick', function(e) {
/** on(type, listener, opt_this)
 * Listen for a certain type of event.
 * あるタイプのイベントをリッスンします。(ol4 API)
 */
 var hit = false;
 map.forEachFeatureAtPixel(e.pixel, function() {
 /** forEachFeatureAtPixel(pixel, callback, opt_this)
  * Detect features that intersect a pixel on the viewport, 
  * and execute a callback with each intersecting feature. 
  * Layers included in the detection can be configured 
  * through opt_layerFilter. 
  * ビューポート上のピクセルと交差するフィーチャを検出し、互
  * いに交差するフィーチャと共にコールバックを実行します。
  * 検出に含まれるレイヤが opt_layerFilter を通じて設定する
  * ことができます。(ol4 API)
  */
  hit = true;
 }, {
  hitTolerance: hitTolerance
  /** hitTolerance:
   * Hit-detection tolerance in pixels. Pixels inside the 
   * radius around the given position will be checked for 
   * features. This only works for the canvas renderer and 
   * not for WebGL. Default is 0.
   * Hit-detection の許容差(ピクセル単位)。 指定された位置を
   * 中心とした半径内のピクセルがフィーチャのチェックに使われま 
   * す。canvas レンダラのみで、WebGLでは使用できません。 デ
   * フォルトは0です。(ol4 API)
   */
 });
 if (hit) {
  style.getStroke().setColor('green');
  /** getStroke()
   * Get the stroke style.(ol4 API)
   */
  /** setColor(color)
   * Set the color.(ol4 API)
   */
  statusElement.innerHTML = ' A feature got hit!';
  /** Element.innerHTML
   * The Element.innerHTML property sets or gets the HTML 
   * syntax describing the element's descendants.
   * Element.innerHTMLプロパティは、要素(element)の子孫を説
   * 明する HTML 構文を設定、または、取得します。
   * (MDN[https://developer.mozilla.org/en-US/docs/Web/
   * API/Element/innerHTML])
   */
 } else {
  style.getStroke().setColor('black');
  statusElement.innerHTML = ' No feature got hit.';
 }
 feature.changed();
 /** changed()
  * Increases the revision counter and dispatches a 'change' 
  * event.
  * リビジョンカウンタを増派し、 「change」イベントを送出します。
  * (ol4 API)
  */
});
var selectHitToleranceElement = document.getElementById('hitTolerance');
var circleCanvas = document.getElementById('circle');
var changeHitTolerance = function() {
 hitTolerance = parseInt(selectHitToleranceElement.value, 10);
 /** parseInt(string, radix)
  * string: 文字列, radix: 基数(進法)
  * parseInt()関数は、第1引数の文字列を解析(パース)し、第2引数
  * に与えられた基数(数学的記数法の底)にもとづく整数を返します。
  * (MDN[https://developer.mozilla.org/ja/docs/Web/
  * JavaScript/Reference/Global_Objects/parseInt])
  */
 var size = 2 * hitTolerance + 2;
 circleCanvas.width = size;
 circleCanvas.height = size;
 var ctx = circleCanvas.getContext('2d');
 /** HTMLCanvasElement.getContext()
  * The HTMLCanvasElement.getContext() method returns a 
  * drawing context on the canvas, or null if the 
  * context identifier is not supported.
  * HTMLCanvasElement.getContext()メソッドは、キャンバ
  * ス上の描画コンテキストを返すか、または コンテキスト識別
  * 子がサポートされていない場合、null を返します。
  * contextType Is a DOMString containing the context 
  * identifier defining the drawing context associated 
  * to the canvas.
  * "2d", leading to the creation of a 
  * CanvasRenderingContext2D object representing a 
  * two-dimensional rendering context.
  * contextTypeは canvas に関連する描画コンテキストを定義
  * するコンテキスト識別子を含む DOMString  です。
  * 「2d」、二次元のレンダリングコンテキストを表す
  * CanvasRenderingContext2D オブジェクトの作成につなが
  * ります。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/
  * API/HTMLCanvasElement/getContext])
  */
 ctx.clearRect(0, 0, size, size);
 /** CanvasRenderingContext2D.clearRect()
  * The CanvasRenderingContext2D.clearRect() method of the 
  * Canvas 2D API sets all pixels in the rectangle defined 
  * by starting point (x, y) and size (width, height) to 
  * transparent black, erasing any previously drawn content.
  * Canvas 2D APIのCanvasRenderingContext2D.clearRect() 
  * メソッドは、開始点(x、y)とサイズ(幅、高さ)で定義された
  * 矩形のすべてのピクセルを、以前に描画された内容を透過な黒に
  * するように設定します。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/API/
  * CanvasRenderingContext2D/clearRect])
  */
 ctx.beginPath();
 /** CanvasRenderingContext2D.beginPath()
  * The CanvasRenderingContext2D.beginPath() method of the 
  * Canvas 2D API starts a new path by emptying the list of 
  * sub-paths. Call this method when you want to create a 
  * new path.
  * Canvas 2D APIのCanvasRenderingContext2D.beginPath() 
  * メソッドは、サブパスのリストを空にして新しいパスを開始しま
  * す。新しいパスを作成する場合は、このメソッドを呼び出します。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/API/
  * CanvasRenderingContext2D/beginPath])
  */
 ctx.arc(hitTolerance + 1, hitTolerance + 1, hitTolerance + 0.5, 0, 2 * Math.PI);
 /** CanvasRenderingContext2D.arc()
  * The CanvasRenderingContext2D.arc() method of the Canvas 
  * 2D API adds an arc to the path which is centered at 
  * (x, y) position with radius r starting at startAngle and 
  * ending at endAngle going in the given direction by 
  * anticlockwise (defaulting to clockwise).
  * 
  * void ctx.arc(x, y, radius, startAngle, endAngle, 
  * anticlockwise);
  * x: The x coordinate of the arc's center.
  * y: The y coordinate of the arc's center.
  * radius: The arc's radius.
  * startAngle: The angle at which the arc starts, measured 
  *  clockwise from the positive x axis and expressed in 
  *  radians.
  * endAngle: The angle at which the arc ends, measured 
  *  clockwise from the positive x axis and expressed in 
  *  radians.
  * anticlockwise: Optional An optional Boolean which, if 
  *  true, causes the arc to be drawn counter-clockwise 
  *  between the two angles. By default it is drawn 
  *  clockwise.
  *  
  * Canvas 2D APIのCanvasRenderingContext2D.arc()メソッ
  * ドは、startAngleで始まりendAngleで終わる半径rの(x、y)位
  * 置を中心にしたパスに反時計回り(デフォルトは時計回り)に円
  * 弧を追加します。 
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/API/
  * CanvasRenderingContext2D/arc])
  */
 ctx.fill();
 /** CanvasRenderingContext2D.fill()
  * The CanvasRenderingContext2D.fill() method of the 
  * Canvas 2D API fills the current or given path with the 
  * current fill style using the non-zero or even-odd 
  * winding rule.
  * Canvas 2D APIのCanvasRenderingContext2D.fill() メソッド
  * は、現在の、または、指定されたパスを、非ゼロ、または、奇数
  * のワインディングルールを使用して現在の塗りつぶしスタイルで
  * 塗りつぶします。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/API/
  * CanvasRenderingContext2D/fill])
  */
 ctx.stroke();
 /** CanvasRenderingContext2D.stroke()
  * The CanvasRenderingContext2D.stroke() method of the 
  * Canvas 2D API strokes the current or given path with the 
  * current stroke style using the non-zero winding rule.
  * Canvas 2D APIのCanvasRenderingContext2D.stroke() メソッド
  * は、非ゼロのワインディングルールを使用して、現在の、または、
  * 指定されたパスを現在のストロークスタイルでストロークします。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/API/
  * CanvasRenderingContext2D/stroke])
  */
};
selectHitToleranceElement.onchange = changeHitTolerance;
/** GlobalEventHandlers.onchange()
 * The onchange property sets and returns the event handler 
 * for the change event.
 * onchange プロパティは、change イベントに対してイベントハ
 * ンドラを設定、および、返します。
 * (MDN[https://developer.mozilla.org/en-US/docs/Web/
 * API/GlobalEventHandlers/onchange])
 */
changeHitTolerance();
 

2 - ol4.0ex 166b - geojson-vt integration 2

「geojson-vt.js(2166-ol4ex.js)」は、マップを表示するための JavaScript ファイルです。

「2166-ol4ex.js」
var replacer = function(key, value) {
 if (value.geometry) {
  var type;
  var rawType = value.type;
  var geometry = value.geometry;

  if (rawType === 1) {
   type = geometry.length === 1 ? 'Point' : 'MultiPoint';
   /** 条件演算子 condition ? expr1 : expr2 
    * condition: true か false かを評価する条件文です。
    * expr1, expr2: 各々の値の場合に実行する式です。
    * condition が true の場合、演算子は expr1 の値を選択しま
    * す。そうでない場合は expr2 の値を選択します。
    * (MDN[https://developer.mozilla.org/ja/docs/Web/
    * JavaScript/Reference/Operators/
    * Conditional_Operators])
    */
  } else if (rawType === 2) {
   type = geometry.length === 1 ? 'LineString' : 'MultiLineString';
  } else if (rawType === 3) {
   type = geometry.length === 1 ? 'Polygon' : 'MultiPolygon';
  }
  return {
   'type': 'Feature',
   'geometry': {
    'type': type,
    'coordinates': geometry.length == 1 ? geometry : [geometry]
   },
   'properties': value.tags
  };
 } else {
 return value;
 }
};
var tilePixels = new ol.proj.Projection({
/** ol.proj.Projection
 * Projection definition class. One of these is created 
 * for each projection supported in the application and 
 * stored in the ol.proj namespace. You can use these in 
 * applications, but this is not required, as API params 
 * and options use ol.proj.ProjectionLike which means the 
 * simple string code will suffice.
 * 投影定義クラス。これらの一つは、アプリケーションでサポートさ
 * れ、ol.proj名前空間に格納されている各投影に対して作成されま
 * す。アプリケーションでこれらを使用することができますが、API 
 * のパラメータとオプションは、単純な文字列コードで十分であるこ
 * とを意味する ol.proj.ProjectionLike を使用するので、これ
 * は必要ありません。(ol4 API)
 */
 code: 'TILE_PIXELS',
 /** code:
  * The SRS identifier code, e.g. EPSG:4326. Required.
  * SRS 識別子。例えば EPSG:4326。必須。(ol4 API)
  */
 units: 'tile-pixels'
 /** units:
  * Units. Required unless a proj4 projection is defined 
  * for code.
  * 単位。コードに proj4 projection が定義されていなければ必須。
  * (ol4 API)
  */
});
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. 
   * プリレンダリング(事前描画)を提供するレイヤソースのため
   * の、特定の解像度でのズームレベルによって編成されているグ
   * リッドのタイルイメージ。(ol4 API)
   */
   source: new ol.source.OSM()
   /** ol.source.OSM 
    * Layer source for the OpenStreetMap tile server.
    * OpenStreetMap タイルサーバのレイヤソース。(ol4 API)
    */
  })
 ],
 target: 'map',
 view: new ol.View({
  center: [0, 0],
  zoom: 2
 })
});
var url = 'data/geojson/countries.geojson';
fetch(url).then(function(response) {
/** GlobalFetch.fetch()(This is an experimental technology)
 * The fetch() method of the GlobalFetch interface starts 
 * the process of fetching a resource. This returns a 
 * promise that resolves to the Response object 
 * representing the response to your request.
 * GlobalFetch インタフェースの fetch() メソッドは、リソー
 * スを取得する処理を開始します。これは要求に対する応答を表す 
 * Response オブジェクトに解決のプロミス(promise)を返しま
 * す。
 *(MDN[https://developer.mozilla.org/ja/docs/Web/API/
 * FGlobalFetch/fetch])
 */
 return response.json();
/** Response(This is an experimental technology)
 * The Response interface of the Fetch API represents 
 * the response to a request.
 * Fetch API の Response インタフェースは、要求に対する応答
 * を表します。
 * (MDN[https://developer.mozilla.org/en-US/docs/Web/
 * API/Response])
 */
}).then(function(json) {
 var tileIndex = geojsonvt(json, {
 // build an initial index of tiles(geojson-vt)
  extent: 4096, // tile extent (both width and height)
  debug: 1     // logging level (0 to disable, 1 or 2)
 });
 var vectorSource = new ol.source.VectorTile({
 /** ol.source.VectorTile
  * Class for layer sources providing vector data divided 
  * into a tile grid, to be used with ol.layer.VectorTile. 
  * Although this source receives tiles with vector 
  * features from the server, it is not meant for feature 
  * editing. Features are optimized for rendering, their 
  * geometries are clipped at or near tile boundaries and 
  * simplified for a view resolution. See ol.source.Vector 
  * for vector sources that are suitable for feature 
  * editing.
  * ol.layer.VectorTile で使用するタイルとグリッドに分割され
  * たベクタデータを提供するレイヤソースのクラス。このソース
  * はベクタフィーチャを持つタイルをサーバから受信しますが、
  * フィーチャの編集を意味したものではありません。フィーチャ
  * はレンダリングのために最適化され、そのジオメトリはタイル
  * の境界線、または、その近くでクリップされ、ビュー解像度の
  * ために単純化されます。フィーチャ編集に適したベクトルソー
  * スについては、ol.source.Vector を参照してください。
  * (ol4 API)
  */
  format: new ol.format.GeoJSON(),
  /** format:
   * Feature format for tiles. Used and required by 
   * the default tileLoadFunction.
   * タイルのためのフィーチャフォーマット。デフォルトの 
   * tileLoadFunction によって使用され、必要とされます。
   * (ol4 API)
   */
  /** ol.format.GeoJSON 
   * Feature format for reading and writing data in the 
   * GeoJSON format.
   * GeoJSON フォーマットのデータを読み書きするためのフィー
   * チャフォーマット。(ol4 API)
   */
  tileGrid: ol.tilegrid.createXYZ(),
  /** tileGrid
   * Tile grid.(ol4 API)
   */
  /** ol.tilegrid.createXYZ(opt_options)
   * Creates a tile grid with a standard XYZ tiling 
   * scheme.
   * 標準のXYZタイルスキーマを持つタイルグリッドを作成します。
  * (ol4 API)
   */
  tilePixelRatio: 16,
  /** tilePixelRatio:
   * The pixel ratio used by the tile service. For example, 
   * if the tile service advertizes 256px by 256px tiles 
   * but actually sends 512px by 512px tiles (for 
   * retina/hidpi devices) then tilePixelRatio should be 
   * set to 2. Default is 1.
   * タイルサービスで使用されるピクセル比率。 例えば、タイル
   * サービスは 256×256 ピクセルのタイルを提供しますがが、実
   * 際には、(retina/hipdi デバイスの場合)512 ×512 ピクセ
   * ルのタイルを送信する場合、tilePixelRatio は2に設定する必
   * 要があります。デフォルトは1です。(ol4 API)
   */
  tileLoadFunction: function(tile) {
  /** tileLoadFunction:
   * Optional function to load a tile given a URL. 
   * URL を指定されたタイルをロードするためのオプション関数
   * (function)。
   * Could look like this:
   * 
   * function(tile, url) {
   *  tile.setLoader(function() {
   *   var data = // ... fetch data
   *   var format = tile.getFormat();
   *   tile.setFeatures(format.readFeatures(data));
   *   tile.setProjection(format.readProjection(data));
   *  };
   * });
   * (ol4 API)
   */
   var format = tile.getFormat();
   /** getFormat()
    * Get the format associated with this source.
    * このソースに関連付けられたフォーマットを取得します。
    * (ol4 API)
    */
   var tileCoord = tile.getTileCoord();
   /** getTileCoord()
    * Get the tile coordinate for this tile.
    * (ol4 API)
    */
   var data = tileIndex.getTile(tileCoord[0], tileCoord[1], -tileCoord[2] - 1);
   // request a particular tile(geojson-vt)
   var features = format.readFeatures(
    /** readFeatures(source, opt_options)
     * Read all features from a GeoJSON source. Works for 
     * all GeoJSON types. If the source includes only 
     * geometries, features will be created with those 
     * geometries.
     * GeoJSON ソースからすべてのフィーチャを読み込みます。 
     * すべて のGeoJSON タイプに対応しています。 ソースにジオ
     * メトリのみが含まれている場合、そのジオメトリでフィーチャ
     * が作成されます。(ol4 API)
     */
    JSON.stringify({
    /** JSON.stringify(value[, replacer[, space]])
     * JSON.stringify() メソッドは JavaScript の値を JSON 
     * 文字列に変換します。置き換え関数を指定して値を置き
     * 換えたり、置き換え配列を指定して指定されたプロパティ
     * のみを含むようにしたりできます。
     * (MDN[https://developer.mozilla.org/ja/docs/Web/
     * JavaScript/Reference/Global_Objects/JSON/stringify])
      */
     type: 'FeatureCollection',
     features: data ? data.features : []
    }, replacer));
    tile.setLoader(function() {
    /** setLoader(loader)
     * Set the feature loader for reading this tile's 
     * features.
     * このタイルのフィーチャを読み取るためのフィーチャローダを
     * 設定します。(ol4 API)
     */
     tile.setFeatures(features);
     /** setFeatures(features)
      * (ol4 API)
      */
     tile.setProjection(tilePixels);
     /** setProjection(projection)
      * Set the projection of the features that were added 
      * with #setFeatures.
      * #setFeaturesで追加されたフィーチャの投影を設定します。
      * (ol4 API)
      */
   });
  },
  url: 'data:' 
// arbitrary url, we don't use it in the tileLoadFunction
 });
 var vectorLayer = new ol.layer.VectorTile({
 /** ol.layer.VectorTile
  * Layer for vector tile data that is rendered client-side. 
  * Note that any property set in the options is set as a 
  * ol.Object property on the layer object.
  * 
  * クライアント側にレンダリングされるベクタタイルデータのレイ 
  * ヤ。オプションに設定されたプロパティは、レイヤオブジェクト
  * の ol.Object プロパティとして設定されます。
  * (ol4 API)
  */
  source: vectorSource
 });
 map.addLayer(vectorLayer);
 /** addLayer(layer)
  * Adds the given layer to the top of this map.
  * 与えられたレイヤをこのマップの一番上に追加します。(ol4 API)
  */
});
 
 

2016年12月31日土曜日

2 - ol3.20ex 165b - topolis integration 2

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

「2165-ol3ex.js」
var raster = 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.OSM()
 /** ol.source.OSM 
  * Layer source for the OpenStreetMap tile server.
  * OpenStreetMap タイルサーバのレイヤソース。(ol3 API)
  */
});
var nodes = new ol.source.Vector({wrapX: false});
/** ol.source.Vector
 * Provides a source of features for vector layers. 
 * Vector features provided by this source are suitable 
 * for editing. See ol.source.VectorTile for vector 
 * data that is optimized for rendering.
 * ベクタレイヤのフィーチャのソースを用意します。このソース
 * が提供するベクタフィーチャは、編集に適しています。レンダ
 * リングのために最適化されたベクタデータの 
 * ol.source.VectorTile を参照してください。(ol3 API)
 */
/** wrapX:
 * Wrap the world horizontally. Default is true. For 
 * vector editing across the -180° and 180° meridians 
 * to work properly, this should be set to false. The 
 * resulting geometry coordinates will then exceed the 
 * world bounds.
 * 水平方向に世界をラップします。デフォルトは true。-180°
 * と180°の子午線を横切って編集するベクトルが正しく動作す
 * るために、これは false に設定する必要があります。ジオメ
 * トリの座標の結果は、その後、世界の境界線を超えます。
 * (ol3 API[experimental])
 */
var nodesLayer = new ol.layer.Vector({
/** ol.layer.Vector
 * Vector data that is rendered client-side.
 * クライアント側で描画されるベクタデータ。(ol3 API)
 */
 source: nodes,
 style: function(f) {
  var style = new ol.style.Style({
  /** ol.style.Style 
   * Container for vector feature rendering styles. Any 
   * changes made to the style or its children through 
   * set*() methods will not take effect until the feature 
   * or layer that uses the style is re-rendered.
   * ベクタフィーチャがスタイルを描画するためのコンテナ。
   * スタイルや set*() メソッドを通じてその子に加えられた変
   * 更は、スタイルを使用するフィーチャまたはレイヤが再レン
   * ダリングされるまで有効になりません。
   * (ol3 API[experimental])
   */
   image: new ol.style.Circle({
   /** ol.style.Circle
    * Set circle style for vector features.
    * ベクタフィーチャの円のスタイルを設定。(ol3 API)
    */
    radius: 8,
    fill: new ol.style.Fill({color: 'rgba(255, 0, 0, 0.2)'}),
    /** ol.style.Fill 
     * Set fill style for vector features.
     * ベクタフィーチャの塗りつぶしスタイルを設定。
     * (ol3 API[experimental])
     */
    stroke: new ol.style.Stroke({color: 'red', width: 1})
    /** 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[experimental])
     */
    /** color
     * A color, gradient or pattern. See ol.color and 
     * ol.colorlike for possible formats. Default null; 
     * if null, the Canvas/renderer default black will 
     * be used.
     * 色、グラデーションまたはパターン。可能なフォーマットの対
     * する ol.color と oil.color を参照してください。デフォル
     * トは null; null の場合は、Canvas/renderer デフォルトの
     * 黒が使用されます。
     * (ol3 API[experimental])
     */
    }),
    text: new ol.style.Text({
    /** ol.style.Text
     * Set text style for vector features.
     * ベクタフィーチャの文字列のスタイルを設定します。
     * (ol3 API[experimental])
     */
     text: f.get('node').id.toString(),
     /** get(key)
      * Gets a value.(ol3 API)
      */
     /** Number.prototype.toString( [ radix ] )
      * 指定された Number オブジェクトを表す 文字列を返します。
      * radix: 数値を表すために使われる基数を指定する、2 から 
      * 36 までの整数。省略したときは 10。
      * MDN([https://developer.mozilla.org/ja/docs/Web/
      * JavaScript/Reference/Global_Objects/Number/toString])
      */
     fill: new ol.style.Fill({color: 'red'}),
     /** fill:
      * Fill style. If none is provided, we'll use a dark 
      * fill-style (#333).
      * (ol3 API[experimental])
      */
     stroke: new ol.style.Stroke({
      color: 'white',
      width: 3
     })
    })
   });
  return [style];
 }
});
var edges = new ol.source.Vector({wrapX: false});
var edgesLayer = new ol.layer.Vector({
 source: edges,
 style: function(f) {
  var style = new ol.style.Style({
   stroke: new ol.style.Stroke({
    color: 'blue',
    width: 1
   }),
   text: new ol.style.Text({
    text: f.get('edge').id.toString(),
    fill: new ol.style.Fill({color: 'blue'}),
    stroke: new ol.style.Stroke({
     color: 'white',
     width: 2
    })
   })
  });
  return [style];
 }
});
var faces = new ol.source.Vector({wrapX: false});
var facesLayer = new ol.layer.Vector({
 source: faces,
 style: function(f) {
  var style = new ol.style.Style({
   stroke: new ol.style.Stroke({
    color: 'black',
    width: 1
   }),
   fill: new ol.style.Fill({
    color: 'rgba(0, 255, 0, 0.2)'
   }),
   text: new ol.style.Text({
    font: 'bold 12px sans-serif',
    /** font:
     * Font style as CSS 'font' value, see: 
     * https://developer.mozilla.org/en-US/docs/Web/API/
     * CanvasRenderingContext2D/font. 
     * Default is '10px sans-serif'
     * (ol3 API[experimental])
     */
    text: f.get('face').id.toString(),
    fill: new ol.style.Fill({color: 'green'}),
    stroke: new ol.style.Stroke({
     color: 'white',
     width: 2
    })
   })
  });
  return [style];
 }
});
var map = new ol.Map({
 layers: [raster, facesLayer, edgesLayer, nodesLayer],
 target: 'map',
 view: new ol.View({
  center: [-11000000, 4600000],
  zoom: 16
 })
});
var topo = topolis.createTopology();
/** createTopology()
 * createTopology(name, srid, tolerance)
 * Create topology.
 * (JDoc:Module:topo[https://bjornharrtell.github.io/
 * topolis/0.1.0/apidocs/module-topo.html#.createTopology])
 */
topo.on('addnode', nodeToFeature);
/** on(topo, name, callback)
 * topo.js line 100
 * (JSDoc: Source topo.js[https://bjornharrtell.github.io/
 * topolis/0.1.0/apidocs/topo.js.html])
 */
topo.on('removenode', function(e) {
 removeElementFeature(nodes, e);
});
topo.on('addedge', edgeToFeature);
topo.on('modedge', function(e) {
 var feature = edges.getFeatureById(e.id);
 /**getFeatureById(id)
  * Get a feature by its identifier (the value returned by 
  * feature.getId()). Note that the index treats string 
  * and numeric identifiers as the same. So 
  * source.getFeatureById(2) will return a feature with id 
  * '2' or 2.
  * フィーチャ識別子(feature.getId()によって返される値)に
  * よってフィーチャを取得します。 インデックスは、文字列と数
  * 値の識別子を同じものとして扱うことに注意してください。 し
  * たがって、source.getFeatureById(2)は、IDが '2'(文字列)
  * または 2 (数値)のフィーチャを返します。(ol3 API)
  */
 feature.setGeometry(new ol.geom.LineString(e.coordinates));
 /** setGeometry()
  * Set the geometry for this feature. This will 
  * update the property with the current name 
  * returned by ol.Feature#getGeometryName. 
  * このフィーチャのジオメトリを設定します。これは、
  * ol.Feature#getGeometryName によって返された、現在の
  * 名前とともにプロパティを更新します。
  * (ol3 API)
  */
 /** ol.geom.LineString
  * Linestring geometry.(ol3 API)
  */
});
topo.on('removeedge', function(e) {
 removeElementFeature(edges, e);
});
topo.on('addface', faceToFeature);
topo.on('removeface', function(e) {
 removeElementFeature(faces, e);
});
function removeElementFeature(source, element) {
 var feature = source.getFeatureById(element.id);
 source.removeFeature(feature);
}
function nodeToFeature(node) {
 var feature = new ol.Feature({
 /** ol.Feature
  * A vector object for geographic features with a 
  * geometry and other attribute properties, similar 
  * to the features in vector file formats like 
  * GeoJSON.
  * GeoJSONのようなベクトルファイル形式のフィーチャに類
  * 似した、ジオメトリとその他の属性プロパティを持つ地物
  * フィーチャのためのベクトルオブジェクト。(ol3 API)
  */
  geometry: new ol.geom.Point(node.coordinate),
  /** ol.geom.Point
   * Point geometry.(ol3 API)
   */
  node: node
 });
 feature.setId(node.id);
 /** setId(id)
  * Set the feature id. The feature id is considered 
  * stable and may be used when requesting features or 
  * comparing identifiers returned from a remote source. 
  * The feature id can be used with the 
  * ol.source.Vector#getFeatureById method.
  * フィーチャ id を設定します。 フィーチャ id は安定していると
  * 考えられ、フィーチャを要求したり、リモートソースから返された
  * 識別子を比較するときに使用されます。 フィーチャ id は、
  * ol.source.Vector#getFeatureByIdメソッドで使用できます。
  * (ol3 API)
  */
 nodes.addFeature(feature);
 /** addFeature(feature)
  * Add a single feature to the source. If you want to 
  * add a batch of features at once, call 
  * source.addFeatures() instead.
  * 単一のフィーチャをソースに追加します。 一度にフィーチャの
  * バッチを追加する場合は、代わりにsource.addFeatures() を呼
  * び出します。(ol3 API)
  */
}
function edgeToFeature(edge) {
 var feature = new ol.Feature({
  geometry: new ol.geom.LineString(edge.coordinates),
  edge: edge
 });
 feature.setId(edge.id);
 edges.addFeature(feature);
}
function faceToFeature(face) {
 var coordinates = topo.getFaceGeometry(face);
 /** getFaceGeometry(topo, face)
  * Returns the polygon in the given topology with the  
  * specified face.
  * 指定された面の指定されたトポロジのポリゴンを返します。
  * (JDoc:Module:topo[https://bjornharrtell.github.io/
  * topolis/0.1.0/apidocs/module-face.html])
  */
 var feature = new ol.Feature({
  geometry: new ol.geom.Polygon(coordinates),
  /** ol.geom.Polygon
   * Polygon geometry.(ol3 API)
   */
  face: face
 });
 feature.setId(face.id);
 faces.addFeature(feature);
}
function createNode(topo, coord) {
 var node;
 var existingEdge = topo.getEdgeByPoint(coord, 5)[0];
 /** getEdgeByPoint
  * (JDoc:Module:topo[https://bjornharrtell.github.io/
  * topolis/0.1.0/apidocs/module-topo.html])
  */
 if (existingEdge) {
  node = topo.modEdgeSplit(existingEdge, coord);
  /** modEdgeSplit
   * (JDoc:Module:topo[https://bjornharrtell.github.io/
   * topolis/0.1.0/apidocs/module-topo.html])
   */
 } else {
  node = topo.addIsoNode(coord);
  /** addIsoNode(topo, coordinate)
   * Adds an isolated node to a face in a topology and 
   * returns the new node. If face is null, the node is 
   * still created.
   * 分離されたノードをトポロジの面に追加し、新しいノードを返し
   * ます。 face が null の場合、ノードはまだ作成されています。
   * (JDoc:Module:topo[https://bjornharrtell.github.io/
   * topolis/0.1.0/apidocs/module-node.html])
   */
 }
 return node;
}
function onDrawend(e) {
 var edgeGeom = e.feature.getGeometry().getCoordinates();
 /** getGeometry()
  * Get the feature's default geometry. A feature may 
  * have any number of named geometries. The "default" 
  * geometry (the one that is rendered by default) is 
  * set when calling ol.Feature#setGeometry.
  * フィーチャのデフォルトのジオメトリを取得します。フィーチャ
  * は、任意の数の指定のジオメトリのを有することができます。
  * 「デフォルト」のジオメトリ(デフォルトでレンダリングされ
  * るもの)が ol.Feature#setGeometry を呼び出すときに
  * 設定されています。(ol3 API)
  */
 /** getCoordinates()
  * Return the coordinates of the linestring.
  * ラインストリングの座標を返します。(ol3 API)
  */
 var startCoord = edgeGeom[0];
 var endCoord = edgeGeom[edgeGeom.length - 1];
 var start, end;
 try {
  start = topo.getNodeByPoint(startCoord);
  /** getNodeByPoint(topo, coordinate)
   * Find the node at a point location.
   * 点座標のノードを見つけます。
   * (JDoc:Module:topo[https://bjornharrtell.github.io/
   * topolis/0.1.0/apidocs/module-node.html])
   */
  end = topo.getNodeByPoint(endCoord);
  var edgesAtStart = topo.getEdgeByPoint(startCoord, 5);
  var edgesAtEnd = topo.getEdgeByPoint(endCoord, 5);
  var crossing = topo.getEdgesByLine(edgeGeom);
  /** getEdgesByLine
   * (JDoc:Module:topo[https://bjornharrtell.github.io/
   * topolis/0.1.0/apidocs/module-topo.html])
   */
  if (crossing.length === 1 && !start && !end && edgesAtStart.length === 0 && edgesAtEnd.length === 0) {
   topo.remEdgeNewFace(crossing[0]);
   /** remEdgeNewFace
    * (JDoc:Module:topo[https://bjornharrtell.github.io/
    * topolis/0.1.0/apidocs/module-topo.html])
    */
   start = crossing[0].start;
   if (start.face) {
    topo.removeIsoNode(start);
    /** removeIsoNode
     * (JDoc:Module:topo[https://bjornharrtell.github.io/
     * topolis/0.1.0/apidocs/module-topo.html])
     */
   }
   end = crossing[0].end;
   if (end.face) {
    topo.removeIsoNode(end);
   }
   return;
  }
  if (!start) {
   start = createNode(topo, startCoord);
   edgeGeom[0] = start.coordinate;
  }
  if (!end) {
   end = createNode(topo, endCoord);
   edgeGeom[edgeGeom.length - 1] = end.coordinate;
  }
  topo.addEdgeNewFaces(start, end, edgeGeom);
  /** addEdgeNewFaces(topo, start, end, coordinates)
   * Add a new edge and, if in doing so it splits a face, 
   * delete the original face and replace it with two new 
   * faces.
   * 新しいエッジを追加し、その際に面を分割する場合は元の面を削
   * 除し、2つの新しい面に置き換えます。
   * (JDoc:Module:topo[https://bjornharrtell.github.io/
   * topolis/0.1.0/apidocs/module-edge.html#.addEdgeNewFaces])
   */
 } catch (e) {
  toastr.warning(e.toString());
 }
}
var draw = new ol.interaction.Draw({
 /** ol.interaction.Draw 
  * Interaction that allows drawing geometries.
  * ジオメトリの描画を認めるインターラクション。(ol3 API)
  */
 type: 'LineString'
});
draw.on('drawend', onDrawend);
/** on(type, listener, opt_this)
 * Listen for a certain type of event.
 * あるタイプのイベントをリッスンします。(ol3 API)
 */
map.addInteraction(draw);
/** addInteraction(interaction)
 * Add the given interaction to the map.
 * マップへ指定されたインターラクションを追加します。
 * (ol3 API)
 */
var snap = new ol.interaction.Snap({
/** ol.interaction.Snap
 * Handles snapping of vector features while modifying 
 * or drawing them. The features can come from a 
 * ol.source.Vector or ol.Collection Any interaction 
 * object that allows the user to interact with the 
 * features using the mouse can benefit from the 
 * snapping, as long as it is added before.
 * The snap interaction modifies map browser event 
 * coordinate and pixel properties to force the snap to 
 * occur to any interaction that them.
 * 変更または描画の間、ベクタフィーチャのスナップを処理しま
 * す。フィーチャは、ol.source.Vector または ol.Collection 
 * 由来です。ユーザーがマウスを使用してフィーチャをインタラ
 * クションすることを可能にする任意のインタラクションオブジェ
 * クトは、それが前に追加されるように、スナップの恩恵を得る
 * ことができます。スナップインタラクションは、マップブラウ
 * ザイベントコーディネートと画素特性をそれらの任意のインタ
 * ラクションのために発生するスナップへ強制的に変更します。 
 * (ol3 API)
 */
 source: edges
});
map.addInteraction(snap);
map.addControl(new ol.control.MousePosition());
/** addControl(control)
 * Add the given control to the map.
 * 指定したコントロールをマップに追加します。
 * (ol3 API)
 */
/** ol.control.MousePosition 
 * A control to show the 2D coordinates of the mouse 
 * cursor. By default, these are in the view projection, 
 * but can be in any supported projection. By default 
 * the control is shown in the top right corner of the 
 * map, but this can be changed by using the css selector 
 * .ol-mouse-position.
 * マウスカーソルの2次元座標を表示すするためのコントロール。デ
 * フォルトでは、これらはビュー投影(の数値)ですが、サポートさ
 * れている任意の投影にすることができます。デフォルトでは、コン
 * トロールは、マップの右上に表示されますが、これは CSS セレク
 * タ .ol-mouse-position を使用して変更することができます。
 * (ol3 API)
 */