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

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)
 */
 
 

2 - ol4.3ex 172a - Vector Label Decluttering 1

「Vector Label Decluttering(vector-label-decluttering.html) 」を参考に地図を表示してみます。
説明に次のようにあります。

A custom renderer function is used instead of an ol.style.Text to label the countries of the world. Only texts that are not wider than their country's bounding box are considered and handed over to Labelgun for decluttering.

ol.style.Text の代わりにカスタムレンダラ関数を使用して、世界の国にラベルを付けます。 国のバウンディングボックスよりも幅の広くないテキストだけが考慮され、decluttering のために Labelgun に引き渡されます。


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



b 「ファイルを開く」ウィンドウで、「user」->「eclipse-workspace」->「ol4proj」-> 「v4.3.1」->「examples」->「vector-label-decluttering.html」をクリックして選択し、「OK」ボタンをクリッ クします。
同じように「vector-label-decluttering.js」を開きます。



(この状態でファイル名をキーボードで打つと検索欄が表示されて候補が絞り込めます。)

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



d 「ファイル」ウィンドウで「ol4proj」->「v4.3.1」->「examples」をクリックして選択し、「ファイル名」を「2172-ol4ex.html」と入力し、「完了」ボタンをクリックします。
(「ファイル」->「新規」->「その他」をクリックし、「ウィザードを選択」ダイアログで「Web」->「HTMLファイル」からテンプレートも作成できます。)







e 「vector-label-decluttering.html」の内容をコピーして「2172-ol4ex.html」に貼り付け、修正します。

f 同じように、新規に「2172-ol4ex.js」ファイルを作成し、「vector-label-decluttering.js」の内容をコピーして貼り付け、修正します。「vector-label-decluttering-require.js」も「2172-ol4ex-require.js」に貼り付けます。
(「ファイル」->「新規」->「JavaScript ソース・ファイル」をクリックし、「新規 JavaScript ファイル」ダイアログでテンプレートも作成できます。)






「2172-ol3ex.html」
<!DOCTYPE html>
<html lang="en-US">
 <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" type="text/css">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" type="text/css">
  <link rel="stylesheet" href="./resources/prism/prism.css" type="text/css">
  <link rel="stylesheet" href="../css/ol.css" type="text/css">
  <link rel="stylesheet" href="./resources/layout.css" type="text/css">

  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=Set""></script>
  <script src="https://unpkg.com/rbush@2.0.1/rbush.min.js"></script>
  <script src="https://unpkg.com/labelgun@0.1.1/lib/labelgun.min.js"></script>
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=fetch,requestAnimationFrame,Element.prototype.classList,URL"></script>
  <script src="./resources/zeroclipboard/ZeroClipboard.min.js"></script>
  <title>Vector Label Decluttering</title>
 </head>
 <body>
  <!-- 
  bootstrap-combined.min.css, ol.css, layout.css,
  CSSファイルで設定されたセレクタを使用。
  -->
  <header class="navbar" role="navigation">
   <div class="container">
    <div class="display-table pull-left" id="navbar-logo-container">
     <a class="navbar-brand" href="./"><img src="./resources/logo-70x70.png"> OpenLayers Examples</a>
    </div>
    <!-- menu items that get hidden below 768px width -->
    <nav class='collapse navbar-collapse navbar-responsive-collapse'>
     <ul class="nav navbar-nav pull-right">
      <li><a href="../doc">Docs</a></li>
      <li><a class="active" href="index.html">Examples</a></li>
      <li><a href="../apidoc">API</a></li>
      <li><a href="https://github.com/openlayers/openlayers">Code</a></li>
     </ul>
    </nav>
   </div>
  </header>
  <div class="container-fluid">
   <div id="latest-check" class="alert alert-warning alert-dismissible" role="alert" style="display:none">
    <button id="latest-dismiss" type="button" class="close" data-dismiss="alert" aria-label="Close">
     <span aria-hidden="true">&times;</span>
    </button>
     This example uses OpenLayers v<span>4.3.1</span>. 
     The <a id="latest-link" href="#" class="alert-link">latest</a>
     is v<span id="latest-version"></span>.
   </div>
   <div class="row-fluid">
    <div class="span12">
     <h4 id="title">Street Labels</h4>
     <div id="map" class="map"></div>
    </div>
   </div>
   <div class="row-fluid">
    <div class="span12">
     <p id="shortdesc">Render street names with a custom 
       render.</p>
     <div id="docs"><p>A custom <code>renderer 
      </code>function is used instead of an <code>
      ol.style.Text</code> to label the countries of the 
      world. Only texts that are not wider than their 
      country's bounding box are considered and handed over 
      to <a href="https://github.com/Geovation/labelgun">
      Labelgun</a> for decluttering.</p>
     </div>
     <div id="api-links">Related API documentation: 
      <ul class="inline">
       <li>
        <a href="../apidoc/ol.Map.html" title="API documentation for ol.Map">ol.Map</a>
       </li>,
       <li>
        <a href="../apidoc/ol.View.html" title="API documentation for ol.View">ol.View</a>
       </li>,
       <li>
        <a href="../apidoc/ol.extent.html" title="API documentation for ol.extent">ol.extent</a>
       </li>,
       <li>
        <a href="../apidoc/ol.format.GeoJSON.html" title="API documentation for ol.format.GeoJSON">ol.format.GeoJSON</a>
       </li>,
       <li>
        <a href="../apidoc/ol.layer.Vector.html" title="API documentation for ol.layer.Vector">ol.layer.Vector</a>
       </li>,
       <li>
        <a href="../apidoc/ol.source.Vector.html" title="API documentation for ol.source.Vector">ol.source.Vector</a>
       </li>,
       <li>
        <a href="../apidoc/ol.style.Fill.html" title="API documentation for ol.style.Fill">ol.style.Fill</a>
       </li>,
       <li>
        <a href="../apidoc/ol.style.Stroke.html" title="API documentation for ol.style.Stroke">ol.style.Stroke</a>
       </li>,
       <li>
        <a href="../apidoc/ol.style.Style.html" title="API documentation for ol.style.Style">ol.style.Style</a>
       </li>
      </ui>
     </div>
    </div>
   </div>
   <div class="row-fluid">
    <div id="source-controls">
     <a id="copy-button">
      <i class="fa fa-clipboard"></i> Copy
     </a>
     <a id="codepen-button">
      <i class="fa fa-codepen"></i> Edit
     </a>
    </div>
    <form method="POST" id="codepen-form" target="_blank" action="https://codepen.io/pen/define/">
     <textarea class="hidden" name="title">Vector Label Decluttering</textarea>
     <textarea class="hidden" name="description">Label decluttering with a custom renderer.</textarea>
     <textarea class="hidden" name="js">
// --- 省略 ---
&lt;/html&gt;</code></pre>
   </div>
  </div>
  <script src="./resources/common.js"></script>
  <script src="./resources/prism/prism.min.js"></script>
  <!-- 
  <script src="loader.js?id=vector-label-decluttering"></script>
  -->
  <!-- ファイル修正 -->
  <script src="loader.js?id=2172-ol4ex"></script>
 </body>
 <script>
  var packageUrl = 'https://raw.githubusercontent.com/openlayers/openlayers.github.io/build/package.json';
  fetch(packageUrl).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])
    */
   /** Body.json()(This is an experimental technology)
    * The json() method of the Body mixin takes a Response 
    * stream and reads it to completion. It returns a 
    * promise that resolves with an object literal 
    * containing the JSON data.
    * Body mixin の json() メソッドは、Response ストリームを
    * 受け取り、それを完了させるために読み込みます。これは、
    * JSON データを含むオブジェクトリテラルで解決する約束
    * (promisee)を返します。
    * (MDN[https://developer.mozilla.org/en-US/docs/Web/
    * API/Body/json])
    */
  }).then(function(json) {
   var latestVersion = json.version;
   document.getElementById('latest-version').innerHTML = latestVersion;
   var url = window.location.href;
   var branchSearch = url.match(/\/([^\/]*)\/examples\//);
   /** String.prototype.match()
    * 正規表現 に対する 文字列 のマッチングの際に、そのマッチ結
    * 果を得るために使われます。
    * (MDN[https://developer.mozilla.org/ja/docs/Web/
    * JavaScript/Reference/Global_Objects/String/match])
    */
   var cookieText = 'dismissed=-' + latestVersion + '-';
   var dismissed = document.cookie.indexOf(cookieText) != -1;
   /** String.prototype.indexOf()
    * 呼び出す String オブジェクト 中で、指定された値が最初に現
    * れたインデックスを返します。fromIndex から検索を始め、値が
    * 見つからない場合は -1 を返します。
    * (MDN[https://developer.mozilla.org/ja/docs/Web/
    * JavaScript/Reference/Global_Objects/String/indexOf])
    */
   if (!dismissed && /^v[0-9\.]*$/.test(branchSearch[1]) && '4.1.0' != latestVersion) {
    var link = url.replace(branchSearch[0], '/latest/examples/');
    /** Location.replace()
     * The Location.replace() method replaces the current 
     * resource with the one at the provided URL. The 
     * difference from the assign() method is that after 
     * using replace() the current page will not be saved 
     * in session History, meaning the user won't be able 
     * to use the back button to navigate to it.
     * 指定された URL に現在の文書を置き換えます。 assign() メ
     * ソッドとの違いは、replace() を用いた後、現在のページは、
     * セッションの履歴には保持されないことです。つまり、ユーザ
     * は、置き換え前のページに戻るために、戻るボタンを使うこと
     * ができません。
     * (MDN[https://developer.mozilla.org/en-US/docs/Web/
     * API/Location/replace])
     */
    fetch(link, {method: 'head'}).then(function(response) {
     var a = document.getElementById('latest-link');
     a.href = response.status == 200 ? link : '../../latest/examples/';
     /** Response.status(This is an experimental technology)
      * The status read-only property of the Response 
      * interface contains the status code of the response 
      * (e.g., 200 for a success).
      * Response インタフェースの status 読み取り専用プロパティ
      * は、応答のステータス・コード(例えば、成功のために 200)
      * を含みます。
     * (MDN[https://developer.mozilla.org/en-US/docs/Web/
     * API/Response/status])
      */
    });
    var latestCheck = document.getElementById('latest-check');
    latestCheck.style.display = '';
    document.getElementById('latest-dismiss').onclick = function() {
     latestCheck.style.display = 'none';
     document.cookie = cookieText;
    }
   }
  });
 </script>
</html>


COMMONJS は

COMMONJS
http://webpack.github.io/docs/commonjs.html

に、次のようにあります。

The CommonJS group defined a module format to solve JavaScript scope issues by making sure each module is executed in its own namespace.
This is achieved by forcing modules to explicitly export those variables it wants to expose to the “universe”, and also by defining those other modules required to properly work.
To achieve this CommonJS give you two tools:
the require() function, which allows to import a given module into the current scope.
the module object, which allows to export something from the current scope.

CommonJSグループは、それ自身の名前空間内で実行されている各モジュールを確認することによって、JavaScriptのスコープ問題を解決するためのモジュールフォーマットを定義しました。
これは、それが「universe(?)」に公開したい変数を明示的にエクスポートするモジュールを強制することによって、同じように、正常に動作するのに必要な他のモジュールを定義することによって、達成されます。
この CommonJS を達成するために2つのツールを与えます:
require()関数、指定したモジュールを現在のスコープにインポートすることができます。
モジュールオブジェクト、現在のスコープからエクスポートすることができます。


Prism は、

Prism
http://prismjs.com/

に、次のようにあります。

Prism is a lightweight, extensible syntax highlighter, built with modern web standards in mind. It’s a spin-off from Dabblet and is tested there daily by thousands.
Prismは、最新のWeb標準に構築されたことを考慮し軽量で拡張可能なシンタックスハイライトです。それは Dabblet からスピンオフで、何千人も日々そこで試験されています。


ZeroClipboard は

ZeroClipboard v2.x
http://zeroclipboard.org/

に、次のようにあります。

The ZeroClipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie and a JavaScript interface.
ZeroClipboard ライブラリは、見えない Adobe Flash ムービーとJavaScript のインターフェイスを使用してテキストをクリップボードにコピーする簡単な方法を提供します。

Debian 9 では動作しませんでした。ボタンを右クリックしたときに flash のコンテキストメニューが表示されると動作しています。