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

2019年8月26日月曜日

ol5.3ex 10 - XYZ

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

説明に次のようにあります。

The XYZ source is used for tile data that is accessed through URLs that include a zoom level and tile grid x/y coordinates.

XYZ source は、ズームデータとタイルグリッド x/y 座標を含む URL を通してアクセスされるタイルデータに対して使用されます。


この例では、「Thunderforest(https://www.thunderforest.com/)」のサービスを使います。使い方(API の取得、価格等)についてはホームページを参照してください。

次の内容で index.js を作成します。

user@deb9-vmw:~/new-project$ vim index.js
import 'ol/ol.css';
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import TileLayer from 'ol/layer/Tile.js';
import XYZ from 'ol/source/XYZ.js';
var map = new Map({
 target: 'map',
 /** 
  *  target [Map(options)]
  * The container for the map, either the element itself 
  * or the id of the element. If not specified at 
  * construction time, module:ol/Map~Map#setTarget must 
  * be called for the map to be rendered.
  * map のコンテナ、(HTML)エレメント自身、または、エレメント
  * の id。構築時に指定されていない場合、描画される map のた
  * めに module:ol/Map~Map#setTarget が呼び出されなけれ
  * ばなりません。
  * (ol5 API)
  */
 layers: [
 /** 
  * layers [Map(options)]
  * Layers. If this is not defined, a map with no layers 
  * will be rendered. Note that layers are rendered in 
  * the order supplied, so if you want, for example, a 
  * vector layer to appear on top of a tile layer, it 
  * must come after the tile layer.
  * レイヤ(layers)。これが定義されていない場合、レイヤのない
  * マップが描画されます。レイヤは提供された順番に描画されるの
  * で、例えば、ベクタレイヤがタイルレイヤの上に表示するよう望む
  * なら、タイルレイヤの後に来なければならないことに注意してくだ
  * さい。(ol5 API)
  */
  new TileLayer({
  /** 
   *  ol/layer/Tile~TileLayer 
   * For layer sources that provide pre-rendered, tiled 
   * images in grids that are organized by zoom levels for 
   * specific resolutions. 
   * プリレンダリング(事前描画)を提供するレイヤソースのため
   * の、特定の解像度でのズームレベルによって編成されているグ
   * リッドのタイルイメージ。(ol5 API)
   */
   source: new XYZ({
   /** 
    *  source [TileLayer(options)]
    * Source for this layer.
    * レイヤのソース。(ol5 API)
    */
   /** 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,  
    * module: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 で次のように使用できます。
    * (ol5 API)
    */
    url: 'https://{a-c}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png' +
    '?apikey=Your API key from http://www.thunderforest.com/docs/apikeys/ here'
    /** 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 オプションでそれぞれを個別に定義する代
     * わりに、使用することができます。
     *(ol5 API)
     */
   })
  })
 ],
 view: new View({
 /** 
  *  view [Map(options)]
  * The map's view. No layer sources will be fetched 
  * unless this is specified at construction time or 
  * through module:ol/Map~Map#setView.
  * map(マップ)の view(ビュー)。これが構築時に指定されて
  * いないか、module:ol/Map~Map#setView を介さなければ、
  * 取得されるレイヤソースはありません。
  * (ol5 API)
  */
  center: [-472202, 7530279],
  /**
   *  center[new View(opt_options)]
   * The initial center for the view. The coordinate system 
   * for the center is specified with the projection option. 
   * Layer sources will not be fetched if this is not set, 
   * but the center can be set later with #setCenter.
   * view(ビュー)の初期 center(中心)値。 center の座標系
   * は、projection(投影法)オプションで指定されます。これが
   * 設定されなければレイヤソースは取得されませんが、center は 
   * #setCenter で後で設定できます。
   * (ol5 API)
   */
  zoom: 12
  /**
   *  zoom[new View(opt_options)]
   * Only used if resolution is not defined. Zoom level  
   * usedto calculate the initial resolution for the view. 
   * The initial resolution is determined using the 
   * #constrainResolution method.
   * resolution(解像度)が定義されていない場合のみ使用されま
   * す。view の初期 resolution(解像度)を計算するために使用
   * される zoom(ズーム)レベル。初期 resolution は、
   * #constrainResolution メソッドを使用して決定されます。
   * (ol5 API)
   */
 })
});
次に index.html を作成します。
user@deb9-vmw:~/new-project$ vim index.html
<!doctype html>
<html>
 <head>
  <title>XYZ</title>
  <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
 </head>
 <body>
  <div id="map" class="map"></div>
  <script src="./index.js"></script>
 </body>
</html>
npm start を実行します。

user@deb9-vmw:~/new-project$ npm start

Webブラウザのアドレス欄に

http://localhost:1234

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

ol5-ex010-01.png

ol5.3ex 9 - Static Image

「Static Image (static-image.html) 」を参考に地図を表示してみます。

説明に次のようにあります。

This example uses a static image as a layer source. The map view is configured with a custom projection that translates image coordinates directly into map coordinates.

この例はレイヤソースとしてスタティックイメージ(静止画像)を使います。マップビューは画像座標を直接地図座標に変換するカスタム投影法で設定されます。

次の内容で index.js を作成します。
user@deb9-vmw:~/new-project$ vim index.js
import 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import {getCenter} from 'ol/extent';
import ImageLayer from 'ol/layer/Image';
import Projection from 'ol/proj/Projection';
import Static from 'ol/source/ImageStatic';
// Map views always need a projection.  Here we just want 
// to map imagecoordinates directly to map coordinates, 
// so we create a projection that uses the image extent 
// in pixels.
// マップビューは常に投影法が必要です。ここでは、単に、直接マッ
// プ座標へ画像座標をマップしたいので、ピクセル単位で画像の範囲
// を使用する投影法を作成します。
var extent = [0, 0, 1024, 968];
var projection = new Projection({
/** 
 *  ol/proj/Projection~Projection
 * Projection definition class. One of these is created 
 * for each projection supported in the application and 
 * stored in the module:ol/proj namespace. You can use 
 * these in applications, but this is not required, as 
 * API params and options use 
 * module:ol/proj~ProjectionLike which means the simple 
 * string code will suffice.
 * 投影法定義クラス。これらの一つは、アプリケーションでサポー
 * トされ、module:ol/proj 名前空間に格納されている各投影法に
 * 対して作成されます。アプリケーションでこれらを使用すること
 * ができますが、API のパラメータとオプションは、単純な文字列
 * コードで十分であることを意味する 
 * module:ol/proj~ProjectionLike を使用するので、これは必要
 * ありません。(ol5 API)
 */
 code: 'xkcd-image',
 /** code [Projection(options)]
  * The SRS identifier code, e.g. EPSG:4326.
  * SRS 識別コード。例えば、EPSG:4326。
  * (ol5 API) 
  */
 units: 'pixels',
 /** units [Projection(options)]
  * Units. Required unless a proj4 projection is defined 
  * for code.
  * 単位。proj4 プロジェクションがコードとして定義されていな
  * ければ必要です。
  * (ol5 API)
  */
 extent: extent
 /** extent [Projection(options)]
  * The validity extent for the SRS.
  * SRS の有効範囲。
  * (ol5 API)
  */
});
var map = new Map({
 layers: [
 /** 
  * layers [Map(options)]
  * Layers. If this is not defined, a map with no layers 
  * will be rendered. Note that layers are rendered in 
  * the order supplied, so if you want, for example, a 
  * vector layer to appear on top of a tile layer, it 
  * must come after the tile layer.
  * レイヤ(layers)。これが定義されていない場合、レイヤのない
  * マップが描画されます。レイヤは提供された順番に描画されるの
  * で、例えば、ベクタレイヤがタイルレイヤの上に表示するよう望む
  * なら、タイルレイヤの後に来なければならないことに注意してくだ
  * さい。(ol5 API)
  */
  new ImageLayer({
  /**
   *  ol/layer/Image~ImageLayer
   * Server-rendered images that are available for 
   * arbitrary extents and resolutions.
   * 任意の範囲と解像度に有効なサーバ描画イメージ。
   * (ol5 API)
   */
   source: new Static({
   /**
    *  source [ImageLayer(options)]
    * Source for this layer.
    * (ol5 API)
    */
   /** 
    *  ol/source/ImageStatic~Static 
    * A layer source for displaying a single, static image.
    * 単一で静的(投影データが付加されていない)画像の表示の
    * ためのレイヤソース。
    * (ol5 API)
    */
    attributions: '&amp:copy; <a href="http://xkcd.com/license.html">xkcd</a>',
    /** 
     *  attributions [Static(options)]
     * Attributions.
     * アトリビューション(属性)。
     * (ol5 API)
     */
    url: 'https://imgs.xkcd.com/comics/online_communities.png',
    /** 
     *  url [Static(options)]
     * Image URL.
     * 画像 URL。
     * (ol5 API)
     */
    projection: projection,
    /** 
     *  projection [Static(options)]
     * Projection.
     * 投影法。
     * (ol5 API)
     */
    imageExtent: extent
    /** 
     *  imageExtent [Static(options)]
     * Extent of the image in map coordinates. This is the 
     * [left, bottom, right, top] map coordinates of your 
     * image.
     * マップ座標中の画像の範囲。これは、画像の[左、下、右、上]
     * マップ座標。
     * (ol5 API)
     */
   })
  })
 ],
 target: 'map',
 /** 
  *  target [Map(options)]
  * The container for the map, either the element itself 
  * or the id of the element. If not specified at 
  * construction time, module:ol/Map~Map#setTarget must 
  * be called for the map to be rendered.
  * map のコンテナ、(HTML)エレメント自身、または、エレメン
  * トの id。構築時に指定されていない場合、描画される map 
  * のために module:ol/Map~Map#setTarget が呼び出されなけ
  * ればなりません。
  * (ol5 API)
  */
 view: new View({
 /** 
  *  view [Map(options)]
  * The map's view. No layer sources will be fetched 
  * unless this is specified at construction time or 
  * through module:ol/Map~Map#setView.
  * map(マップ)の view(ビュー)。これが構築時に指定されて
  * いないか、module:ol/Map~Map#setView を介さなければ、
  * 取得されるレイヤソースはありません。
  * (ol5 API)
  */
  projection: projection,
  /** 
   *  projection[new View(opt_options)]
   * The projection. The default is Spherical Mercator.
   * 投影法。デフォルト値は、Spherical Mercator(EPSG:3857)。
   * (ol5 API)
   */
  center: getCenter(extent),
  /**
   *  center[new View(opt_options)]
   * The initial center for the view. The coordinate system 
   * for the center is specified with the projection option. 
   * Layer sources will not be fetched if this is not set, 
   * but the center can be set later with #setCenter.
   * view(ビュー)の初期 center(中心)値。 center の座標系
   * は、projection(投影法)オプションで指定されます。これが
   * 設定されなければレイヤソースは取得されませんが、center は 
   * #setCenter で後で設定できます。
   * (ol5 API)
   */
  zoom: 2,
  /**
   *  zoom[new View(opt_options)]
   * Only used if resolution is not defined. Zoom level  
   * usedto calculate the initial resolution for the view. 
   * The initial resolution is determined using the 
   * #constrainResolution method.
   * resolution(解像度)が定義されていない場合のみ使用されま
   * す。view の初期 resolution(解像度)を計算するために使用
   * される zoom(ズーム)レベル。初期 resolution は、
   * #constrainResolution メソッドを使用して決定されます。
   * (ol5 API)
   */
  maxZoom: 8
  /**
   *  maxZoom[new View(opt_options)]
   * The maximum zoom level used to determine the 
   * resolution constraint. It is used together with 
   * minZoom (or maxResolution) and zoomFactor. Note that 
   * if minResolution is also provided, it is given 
   * precedence over maxZoom.
   * 解像度制約を決定するために使用される最大ズームレベル。
   * rminZoom(または、 maxResolution)、zoomFactor と共に
   * 使用されます。minResolution も提供される場合、maxZoom 
   * より優先されることに注意してください。
   * (ol5 API)
   */
 })
});
次に index.html を作成します。
user@deb9-vmw:~/new-project$ vim index.html
<!doctype html>
<html>
 <head>
  <title>Lazy Source</title>
  <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
 </head>
 <body>
  <div id="map" class="map"></div>
  <script src="./index.js"></script>
 </body>
</html>
npm start を実行します。

user@deb9-vmw:~/new-project$ npm start

Webブラウザのアドレス欄に

http://localhost:1234

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



ol5.3ex 8 - UTFGrid

「UTFGrid (lazy-source.html) 」を参考に地図を表示してみます。

説明に次のようにあります。

Point to a country to see its name and flag.

Tiles made with [TileMill](http://tilemill.com). Hosting on MapBox.com or with open-source [TileServer](https://github.com/klokantech/tileserver-php/).

国名と国旗を見るために国をポイント(マウスオーバ)します。

タイルは [TileMill](http://tilemill.com) で作成します。MapBox.com または、open-source [TileServer](https://github.com/klokantech/tileserver-php/) でホスティングします。

作成中...

ol5.3ex 7 - Lazy Source

「Lazy Source (lazy-source.html) 」を参考に地図を表示してみます。

説明に次のようにあります。

Typically, the source for a layer is provided to the layer constructor. If you need to set a layer source after construction, this can be done with the layer.setSource() method.

The layer in the map above is constructed with no source. Use the links below to set/unset the layer source. A layer is not rendered until its source is set.

一般的に、レイヤのソースはレイヤコンストラクタに提供されます。構築の後にレイヤソースを設定したい場合は、layer.setSource() メッソッドを使って実行できます。

上記マップのレイヤは、ソース無しで構築されます。レイヤソースを 設定/未設定するために下記のリンクを使います。レイヤは、ソースが設定されるまで、描画されません。


次の内容で index.js を作成します。
user@deb9-vmw:~/new-project$ vim index.js
import 'ol/ol.css';
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import TileLayer from 'ol/layer/Tile.js';
import OSM from 'ol/source/OSM.js';
var source = new OSM();
/** source(option)
 * Source for this layer. 
 * レイヤのソース。(ol5 API)
 */
var layer = new TileLayer();
/** ol/layer/Tile~TileLayer 
 * For layer sources that provide pre-rendered, tiled 
 * images in grids that are organized by zoom levels for 
 * specific resolutions. 
 * プリレンダリング(事前描画)を提供するレイヤソースのため
 * の、特定の解像度でのズームレベルによって編成されているグ
 * リッドのタイルイメージ。(ol5 API)
 */
var map = new Map({
 layers: [layer],
 /** layers [Map(options)]
  * Layers. If this is not defined, a map with no layers 
  * will be rendered. Note that layers are rendered in 
  * the order supplied, so if you want, for example, a 
  * vector layer to appear on top of a tile layer, it 
  * must come after the tile layer.
  * レイヤ(layers)。これが定義されていない場合、レイヤの
  * ないマップが描画されます。レイヤは提供された順番に描画
  * されるので、例えば、ベクタレイヤがタイルレイヤの上に表
  * 示するよう望むなら、タイルレイヤの後に来なければならな
  * いことに注意してください。(ol5 API)
  */
 target: 'map',
 /** target [Map(options)]
  * The container for the map, either the element itself 
  * or the id of the element. If not specified at 
  * construction time, module:ol/Map~Map#setTarget must 
  * be called for the map to be rendered.
  * map のコンテナ、(HTML)エレメント自身、または、エレメ
  * ントの id。構築時に指定されていない場合、描画される map 
  * のために module:ol/Map~Map#setTarget が呼び出されなけ
  * ればなりません。
  * (ol5 API)
  */
 view: new View({
 /** view [Map(options)]
  * The map's view. No layer sources will be fetched 
  * unless this is specified at construction time or 
  * through module:ol/Map~Map#setView.
  * map(マップ)の view(ビュー)。これが構築時に指定され
  * ていないか、module:ol/Map~Map#setView を介さなければ、
  * 取得されるレイヤソースはありません。
  * (ol5 API)
  */
  center: [0, 0],
  /** center[new View(opt_options)]
   * The initial center for the view. The coordinate 
   * system for the center is specified with the 
   * projection option. Layer sources will not be fetched 
   * if this is not set, but the center can be set later 
   * with #setCenter.
   * view(ビュー)の初期 center(中心)値。 center の座
   * 標系は、projection(投影法)オプションで指定されます。
   * これが設定されなければレイヤソースは取得されませんが、
   * center は #setCenter で後で設定できます。
   * (ol5 API)
   */
  zoom: 2
  /** zoom[new View(opt_options)]
   * Only used if resolution is not defined. Zoom level 
   * used to calculate the initial resolution for the 
   * view. The initial resolution is determined using the 
   * #constrainResolution method.
   * resolution(解像度)が定義されていない場合のみ使用さ
   * れます。view の初期 resolution(解像度)を計算するた
   * めに使用される zoom(ズーム)レベル。初期 resolution 
   * は、#constrainResolution メソッドを使用して決定され
   * ます。(ol5 API)
   */
 })
});
document.getElementById('set-source').onclick = function() {
/** Document.getElementById()
 * The Document method getElementById() returns an 
 * Element object representing the element whose id 
 * property matches the specified string. Since element 
 * IDs are required to be unique if specified, they're a 
 * useful way to get access to a specific element 
 * quickly.
 * If you need to get access to an element which doesn't 
 * have an ID, you can use querySelector() to find the 
 * element using any selector.
 * Document の getElementById() メソッドは、 id プロパティ
 * が指定された文字列に一致する要素を表す Element オブジェ
 * クトを返します。要素の ID は、指定されていれば固有であるこ
 * とが求められているため、特定の要素にすばやくアクセスする
 * には便利な方法です。
 * ID を持たない要素にアクセスする必要がある場合は、
 * querySelector() で何らかのセレクターを使用して要素を検
 * 索することができます。
 * (MDN[https://developer.mozilla.org/ja/docs/Web/API/
 * Document/getElementById])
 */
 layer.setSource(source);
 /** setSource(source)
  * Set the layer source.
  * レイヤソースを設定します。
  * (ol5 API)
  */
};
document.getElementById('unset-source').onclick = function() {
 layer.setSource(null);
};
次に index.html を作成します。
user@deb9-vmw:~/new-project$ vim index.html
<!doctype html>
<html>
 <head>
  <title>Lazy Source</title>
  <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
  <style>
   button.code {
    font-family: Monaco,Menlo,Consolas,"Courier New",monospace;
    font-size: 12px;
    padding: 5px;
    margin: 0 5px;
   }
  </style>
 </head>
 <body>
  <div id="map" class="map"></div>
  <button id="set-source" class="code">layer.setSource(source)</button>
  <button id="unset-source" class="code">layer.setSource(null)</button>
  <script src="./index.js"></script>
 </body>
</html>
npm start を実行します。

user@deb9-vmw:~/new-project$ npm start

Webブラウザのアドレス欄に

http://localhost:1234

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

layer.setSource(source)

layer.setSource(null)


ol5.3ex 6 - Zoomify

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

「About Zoomify, Inc.(http://www.zoomify.com/about.htm)」に次のようにあります。

Vision
Zoomify makes high-quality images zoom-and-pan for fast, interactive viewing on the web with just HTML, JPEGs, and JavaScript! Zoomify's products meet the high-resolution imaging needs of creative professionals, image-centric businesses, and digital device developers. Zoomify is revolutionizing digital imaging in commerce, education, entertainment, science, and security. Technologies include HTML5 viewing options, web-based annotation, and more.
Zoomify は、高画質イメージを、素早くズームとパンし、HTML と JPEGs、JavaScrip だけを使ってウェッブ上でインタラクティブビューにします。Zoomify の製品は、創造的なプロフェッショナルの高解像度画像のニーズや画像中心のビジネス、デジタルデバイス開発者にあっています。Zoomify は、商業や教育、エンターテイメント、科学、セキュリティのデジタル画像に革命を起こしています。技術は HTML5 ビューオプションやウェッブベースの注釈などを含んでいます。


説明に次のようにあります。

Zoomify is a format for deep-zooming into high resolution images. This example shows how to use the Zoomify source with a pixel projection. Internet Imaging Protocol (IIP) with JTL extension is also handled.

Zoomify は、高解像度画像にする深いズームのフォーマットです。この例はピクセル投影法で Zoomify ソースを使用する方法を示しています。JTL 拡張でインターネットイメージプロトコルも取り扱えます。

次の内容で index.js を作成します。
user@deb9-vmw:~/new-project$ vim index.js
import 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import Zoomify from 'ol/source/Zoomify.js';
var imgWidth = 9911;
var imgHeight = 6100;
var zoomifyUrl = 'http://vips.vtech.fr/cgi-bin/iipsrv.fcgi?zoomify=' +
 '/mnt/MD1/AD00/plan_CHU-4HD-01/FOND.TIF/';
var iipUrl = 'http://vips.vtech.fr/cgi-bin/iipsrv.fcgi?FIF=' + '/mnt/MD1/AD00/plan_CHU-4HD-01/FOND.TIF' + '&JTL={z},{tileIndex}';
var layer = new TileLayer({
/** ol/layer/Tile~TileLayer 
 * For layer sources that provide pre-rendered, tiled 
 * images in grids that are organized by zoom levels for 
 * specific resolutions. 
 * プリレンダリング(事前描画)を提供するレイヤソースのため
 * の、特定の解像度でのズームレベルによって編成されているグ
 * リッドのタイルイメージ。(ol5 API)
 */
 source: new Zoomify({
 /** source [TileLayer(option)]
  * Source for this layer. 
  * レイヤのソース。(ol5 API)
  */
 /** ol/source/Zoomify~Zoomify 
  * Layer source for tile data in Zoomify format (both 
  * Zoomify and Internet Imaging Protocol are supported).
  * Zoomify フォーマット(Zoomify と Internet Imaging 
  * Protocol の両方がサポートされる)タイルサデータのレイヤ
  * ソース。(ol5 API)
  */
  url: zoomifyUrl,
  /** url [Zoomify(option)]
   * URL template or base URL of the Zoomify service. A 
   * base URL is the fixed part of the URL, excluding 
   * the tile group, z, x, and y folder structure, e.g. 
   * http://my.zoomify.info/IMAGE.TIF/. A URL template 
   * must include {TileGroup}, {x}, {y}, and {z} 
   * placeholders, e.g. http://my.zoomify.info/
   * IMAGE.TIF/{TileGroup}/{z}-{x}-{y}.jpg. Internet 
   * Imaging Protocol (IIP) with JTL extension can be  
   * also used with {tileIndex} and {z} placeholders, 
   * e.g. http://my.zoomify.info?FIF=IMAGE.TIF&JTL={z},
   * {tileIndex}. A {?-?} template pattern, for example 
   * subdomain{a-f}.domain.com, may be used instead of 
   * defining each one separately in the urls option.
   * URL テンプレート、または、Zoomify サービスのベース URL。
   * ベース URL は、タイルグループ、x、z、y フォルダ構造を除
   * く、 URLの固定された部分、例えば、
   * http://my.zoomify.info/IMAGE.TIF/、です。URL テン
   * プレートは、{TileGroup}、{x}、{y}、{z} プレースホルダを
   * 含まなければなりません。例えば、http://my.zoomify.info/
   * IMAGE.TIF/{TileGroup}/{z}-{x}-{y}.jpg です。JTL 
   * 拡張子のついたInternet Imaging Protocol (IIP) は、
   * {tileIndex} と {z} プレースホルダをつけて使われます。
   * 例えば、http://my.zoomify.info?FIF=IMAGE.TIF&JTL=
   * {z},{tileIndex} です。{?-?} テンプレートパターン、例え
   * ば subdomain{a-f}.domain.com、は urls オプションで
   * それぞれを別に定義するかわりに使うことができます。
   * (ol5 API)
   */
  size: [imgWidth, imgHeight],
  /** size [Zoomify(option)]
   * Size of the image.
   * 画像のサイズ。
   * (ol5 API)
   */
  crossOrigin: 'anonymous'
  /** crossOrigin [Zoomify(option)]
   * The crossOrigin attribute for loaded images. Note 
   * that you must provide a crossOrigin value if you 
   * are using the WebGL renderer or if you want to 
   * access pixel data with the Canvas renderer. See 
   * https://developer.mozilla.org/en-US/docs/Web/HTML/
   * CORS_enabled_image for more detail.
   * ロードされたイメージの crossOrigin 属性。WebGL レンダ
   * ラを使用している場合、または、Canvas レンダラでピクセル
   * データにアクセスする場合、crossOrigin 値を提供なければ
   * ならないことに注意してください。詳細は 
   * https://developer.mozilla.org/en-US/docs/Web/HTML/
   * CORS_enabled_image を参照してください。
   * (ol5 API)
   */
 })
});
var extent = [0, -imgHeight, imgWidth, 0];
var map = new Map({
 layers: [layer],
 /** layers [Map(options)]
  * Layers. If this is not defined, a map with no layers 
  * will be rendered. Note that layers are rendered in 
  * the order supplied, so if you want, for example, a 
  * vector layer to appear on top of a tile layer, it 
  * must come after the tile layer.
  * レイヤ(layers)。これが定義されていない場合、レイヤのない
  * マップが描画されます。レイヤは提供された順番に描画されるの
  * で、例えば、ベクタレイヤがタイルレイヤの上に表示するよう望
  * むなら、タイルレイヤの後に来なければならないことに注意して
  * ください。(ol5 API)
  */
 target: 'map',
 /** target [Map(options)]
  * The container for the map, either the element itself 
  * or the id of the element. If not specified at 
  * construction time, module:ol/Map~Map#setTarget must 
  * be called for the map to be rendered.
  * map のコンテナ、(HTML)エレメント自身、または、エレメント
  * の id。構築時に指定されていない場合、描画される map のた
  * めに module:ol/Map~Map#setTarget が呼び出されなけれ
  * ばなりません。
  * (ol5 API)
  */
 view: new View({
 /** view [Map(options)]
  * The map's view. No layer sources will be fetched unless 
  * this is specified at construction time or through 
  * module:ol/Map~Map#setView.
  * map(マップ)の view(ビュー)。これが構築時に指定されて
  * いないか、module:ol/Map~Map#setView を介さなければ、取
  * 得されるレイヤソースはありません。
  * (ol5 API)
  */
  // adjust zoom levels to those provided by the source
  // ソースによって提供されたそれらのためにズームレベルを調整する
  resolutions: layer.getSource().getTileGrid().getResolutions(),
  /** resolutions [View(options)]
   * Resolutions to determine the resolution constraint. 
   * If set the maxResolution, minResolution, minZoom, 
   * maxZoom, and zoomFactor options are ignored.
   * resolution 制約を決定するための resolutions。
   * maxResolution が設定されている場合、inResolution, 
   * minZoom, maxZoom, and zoomFactor は無視されます。
   * (ol5 API)
   */
  /** getSource()
   * Return the associated tilesource of the the layer.
   * タイルレイヤの関連するタイルソースを返します。
   * (ol5 API)
   */
  /** getTileGrid()
   * Return the tile grid of the tile source.
   * タイルソースのタイルグリッドを返します。
   * (ol5 API)
   */
  /** getResolutions()
   * Get the list of resolutions for the tile grid.
   * タイルグリッドの解像度のリストを取得します。
   * (ol5 API)
   */
  // constrain the center: center cannot be set outside 
  // this extent
  // 中心を制約する: 中心をこの範囲の外に設定できません
  extent: extent
  /** extent [View(options)]
   * The extent that constrains the center, in other words, 
   * center cannot be set outside this extent.
   * 中心を制約する範囲、言い換えれば、中心をこの範囲の外に設
   * 定できません。
   * (ol5 API)
   */
 })
});
map.getView().fit(extent);
/** getView()
 * Get the view associated with this map. A view manages 
 * properties such as center and resolution.
 * このマップと関連するビューを取得します。ビューは、中心や解
 * 像度のような属性を管理します。
 * (ol5 API)
 */
/** fit(geometryOrExtent, opt_options)
 * Fit the given geometry or extent based on the given 
 * map size and border. The size is pixel dimensions of 
 * the box to fit the extent into. In most cases you 
 * will want to use the map size, that is map.getSize(). 
 * Takes care of the map angle.
 * 与えられたジオメトリと与えられたマップサイズと境界をもとと
 * した範囲を合わせます。サイズは、範囲内に合わせるために、ボッ
 * クスの単位はピクセルです。ほとんどの場合、マップサイズを使
 * いますが、それは map.getSize() です。マップアングルに気
 * をつけてください。
 * (ol5 API)
 */
var control = document.getElementById('zoomifyProtocol');
/** Document.getElementById()
 * The Document method getElementById() returns an 
 * Element object representing the element whose id 
 * property matches the specified string. Since element 
 * IDs are required to be unique if specified, they're a 
 * useful way to get access to a specific element 
 * quickly.
 * If you need to get access to an element which doesn't 
 * have an ID, you can use querySelector() to find the 
 * element using any selector.
 * Document の getElementById() メソッドは、 id プロパティ
 * が指定された文字列に一致する要素を表す Element オブジェ
 * クトを返します。要素の ID は、指定されていれば固有であるこ
 * とが求められているため、特定の要素にすばやくアクセスする
 * には便利な方法です。
 * ID を持たない要素にアクセスする必要がある場合は、
 * querySelector() で何らかのセレクターを使用して要素を検
 * 索することができます。
 * (MDN[https://developer.mozilla.org/ja/docs/Web/API/
 * Document/getElementById])
 */
control.addEventListener('change', function(event) {
/** EventTarget.addEventListener()
 * The EventTarget method addEventListener() sets up a 
 * function that will be called whenever the specified 
 * event is delivered to the target. Common targets are
 * Element, Document, and Window, but the target may be 
 * any object that supports events (such as 
 * XMLHttpRequest).
 * addEventListener() works by adding a function or an 
 * object that implements EventListener to the list of 
 * event listeners for the specified event type on the 
 * EventTarget on which it's called.
 * EventTarget.addEventListener() メソッドは、指定された
 * イベントがターゲットに渡されるときにはいつでも呼び出される
 * ファンクションを設定します。一般的なターゲットは、Element、
 * Document、Window ですが、ターゲットは(XMLHttpRequest 
 * のような)イベントをサポートするあらゆるオブジェクトです。
 * addEventListener() は、呼び出される EventTarget の指
 * 定されたイベントタイプためのイベントリスナのリストに 
 * EventListener を実装するファンクション、または、オブジェ
 * クトを追加することによって動作します。
 *(MDN[https://developer.mozilla.org/en-US/docs/Web/API/
 * EventTarget.addEventListener])
 */
 var value = event.currentTarget.value;
 /** Event.currentTarget
  * The currentTarget read-only property of the Event 
  * interface identifies the current target for the 
  * event, as the event traverses the DOM. It always 
  * refers to the element to which the event handler has 
  * been attached, as opposed to Event.target, which 
  * identifies the element on which the event occurred 
  * and which may be its direct descendent. 
  * Event インターフェイスの currentTarget 読み取り専用プ
  * ロパティは、イベントの現在のターゲットを識別し、そのため
  * イベントは DOM を横断します。Event.target とは対象的に、
  * イベントハンドラが装着されている要素を常に参照します。
  * イベントが発生した要素を識別し、その直接の子孫です。
  *(MDN[https://developer.mozilla.org/en-US/docs/Web/API/
  * Event/currentTarget])
  */
 if (value === 'iip') {
  layer.setSource(new Zoomify({
  /** setSource(source)
   * Set the layer source.
   * レイヤソースを設定します。
   * (ol5 API)
   */
   url: iipUrl,
   size: [imgWidth, imgHeight],
   crossOrigin: 'anonymous'
  }));
 } else if (value === 'zoomify') {
  layer.setSource(new Zoomify({
   url: zoomifyUrl,
   size: [imgWidth, imgHeight],
   crossOrigin: 'anonymous'
  }));
 }
});
次に index.html を作成します。
user@deb9-vmw:~/new-project$ vim index.html
<!doctype html>
<html>
 <head>
  <meta charset="utf-8">
  <title>Zoomify</title>
  <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
 </head>
 <body>
  <div id="map"></div>
  <div class="controls">
   <select id="zoomifyProtocol">
    <option value="zoomify">Zoomify</option>
    <option value="iip">IIP</option>
   </select>
  </div>
  <script src="./index.js"></script>
 <body>
</html>
npm start を実行します。

user@deb9-vmw:~/new-project$ npm start

Webブラウザのアドレス欄に

http://localhost:1234

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



ol5.3ex 5 - Stamen Tiles

「Stamen Tiles (stamen.html) 」を参考に地図を表示してみます。「maps.stamen.com(http://maps.stamen.com/」に次のようにあります。

For over a decade, Stamen has been exploring cartography with our clients and in research. These maps are presented here for your enjoyment and use wherever you display OpenStreetMap data.

十年以上、Stamen はクライアントと共に研究の中で地図製作を探究しています。これらの地図は、OpenStreetMap データを表示するところはどこでも、楽しみ使うためにここで提供されます。


説明に次のようにあります。

Two layers are composed: the watercolor base layer with the terrain labels.

2つのレイヤ- terrain labels(地域ラベル)付きの watercolor(水彩画法)ベースレイヤ-で構成されています。


次の内容で index.js を作成します。
user@deb9-vmw:~/new-project$ vim index.js
import 'ol/ol.css';
import 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import {fromLonLat} from 'ol/proj.js';
import Stamen from 'ol/source/Stamen.js';
var map = new Map({
 layers: [ 
 /** layers [Map(options)]
  * Layers. If this is not defined, a map with no layers 
  * will be rendered. Note that layers are rendered in the 
  * order supplied, so if you want, for example, a vector 
  * layer to appear on top of a tile layer, it must come 
  * after the tile layer.
  * レイヤ(layers)。これが定義されていない場合、レイヤのない
  * マップが描画されます。レイヤは提供された順番に描画されるの
  * で、例えば、ベクタレイヤがタイルレイヤの上に表示するよう望
  * むなら、タイルレイヤの後に来なければならないことに注意して
  * ください。(ol5 API)
  */
  new TileLayer({
  /** ol/layer/Tile~TileLayer 
   * For layer sources that provide pre-rendered, tiled 
   * images in grids that are organized by zoom levels for 
   * specific resolutions. 
   * プリレンダリング(事前描画)を提供するレイヤソースのため
   * の、特定の解像度でのズームレベルによって編成されているグ
   * リッドのタイルイメージ。(ol5 API)
   */
   source: new Stamen({
   /** source [TileLayer(option)]
    * Source for this layer. 
    * レイヤのソース。(ol5 API)
    */
   /** ol/source/Stamen~Stamen 
    * Layer source for the Stamen tile server. 
    * Stamen タイルサーバのレイヤのソース。(ol5 API)
    */
    layer: 'watercolor'
    /** layer [Stamen(option)]
     * Layer name. 
     * レイヤ名。(ol5 API)
     */
   })
  }),
  new TileLayer({
   source: new Stamen({
    layer: 'terrain-labels'
   })
  })
 ],
 target: 'map',
 /** target [Map(options)]
  * The container for the map, either the element 
  * itself or the id of the element. If not specified 
  * at construction time, module:ol/Map~Map#setTarget 
  * must be called for the map to be rendered.
  * map のコンテナ、(HTML)エレメント自身、または、エレメ
  * ントの id。構築時に指定されていない場合、描画される map 
  * のために module:ol/Map~Map#setTarget が呼び出されなけ
  * ればなりません。
  * (ol5 API)
  */
 view: new View({
 /** view [Map(options)]
  * The map's view. No layer sources will be fetched 
  * unless this is specified at construction time or 
  * through module:ol/Map~Map#setView.
  * map(マップ)の view(ビュー)。これが構築時に指定さ
  * れていないか、module:ol/Map~Map#setView を介さなけ
  * れば、取得されるレイヤソースはありません。
  * (ol5 API)
  */
  center: fromLonLat([-122.416667, 37.783333]),
  /** center [View(opt_options)]
   * The initial center for the view. The coordinate system 
   * for the center is specified with the projection option. 
   * Layer sources will not be fetched if this is not set, 
   * but the center can be set later with #setCenter.
   * view(ビュー)の初期 center(中心)値。 center の座標系
   * は、projection(投影法)オプションで指定されます。これが
   * 設定されなければレイヤソースは取得されませんが、center 
   * は #setCenter で後で設定できます。
   * (ol5 API)
   */
  zoom: 12
  /** zoom [View(opt_options)]
   * Only used if resolution is not defined. Zoom level used 
   * to calculate the initial resolution for the view. The 
   * initial resolution is determined using the 
   * #constrainResolution method.
   * resolution(解像度)が定義されていない場合のみ使用されま
   * す。view の初期 resolution(解像度)を計算するために使用
   * される zoom(ズーム)レベル。初期 resolution は、
   * #constrainResolution メソッドを使用して決定されます。
   * (ol5 API)
   */
 })
});
次に index.html を作成します。
user@deb9-vmw:~/new-project$ vim index.html
<!doctype html>
<html>
 <head>
  <meta charset="utf-8">
  <title>Stamen Tiles</title>
  <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
 </head>
 <body>
  <div id="map"></div>
  <script src="./index.js"></script>
 <body>
</html>
npm start を実行します。

user@deb9-vmw:~/new-project$ npm start

Webブラウザのアドレス欄に

http://localhost:1234

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



ol5.3ex 4 - CartoDB source example

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

「Github - CartoDB/cartodb: Location Intelligence & Data Visualization tool(https://github.com/CartoDB/cartodb」の「What is CARTO?」に次のようにあります。

What is CARTO?
CARTO is an open, powerful, and intuitive platform for discovering and predicting the key insights underlying the location data in our world.

Empower organizations to optimize operational performance, strategic investments, and everyday decisions with CARTO Engine—our embeddable platform for web and mobile apps—and the new CARTO Builder, a drag and drop analysis tool.

It was built to make it easier for people to tell their stories by providing them with flexible and intuitive ways to create maps and design geospatial applications. CARTO can be installed on your own server and we also offer a hosted service at carto.com.

なぜ CARTO?
CARTO は、私達の世界で地理データの根底にある重要な洞察を発見し予測するためのオープンで強力、そして直感的プラットフォームです。組織に、操作性と戦略的な投資、CARTO Engineーウエッブとモバイルアプリ用の組み込み可能なプラットフォームーと新しい CARTO Builder、ドラッグ・アンド・ドロップアナリストツール、を最大限に活用する権限を与えます。

マップを作成し、地理アプリケーションを設計するための柔軟で直感的な方法でそれらを提供することによって、人々がストーリーを語りやすくするために構築されました。CARTO はあなたのサーバにインストールができ、私達は carto.com のホストサービスも提供します。

「CARTO日本語サービス(https://chizudb.jp/)」も参考にしてください。


説明に次のようにあります。

A simple example with an anonymous cartodb map

匿名 cartodb マップの単純な例

次の内容で index.js を作成します。
user@deb9-vmw:~/new-project$ vim index.js
import 'ol/ol.css';
import 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import {CartoDB, OSM} from 'ol/source/';
var mapConfig = {
 'layers': [{
 /** layers [object] required
  * Array of object.
  * オブジェクトの配列。
  * (CartoDB Maps API[https://carto.com/developers/
  * maps-api/reference/#operation/instantiateAnonymousMap])
  */
  'type': 'cartodb',
  /** type [string(Layer type)] required
   * A string value that defines the layer type:
   * レイヤタイプを定義する文字列値:
   * cartodb - an alias for mapnik (for backward
   * compatibility)
   * 'mapnik' のエイリアス(上位互換)
   * (CartoDB Maps API[https://carto.com/developers/
   * maps-api/reference/#operation/instantiateAnonymousMap])
   */
  'options': {
  /** options [object] required
   * Sets different options for each layer type.
   * 各レイヤタイプに違うオプションを設定。
   * (CartoDB Maps API[https://carto.com/developers/
   * maps-api/reference/#operation/instantiateAnonymousMap])
   */
   'cartocss_version': '2.1.1',
   /** cartocss_version [string (cartocss version)] required
    * A string value, specifying the CartoCSS style version
    * of the CartoCSS attribute.
    * Note: The CartoCSS version is specific to the layer
    * type.
    * 文字列値、CartoCSS 属性の CartoCSS スタイルバージョンを
    * 指定。
    * 注意:CartoCSS バージョンはレイヤタイプ対して特定のもの
    * です。
    * (CartoDB Maps API[https://carto.com/developers/
    * maps-api/reference/#operation/instantiateAnonymousMap])
    */
   'cartocss': '#layer { polygon-fill: #F00; }',
   /** cartocss [string (cartocss)] required
    * Specifies the CartoCSS style to render the tiles.
    * Note: The CartoCSS specification is dependent on the
    * layer type. For details, see mapnik-reference.json.
    * タイルを描画するために CartoCSS スタイルバージョンを指定。
    * 注意:CartoCSS 仕様はレイヤタイプによります。詳細は
    * mapnik-reference.json を参照してください。
    * (CartoDB Maps API[https://carto.com/developers/
    * maps-api/reference/#operation/instantiateAnonymousMap])
    */
   'sql': 'select * from european_countries_e where area > 0'
   /** sql [string] required
    * The SQL request to the user database that will fetch
    * the rendered data.
    * Tip: The SQL request should include the following
    * Mapnik layer configurations:
    * ● geom_column
    * ● interactivity
    * ● attributes
    * Note: The SQL request may contain substitutions
    * tokens, such as !bbox!, !pixel_width! and 
    * !pixel_height!. It is suggested to define the
    * layergroup minzoom and extent variables to prevent
    * errors.
    * 描画されるデートを取得するユーザデータベースのためのSQL
    * リクエスト。
    * コツ:SQL リクエストは、次の Mapnik レイヤ設定を含めます:
    * ● geom_column
    * ● interactivity
    * ● attributes
    * 注意:SQL リクエストは!bbox!、!pixel_width!、
    * !pixel_height!のような、置換トークンを含みます。エラー
    * を防ぐために layergroup minzoom と extent variables を
    * 定義します。
    * (CartoDB Maps API[https://carto.com/developers/
    * maps-api/reference/#operation/
    * instantiateAnonymousMap])
    */
  }
 }]
};
var cartoDBSource = new CartoDB({
/** ol/source/CartoDB~CartoDB
 * Layer source for the CartoDB tiles.
 * CartoDB タイルのレイヤソース。
 * (ol5 API)
 */
 account: 'documentation',
 /** account
  * If using named maps, this will be the name of the 
  * template to load.
  * 名付けられた(named)マップを使用する場合、これはロードする
  * ためのテンプレートの名前です。
  * (ol5 API)
  */
 config: mapConfig
 /** config
  * If using anonymous maps, the CartoDB config to use. 
  * See http://docs.cartodb.com/cartodb-platform/
  * maps-api/anonymous-maps/ for more detail. If using 
  * named maps, a key-value lookup with the template 
  * parameters. See http://docs.cartodb.com/
  * cartodb-platform/maps-api/named-maps/ for more 
  * detail.
  * 匿名(anonymous)マップを使用している場合、使用するための 
  * CartoDB 設定。詳細については http://docs.cartodb.com/
  * cartodb-platform/maps-api/anonymous-maps/を参照して
  * ください。名付けられた(named)マップを使用している場合、テ
  * ンプレートパラメータを持つ key-value 検索。詳細については 
  * http://docs.cartodb.com/cartodb-platform/maps-api/
  * named-maps/を参照してください。
  * (ol5 API)
  */});
var map = new Map({
 layers: [
  new TileLayer({
  /** ol/layer/Tile~TileLayer 
   * For layer sources that provide pre-rendered, tiled 
   * images in grids that are organized by zoom levels for 
   * specific resolutions. 
   * プリレンダリング(事前描画)を提供するレイヤソースのため
   * の、特定の解像度でのズームレベルによって編成されているグ
   * リッドのタイルイメージ。(ol5 API)
   */
   source: new OSM()
   /** source(option)
    * Source for this layer. 
    * レイヤのソース。(ol5 API)
    */
  }),
  new TileLayer({
   source: cartoDBSource
  })
 ],
 target: 'map',
 /** target[new Map(options)]
  * The container for the map, either the element 
  * itself or the id of the element. If not specified 
  * at construction time, module:ol/Map~Map#setTarget 
  * must be called for the map to be rendered.
  * map のコンテナ、(HTML)エレメント自身、または、エレメント
  * の id。構築時に指定されていない場合、描画される map のた
  * めに module:ol/Map~Map#setTarget が呼び出されなけれ
  * ばなりません。
  * (ol5 API)
  */
 view: new View({
 /** view[new Map(options)]
  * The map's view. No layer sources will be fetched 
  * unless this is specified at construction time or 
  * through module:ol/Map~Map#setView.
  * map(マップ)の view(ビュー)。これが構築時に指定されて
  * いないか、module:ol/Map~Map#setView を介さなければ、
  * 取得されるレイヤソースはありません。
  * (ol5 API)
  */
  center: [0, 0],
  /** center[new View(opt_options)]
   * The initial center for the view. The coordinate system 
   * for the center is specified with the projection option. 
   * Layer sources will not be fetched if this is not set, 
   * but the center can be set later with #setCenter.
   * view(ビュー)の初期 center(中心)値。 center の座標系
   * は、projection(投影法)オプションで指定されます。これが
   * 設定されなければレイヤソースは取得されませんが、center は 
   * #setCenter で後で設定できます。
   * (ol5 API)
   */
  zoom: 2
  /** zoom[new View(opt_options)]
   * Only used if resolution is not defined. Zoom level used 
   * to calculate the initial resolution for the view. The 
   * initial resolution is determined using the 
   * #constrainResolution method.
   * resolution(解像度)が定義されていない場合のみ使用されま
   * す。view の初期 resolution(解像度)を計算するために使用
   * される zoom(ズーム)レベル。初期 resolution は、
   * #constrainResolution メソッドを使用して決定されます。
   * (ol5 API)
   */
 })
});
function setArea(n) {
 mapConfig.layers[0].options.sql =
  'select * from european_countries_e where area > ' + n;
 cartoDBSource.setConfig(mapConfig);
 /** setConfig(config)
  * Sets the CartoDB config
  * CartoDB config(設定)を設定。
  */
}
document.getElementById('country-area').addEventListener('change', function() {
/** Document.getElementById()
 * The Document method getElementById() returns an 
 * Element object representing the element whose id 
 * property matches the specified string. Since element 
 * IDs are required to be unique if specified, they're a 
 * useful way to get access to a specific element 
 * quickly.
 * If you need to get access to an element which doesn't 
 * have an ID, you can use querySelector() to find the 
 * element using any selector.
 * Document の getElementById() メソッドは、 id プロパティ
 * が指定された文字列に一致する要素を表す Element オブジェ
 * クトを返します。要素の ID は指定されていれば固有であるこ
 * とが求められているため、特定の要素にすばやくアクセスする
 * には便利な方法です。
 * ID を持たない要素にアクセスする必要が ある場合は、
 * querySelector() で何らかのセレクターを使用して要素を検
 * 索することができます。
 * (MDN[https://developer.mozilla.org/ja/docs/Web/API/
 * Document/getElementById])
 */
/** EventTarget.addEventListener
 * The EventTarget method addEventListener() sets up a 
 * function that will be called whenever the specified 
 * event is delivered to the target. Common targets are
 * Element, Document, and Window, but the target may be 
 * any object that supports events (such as 
 * XMLHttpRequest).
 * addEventListener() works by adding a function or an 
 * object that implements EventListener to the list of 
 * event listeners for the specified event type on the 
 * EventTarget on which it's called.
 * EventTarget.addEventListener() メソッドは、指定された
 * イベントがターゲットに渡されるときにはいつでも呼び出される
 * ファンクションを設定します。一般的なターゲットは、Element、
 * Document、Window ですが、ターゲットは(XMLHttpRequest 
 * のような)イベントをサポートするあらゆるオブジェクトです。
 * addEventListener() は、呼び出される EventTarget の指
 * 定されたイベントタイプためのイベントリスナのリストに 
 * EventListener を実装するファンクション、または、オブジェ
 * クトを追加することによって動作します。
 *(MDN[https://developer.mozilla.org/en-US/docs/Web/API/
 * EventTarget.addEventListener])
 */
 setArea(this.value);
});

次に index.html を作成します。
user@deb9-vmw:~/new-project$ vim index.html
<!doctype html>
<html>
 <head>
  <meta charset="utf-8">
  <title>CartoDB source example</title>

  <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
 </head>
 <body>
  <div id="map"></div>
  <div>
  <form">
   <label>
    Show countries larger than
     <select id="country-area">
      <option value="0" default>0 km&sup2;</option>
      <option value="5000">5000 km&#178;</option>
      <option value="10000">10000 km&#xB2;</option>
      <option value="50000">5000 &#13218;</option>
      <option value="100000">100000 km<sup>2</sup></option>
      <!-- km<sup>2</sup> では option タグ内で
            km² になりません -->
     </select>
    <label>
   <form">
  <div>
  <script src="./index.js"></script>
 <body>
</html>

npm start を実行します。

user@deb9-vmw:~/new-project$ npm start

Webブラウザのアドレス欄に

http://localhost:1234

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

ol5.3ex 3 - Bing Maps

「Bing Maps (bing-maps.html) 」を参考に地図を表示してみます。

Microsoft の 「Custom Maps API for Business | Bing Maps or Enterprise(https://www.microsoft.com/en-us/maps/)」の「Why Bing Maps?」に次のようにあります。

Why Bing Maps?
A Microsoft Cloud Service trusted by enterprise customers worldwide, the Bing Maps platform offers all-inclusive pricing, 24/7 enterprise-grade support at no charge, and flexible licensing.

なぜ Bing Maps?
世界のエンタープライズ分野の顧客によって信頼されているマイクロソフトクラウドサービス、Bing Maps プラットフォームは全部を含めた値段と、24/7のエンタープライズグレードサポートを課金無しで、柔軟なライセンスを提供します。


「Map Control API Reference」の「MapTypeEventArgs Object(https://msdn.microsoft.com/en-us/library/mt761725.aspx)」に「newMapTypeId」と「oldMapTypeId」があります。この例「Bing Maps」では、表示されないマップ(Collins Bart)があります。

説明に次のようにあります。

When the Bing Maps tile service doesn't have tiles for a given resolution and region it returns "placeholder" tiles indicating that. Zoom the map beyond level 19 to see the "placeholder" tiles. If you want OpenLayers to display stretched tiles in place of "placeholder" tiles beyond zoom level 19 then set maxZoom to 19 in the options passed to ol/source/BingMaps.

Bing Maps タイルサービスに与えられる解像度と範囲のタイルがないとき、それを示す "placeholder(プレースホルダ)" タイルを返します。 "placeholder" タイルを見るためにレベル19を超えて map をズームします。 ズームレベル19を超える "プレースホルダ" タイルの場所に拡大タイルを表示することを OpenLayers に望むなら、 ol/source/BingMaps へ渡される option(オプション)で maxZoom を19に設定します。

次の内容で index.js を作成します。
user@deb9-vmw:~/new-project$ vim index.js
import 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import BingMaps from 'ol/source/BingMaps';
var styles = [
 'Road',
 'RoadOnDemand',
 'Aerial',
 'AerialWithLabels',
 'collinsBart',
 'ordnanceSurvey'
];
var layers = [];
var i, ii;
for (i = 0, ii = styles.length; i < ii; ++i) {
 layers.push(new TileLayer({
 /** Array.prototype.push()
  * The push() method adds one or more elements to the end 
  * of an array and returns the new length of the array.
  * push() メソッドは、配列の末尾に 1 つ以上の要素を追加す
  * ることができます。また戻り値として新しい配列の要素数を返
  * します。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/
  * JavaScript/Reference/Global_Objects/Array/push])
  */
 /** ol/layer/Tile~TileLayer 
  * For layer sources that provide pre-rendered, tiled 
  * images in grids that are organized by zoom levels for 
  * specific resolutions. 
  * プリレンダリング(事前描画)を提供するレイヤソースのため
  * の、特定の解像度でのズームレベルによって編成されているグ
  * リッドのタイルイメージ。(ol5 API)
  */
  visible: false,
  /** visible(option)
   * Visibility.
   * 目に見えること。(ol5 API)
   */
  preload: Infinity,
  /** preload(option)
   * Preload. Load low-resolution tiles up to preload 
   * levels. 0 means no preloading.
   * プリ(事前)ロード。プリロードレベルまで低解像度のタイ
   * ルをロードします。デフォルトのプリロードは、全くプリロー
   * ドしないことを意味する 0 です。(ol5 API)
  */
  source: new BingMaps({
  /** source(option)
   * Source for this layer. Required.
   * レイヤのソース。必須。(ol5 API)
   */
  /** ol/source/BingMaps~BingMaps 
   * Layer source for Bing Maps tile data.
   * Bing Maps タイルデータのレイヤソース。(ol5 API)
   */
   key: 'Your Bing Maps Key from http://www.bingmapsportal.com/ here',
   /** key(option)
    * Bing Maps API key. Get yours at 
    * http://www.bingmapsportal.com/.
    * Bing Maps API キー。取得は、
    * http://www.bingmapsportal.com/(ol5 API)
    */
   imagerySet: styles[i]
   /** imagerySet(option)
    * Type of imagery. 
    * 画像の種類。(ol5 API)
    */
   // use maxZoom 19 to see stretched tiles instead of the 
   // BingMaps "no photos at this zoom level" tiles
   // BingMaps の "no photos at this zoom level" タイル
   // の替わりに伸ばされたタイルが見えるために maxZoom 19 
   // を使います。
   // maxZoom: 19
  })
 }));
}
var map = new Map({
 layers: layers,
 /** layers[new Map(options)]
  * Layers. If this is not defined, a map with no layers 
  * will be rendered. Note that layers are rendered in 
  * the order supplied, so if you want, for example, a 
  * vector layer to appear on top of a tile layer, it 
  * must come after the tile layer.
  * layers(レイヤ)。これが定義されていない場合、layers の
  * ない map が描画されます。layers は提供される順番で描画さ
  * れ、もし、例えば、タイルレイヤの上部にベクタレイヤを表示
  * したいなら、タイルレイヤの後に来なければなりません。
  * (ol5 API)
  */
 // Improve user experience by loading tiles while 
 // dragging/zooming. Will make zooming choppy on mobile 
 // or slow devices.
 // ドラッグ/ズームの間、タイルをロードすることによってユー
 // ザエクスペリエンス(体験)を向上します。モバイル、また
 // は、遅い機器ではズームをとぎれとぎれにします。
 loadTilesWhileInteracting: true,
 /** loadTilesWhileInteracting[new Map(options)]
  * When set to true, tiles will be loaded while 
  * interacting with the map. This may improve the user 
  * experience, but can also make map panning and zooming 
  * choppy on devices with slow memory. Default is false.
  * true に設定すると、タイルはマップとの対話中にロードされま
  * す。これは、ユーザエクスペリエンスを向上させるだけでなく、
  * 低速メモリを持つデバイス上でマップパンおよびズームをとぎれ
  * とぎれにすることもできます。デフォルトは false です。
  * (ol5 API)
  */
 target: 'map',
 /** target[new Map(options)]
  * The container for the map, either the element 
  * itself or the id of the element. If not specified 
  * at construction time, module:ol/Map~Map#setTarget 
  * must be called for the map to be rendered.
  * map のコンテナ、(HTML)エレメント自身、またはエレメント
  * の id。構築時に指定されていない場合、描画される map のた
  * めにモジュール:ol/Map~Map#setTarget が呼び出されなけれ
  * ばなりません。
  * (ol5 API)
  */
 view: new View({
 /** view[new Map(options)]
  * The map's view. No layer sources will be fetched 
  * unless this is specified at construction time or 
  * through module:ol/Map~Map#setView.
  * map(マップ)の view(ビュー)。これが構築時に指定されて
  * いないか、モジュール:ol/Map~Map#setView を通じてなけれ
  * ば、取得されるレイヤソースはありません。
  * (ol5 API)
  */
 /** View(ol/View)
  * A View object represents a simple 2D view of the map.
  * This is the object to act upon to change the center, 
  * resolution, and rotation of the map.
  * View(ビュー)オブジェクトは、map(マップ)の 単純な 2D 
  * view を表示します。
  * これは、map の center(中心)、resolution(解像度)、
  * rotation (回転)を変換を実行するためのオブジェクトです。
  * (ol5 API)
  */
  center: [-6655.5402445057125, 6709968.258934638],
  /** center[new View(opt_options)]
   * The initial center for the view. The coordinate 
   * system for the center is specified with the 
   * projection option. Layer sources will not be fetched
   * if this is not set, but the center can be set later 
   * with #setCenter.
   * view(ビュー)の初期 center(中心)値。 center の座標
   * 系は、projection(投影法)オプションで指定されます。これ
   * が設定されなければレイヤソースは取得されませんが、center 
   * は #setCenter で後で設定できます。
   * (ol5 API)
   */
  zoom: 13
  /** zoom[new View(opt_options)]
   * Only used if resolution is not defined. Zoom level 
   * used to calculate the initial resolution for the 
   * view. The initial resolution is determined using 
   * the #constrainResolution method.
   * resolution(解像度)が定義されていない場合のみ使用され
   * ます。view の初期 resolution(解像度)を計算するために
   * 使用されるzoom(ズーム)レベル。初期 resolution は、
   * #constrainResolution メソッドを使用して決定されます。
   * (ol5 API)
   */
 })
});
var select = document.getElementById('layer-select');
/** Document.getElementById()
 * The Document method getElementById() returns an 
 * Element object representing the element whose id 
 * property matches the specified string. Since element 
 * IDs are required to be unique if specified, they're a 
 * useful way to get access to a specific element 
 * quickly.
 * If you need to get access to an element which doesn't 
 * have an ID, you can use querySelector() to find the 
 * element using any selector.
 * Document の getElementById() メソッドは、 id プロパティ
 * が指定された文字列に一致する要素を表す Element オブジェ
 * クトを返します。要素の ID は指定されていれば固有であるこ
 * とが求められているため、特定の要素にすばやくアクセスする
 * には便利な方法です。
 * ID を持たない要素にアクセスする必要が ある場合は、
 * querySelector() で何らかのセレクターを使用して要素を検
 * 索することができます。
 * (MDN[https://developer.mozilla.org/ja/docs/Web/API/
 * Document/getElementById])
 */
function onChange() {
 var style = select.value;
 for (var i = 0, ii = layers.length; i < ii; ++i) {
  layers[i].setVisible(styles[i] === style);
  /** setVisible[TileLayer]
   * Set the visibility of the layer (true or false).
   * layer の visibility(ビジビリティ、目に見えること)
   * (true or false)を設定します。
   * (ol5 API)
   */
 }
}
select.addEventListener('change', onChange);
/** EventTarget.addEventListener()
 * The EventTarget method addEventListener() sets up a 
 * function that will be called whenever the specified 
 * event is delivered to the target. Common targets are
 * Element, Document, and Window, but the target may be 
 * any object that supports events (such as 
 * XMLHttpRequest).
 * addEventListener() works by adding a function or an 
 * object that implements EventListener to the list of 
 * event listeners for the specified event type on the 
 * EventTarget on which it's called.
 * EventTarget.addEventListener() メソッドは、指定された
 * イベントがターゲットに渡されるときにはいつでも呼び出される
 * ファンクションを設定します。一般的なターゲットは、Element、
 * Document、Window ですが、ターゲットは(XMLHttpRequest 
 * のような)イベントをサポートするあらゆるオブジェクトです。
 * addEventListener() は、呼び出される EventTarget の指
 * 定されたイベントタイプためのイベントリスナのリストに 
 * EventListener を実装するファンクション、または、オブジェ
 * クトを追加することによって動作します。
 *(MDN[https://developer.mozilla.org/en-US/docs/Web/API/
 * EventTarget.addEventListener])
 */
onChange();
次に index.html を作成します。
user@deb9-vmw:~/new-project$ vim index.html
<!doctype html>
<html>
 <head>
  <meta charset="utf-8">
  <title>Bing Maps</title>
  <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
 </head>
 <body>
  <div id="map"></div>
  <select id="layer-select">
   <option value="Aerial">Aerial</option>
   <option value="AerialWithLabels" selected>Aerial with labels</option>
   <option value="Road">Road (static)</option>
   <option value="RoadOnDemand">Road (dynamic)</option>
   <option value="collinsBart">Collins Bart</option>
   <option value="ordnanceSurvey">Ordnance Survey</option>
  </select>
  <script src="./index.js"></script>
 <body>
</html>
npm start を実行します。

user@deb9-vmw:~/new-project$ npm start

Webブラウザのアドレス欄に

http://localhost:1234

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



ol5.3ex 2 - OSM Vector Tiles

「OSM Vector Tiles (osm-vector-tiles.html.html) 」の説明に次のようにあります。

A simple vector tiles map with Mapzen vector tiles. This example uses the TopoJSON format's layerName option to determine the layer ("water", "roads", "buildings") for styling. Note: [ol/format/MVT] is an even more efficient format for vector tiles.

Mapzen ベクタタイルを使用した単純なベクタタイルマップ。この例は、スタイリングのためのレイヤ("water", "roads", "buildings")を決定するために TopoJSON フォーマットの layerName オプションを使用します。重要:[ol/format/MVT] は、ベクタタイルのさらに効果的なフォーマットです。

訳者注:Mapzen は、2018年1月でサービスを停止しました。

2018年11月30日金曜日

ol5.3ex 1 - Simple Map

「Simple Map (simple.html) 」を参考に地図を表示してみます。説明に次のようにあります。

A simple map with an OSM source.

OSM ソースを使用したシンプル(単純な)マップ。

次の内容で index.js と index.html を作成します。(テストで使ったファイルの内容と同じです。)
user@deb9-vmw:~/new-project$ vim index.js
import 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';
const map = new Map({
/** const[JavaScript]
 * Constants are block-scoped, much like variables defined 
 * using the let statement. The value of a constant cannot 
 * change through reassignment, and it can't be redeclared.
 * 定数(const)はブロックスコープで、let ステートメントを
 * 使用して定義された変数にとても似ています。定数の値は、再
 * 代入による変更はできず、再宣言されません。
 * (MDN[https://developer.mozilla.org/en-US/docs/Web/
 * JavaScript/Reference/Statements/const])
 */
/** Map[ol/Map]
 * The map is the core component of OpenLayers. For a map 
 * to render, a view, one or more layers, and a target 
 * container are needed:
 * map(マップ)は、OpenLayers のコアコンポーネントです。
 * map を描画するために、view(ビュー)と1つ以上の layers
 * (レイヤ)と target(ターゲット)コンテナが必要です:
 * (ol5 API)
 */
 target: 'map',
 /** target[new Map(options)]
  * The container for the map, either the element itself 
  * or the id of the element. If not specified at 
  * construction time, module:ol/Map~Map#setTarget must 
  * be called for the map to be rendered.
  * map のコンテナ、(HTML)エレメント自身、またはエレメント
  * の id。構築時に指定されていない場合、描画される map のた
  * めにモジュール:ol/Map~Map#setTarget が呼び出されなけれ
  * ばなりません。
  * (ol5 API)
  */
 layers: [
 /** layers[new Map(options)]
  * Layers. If this is not defined, a map with no layers 
  * will be rendered. Note that layers are rendered in 
  * the order supplied, so if you want, for example, a 
  * vector layer to appear on top of a tile layer, it 
  * must come after the tile layer.
  * layers(レイヤ)。これが定義されていない場合、layers のな
  * い map が描画されます。layers は提供される順番で描画され、
  * もし、例えば、タイルレイヤの上部にベクタレイヤを表示したい
  * なら、タイルレイヤの後に来なければなりません。
  * (ol5 API)
  */
  new TileLayer({
   source: new OSM()
  })
 ],
 view: new View({
 /** view[new Map(options)]
  * The map's view. No layer sources will be fetched unless
  * this is specified at construction time or through 
  * module:ol/Map~Map#setView.
  * map(マップ)の view(ビュー)。これが構築時に指定されてい
  * ないか、モジュール:ol/Map~Map#setView を通じてなければ、
  * 取るレイヤソースはありません。
  * (ol5 API)
  */
 /** View(ol/View)
  * A View object represents a simple 2D view of the map.
  * This is the object to act upon to change the center, 
  * resolution, and rotation of the map.
  * View(ビュー)オブジェクトは、map(マップ)の 単純な 2D 
  * view を表示します。
  * これは、map の center(中心)、resolution(解像度)、
  * rotation (回転)を変換を実行するためのオブジェクトです。
  * (ol5 API)
  */
  center: [0, 0],
  /** center[new View(opt_options)]
   * The initial center for the view. The coordinate system 
   * for the center is specified with the projection option. 
   * Layer sources will not be fetched if this is not set, 
   * but the center can be set later with #setCenter.
   * view(ビュー)の初期 center(中心)値。 center の座標系
   * は、projection(投影法)オプションで指定されます。これが
   * 設定されなければレイヤソースは取得されませんが、center は 
   * #setCenter で後で設定できます。
   * (ol5 API)
   */
  zoom: 2
  /** zoom[new View(opt_options)]
   * Only used if resolution is not defined. Zoom level used 
   * to calculate the initial resolution for the view. The 
   * initial resolution is determined using the 
   * #constrainResolution method.
   * resolution(解像度)が定義されていない場合のみ使用されま
   * す。view の初期 resolution(解像度)を計算するために使用
   * される zoom(ズーム)レベル。初期 resolution は、
   * #constrainResolution メソッドを使用して決定されます。
   * (ol5 API)
   */
 })
});

user@deb9-vmw:~/new-project$ vim index.html
<!doctype html>
<html>
 <head>
  <meta charset="utf-8">
  <title>Simple Map</title>
  <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
 </head>
 <body>
  <div id="map"></div>
  <script src="./index.js"></script>
 <body>
</html>
npm start を実行します。
user@deb9-vmw:~/new-project$ npm start
> new-project@1.0.0 start /home/user/ol5-examples01

> parcel index.html

Server running at http://localhost:1234

✨  Built in 16.23s.

Webブラウザのアドレス欄に

http://localhost:1234

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


v5.3.0 がリリースされました

v5.3.0 がリリースされました
日本時間で(2018.11.7)に v5.3.0 がリリースされました。

Releases 5.3.0 - openlayers/openlayers GitHub
(https://github.com/openlayers/openlayers/releases/tag/v5.3.0)より

We're continuing to work toward more complete type checking with TypeScript – based on JSDoc annotations in the source. The 5.3 release includes a number of bug fixes related to the type checking effort. In addition the release comes with a handful of new features and improved API reference docs.

ソース内の JSDoc annotations を基本とした - TypeScript を使用してより完全なタイプチェックに向かって作業しています。5.3 リリースは、2、3のタイプチェック効果に関係したバグフィックスを含みます。加えて、リリースは少しの新しい機能と向上した API リファレンスドキュメントを備えています。


Upgrade Notes

The getUid function returns string
getUid ファンクションは文字列を返します

The getUid function from the ol/util module now returns a string instead of a number.

ol/util モジュールからの getUid ファンクションは、現在、数字のかわりに文字列を返します。


Attributions are not collapsible for ol/source/OSM
Attributions は ol/source/OSM に対して折りたたみできません

When a map contains a layer from a ol/source/OSM source, the ol/control/Attribution control will be shown with the collapsible: false behavior.

map は ol/source/OSM ソースのレイヤを含むとき、ol/control/Attribution コントロールは collapsible: false 動作で表示されます。

To get the previous behavior, configure the ol/control/Attribution control with collapsible: true.

以前の動作を求めるためには、ol/control/Attribution コントロールをcollapsible: true に設定します。

(New Features and Fixes は、リストを参照して下さい。)

2018年10月31日水曜日

OpenLayers5 Workshop - 4.3 Render sea level

4 Raster Operations
4.3 Render sea level
平均海面を描画

In the previous step, we rendered the Terrain-RGB tiles directly on the map. What we want to do is render sea level on the map instead. And we want users to be able to adjust the height above sea level and see the adjusted height rendered on the map. We'll use a raster source to work with the elevation data directly and get the user input from an input slider on the page.

前回のステップで、Terrain-RGB タイルを直接マップ上に描画しました。(今回)したいことは、かわりに、平均海面をマップ上に描画します。そして、ユーザが海抜の高さを調整し、マップ上に描画された調節された高さを見ることができるようにします。elevation(標高)データで直接操作するためにラスタソースを使い、ページ上のインプットスライダからユーザインプット(input)を取得します。

Let's add the controls to the page first. In your index.html, add the following label and input slider:

最初にコントロ0るをページに追加しましょう。index.html に次のラベルとインプットスライダを追加します:
<label id="slider">
 Sea level
 <input id="level" type="range" min="0" max="100" value="1"/>
 +<span id="output"></span> m
</label>
Now add some style to those controls (in the <style> of your index.html):

では、(index.html の <style> に)いくつかのスタイルをそれらのコントロールに追加します:
#slider {
 position: absolute;
 bottom: 1rem;
 width: 100%;
 text-align: center;
 text-shadow: 0px 0px 4px rgba(255, 255, 255, 1);
}
Instead of directly rendering the R, G, B, A values from the Terrain-RGB tiles, we want to manipulate the pixel values before rendering. The raster source allows you to do this by accepting any number of input sources and an operation. This operation is a function that gets called for every pixel in the input sources. We only have one input source (elevation), so it will get called with an array of one pixel, where a pixel is a [red, green, blue, alpha] array. The operation also gets called with a data object. We'll use the data object to pass along the value of the input slider.

Terrain-RGB タイルから R、G、B、A 値を直接描画するかわりに、描画する前にピクセル値を操作するようにします。ラスタソース(raster source)は、任意の数のインプットソース(input source)と operation(オペレーション)を受け取ることによってこれを行うことを許可します。この operation はインプットソースのすべてのピクセルの呼び出し(call)を取得するファンクションです。1つのインプットソース(elevation)だけ持ち、そのため、1つのピクセルの配列を伴う呼び出しを取得し、ピクセルは、[red, green, blue, alpha] 配列になっています。operation は data(データ)オブジェクトを伴う呼び出しも取得します。インプットスライダの値に沿って渡すために data オブジェクトを使います。

First, import the RasterSource and ImageLayer (in main.js):

最初に、(main.js に)RasterSource と ImageLayer をインポートします:
import ImageLayer from 'ol/layer/Image';
import RasterSource from 'ol/source/Raster';
Add the function below to your main.js. This function decodes the input elevation data — transforming red, green, and blue values into a single elevation measure. For elevation values at or below the user selected value, the function returns a partially transparent blue pixel. For values above the user selected value, the function returns a transparent pixel.

下の function を main.js に追加します。このファンクションは、インプット elevation データを、赤(red)、緑(green)、青(blue)の値を単一の elevation 量に変換するために、デコード(復号化)します。ユーザが選択した、または、それより低い elevation 値の場合には、ファンクションは部分的に透明な青ピクセルを返します。ユーザが選択した値より高い場合には、ファンクションは透明なピクセルを返します。
function flood(pixels, data) {
 const pixel = pixels[0];
 if (pixel[3]) {
  // decode R, G, B values as elevation
  const height = -10000 + ((pixel[0] * 256 * 256 + pixel[1] * 256 + pixel[2]) * 0.1);
  if (height <= data.level) {
   // sea blue
   pixel[0] = 145; // red
   pixel[1] = 175; // green
   pixel[2] = 186; // blue
   pixel[3] = 255; // alpha
  } else {
   // transparent
   pixel[3] = 0;
  }
 }
 return pixel;
}
Create a raster source with a single input source (the elevation data), and configure it with the flood operation.

単一の入力ソース(elevation データ)でラスターソースを作成し、 flood operation でそれを設定します。
const raster = new RasterSource({
 sources: [elevation],
 operation: flood
});
Listen for changes on the slider input and re-run the raster operations when the user adjusts the value.

ユーザが値を調節するとき、スライダインプット(input)と raster operation の再実行の変更に対してリッスンします。
const control = document.getElementById('level');
const output = document.getElementById('output');
control.addEventListener('input', function() {
 output.innerText = control.value;
 raster.changed();
});
output.innerText = control.value;
The beforeoperations event is fired before the pixel operations are run on the raster source. This is our opportunity to provide additional data to the operations. In this case, we want to make the range input value (meters above sea level) available.

beforeoperations イベントは、pixel operations がラスタソースに対して実行される前に、始動します。これは、追加 data を operations に提供するための契機です。この場合、入力された値の範囲(標高メートル)を利用可能にします。
raster.on('beforeoperations', function(event) {
 event.data.level = control.value;
});
Finally, render the output from the raster operation by adding the source to an image layer. Replace the tile layer with an image layer that uses our raster source (modify the layers array in main.js):

最後に、ソースをイメージレイヤに追加することによって raster operation から出力を描画します。ラスタソースを使用するイメージレイヤで タイルレイヤを置き換えます(main.js で layers 配列を修正します):
new ImageLayer({
 opacity: 0.8,
 source: raster
})
With all this in place, the map should now have a slider that let's users control changes in sea level.

すべてこれを正しい場所に用いると、マップはユーザが海面の変化を調節できるスライダを保持できます。

Sea level rise in Boston

■□ Debian9 で試します■□
「Render sea level」の例を表示します。「Map setup」で使用した index.html のバックアップを保存して次のように修正します。

user@deb9-vmw:~/openlayers-workshop-en$ cp index.html index.html_mapsetup
user@deb9-vmw:~/openlayers-workshop-en$ vim index.html
<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title>OpenLayers</title>
  <style>
   html, body, #map-container {
    margin: 0;
    height: 100%;
    width: 100%;
    font-family: sans-serif;
    }
   #slider {
    position: absolute;
    bottom: 1rem;
    width: 100%;
    text-align: center;
    text-shadow: 0px 0px 4px rgba(255, 255, 255, 1);
   }
  </style>
 </head>
 <body>
  <div id="map-container"></div>
  <label id="slider">
   Sea level
   <input id="level" type="range" min="0" max="100" value="1"/>
   +<span id="output"></span> m
  </label>
 </body>
</html>
「Render elevation data」で使用した main.js のバックアップを保存して次のように修正します。

user@deb9-vmw:~/openlayers-workshop-en$ cp main.js main.js_elevation
user@deb9-vmw:~/openlayers-workshop-en$ vim main.js
import 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import XYZSource from 'ol/source/XYZ';
import {fromLonLat} from 'ol/proj';
import ImageLayer from 'ol/layer/Image';
import RasterSource from 'ol/source/Raster';
const key = '<your-default-public-token>';
const elevation = new XYZSource({
 url: 'https://api.mapbox.com/v4/mapbox.terrain-rgb/{z}/{x}/{y}.pngraw?access_token=' + key,
 crossOrigin: 'anonymous'
});
function flood(pixels, data) {
 const pixel = pixels[0];
 if (pixel[3]) {
  // decode R, G, B values as elevation
  const height = -10000 + ((pixel[0] * 256 * 256 + pixel[1] * 256 + pixel[2]) * 0.1);
  if (height <= data.level) {
   // sea blue
   pixel[0] = 145; // red
   pixel[1] = 175; // green
   pixel[2] = 186; // blue
   pixel[3] = 255; // alpha
  } else {
   // transparent
   pixel[3] = 0;
  }
 }
 return pixel;
}
const raster = new RasterSource({
 sources: [elevation],
 operation: flood
});
const control = document.getElementById('level');
const output = document.getElementById('output');
control.addEventListener('input', function() {
 output.innerText = control.value;
 raster.changed();
});
output.innerText = control.value;
raster.on('beforeoperations', function(event) {
 event.data.level = control.value;
});
new Map({
 target: 'map-container',
 layers: [
  new TileLayer({
   source: new XYZSource({
    url: 'http://tile.stamen.com/terrain/{z}/{x}/{y}.jpg'
   })
  }),
  new ImageLayer({
   opacity: 0.8,
   source: raster
  })
 ],
 view: new View({
  center: fromLonLat([-71.06, 42.37]),
  zoom: 12
 })
});
http://localhost:3000/ とブラウザでマップを開きます。(もし開かなければ、'npm start' を実行してください。



OpenLayers5 Workshop - 4.2 Render elevation data

4 Raster Operations
4.2 Render elevation data
標高データを描画

We're going to work with elevation data that is encoded in PNG tiles (see the Mapbox post on Terrain-RGB for more detail). For this exercise, you'll need to sign up for a Mapbox account and use your access token for tiles.

PNG(ピングフォーマット画像)タイルでエンコードされる elevation(標高)データを使って作業します(さらに詳細は Mapbox に搭載の Terrain-RGB を参照)。この演習のために、Mapbox アカウントのサインアップとタイルのためのアクセストークンを使うことが必要です。

Add your default public token to main.js:

デフォルトのパブリックトークンを main.js を追加します:

const key = '<your-default-public-token>';

We want to manipulate the elevation data before rendering, but initially we'll add the Terrain-RGB tiles to the map just to see what they look like. To do this, create an XYZ source with the Terrain-RGB URL and your access token.

描画の前に elevation データを操作したいのですが、最初に、どのように見えるか単に見るため、Terrain-RGB タイルをマップに追加します。これを実行するため、Terrain-RGB URL とアクセストークンで XYZ ソースを作成します。
const elevation = new XYZSource({
 url: 'https://api.mapbox.com/v4/mapbox.terrain-rgb/{z}/{x}/{y}.pngraw?access_token=' + key,
 crossOrigin: 'anonymous'
});
Next, create a tile layer that uses the elevation source. Add this layer your map's layers array in main.js:

次に、elevation ソースを使うタイルレイヤを作成します。 main.js でこのレイヤをマップレイヤ配列に追加します:
new TileLayer({
 opacity: 0.8,
 source: elevation
})
You should now see some oddly colored tiles shown over your base layer. The elevation data in the Terrain-RGB tiles is encoded in the red, green, and blue channels. So while this data isn't meant to be rendered directly, it is interesting to look at.

ベースレイヤを覆って表示される奇妙なカラータイルが見られます。Terrain-RGB タイルの標高データは、赤、緑、青チャンネルにエンコードされます。このデータは、直接描画されるものではありませんが、見るのは興味深いです。

Terrain-RGB tiles rendered over Boston

■□ Debian9 で試します■□
「Render elevation data」の例を表示します。「Map setup」で使用した main.js のバックアップを保存して次のように修正します。

user@deb9-vmw:~/openlayers-workshop-en$ cp main.js main.js_mapsetup
user@deb9-vmw:~/openlayers-workshop-en$ vim main.js
import 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import XYZSource from 'ol/source/XYZ';
import {fromLonLat} from 'ol/proj';
const key = '<your-default-public-token>';
const elevation = new XYZSource({
 url: 'https://api.mapbox.com/v4/mapbox.terrain-rgb/{z}/{x}/{y}.pngraw?access_token=' + key,
 crossOrigin: 'anonymous'
});
new Map({
 target: 'map-container',
 layers: [
  new TileLayer({
   source: new XYZSource({
    url: 'http://tile.stamen.com/terrain/{z}/{x}/{y}.jpg'
   })
  }),
  new TileLayer({
   opacity: 0.8,
   source: elevation
  })
 ],
 view: new View({
  center: fromLonLat([-71.06, 42.37]),
  zoom: 12
 })
});
http://localhost:3000/ とブラウザでマップを開きます。(もし開かなければ、'npm start' を実行してください。



OpenLayers5 Workshop - 4.1 Map setup

4 Raster Operations
ラスタ操作

Up to this point, when we have used raster data (with an XYZ tile source for example), we have used it for presentation purposes only — rendering the data directly to the map. It is also possible to work with the pixel values in the data we fetch, run operations on these values, and manipulate things before rendering. The Raster source provides a way to run pixel-wise operations on data from any number of input sources. When the source is used in an Image layer, the result of the raster operation can be rendered on the map.

ここまでで、(example の XYZ タイルソースを使用した)ラスタデータ使うとき、プレゼンテーション目的だけで使い、データを直接マップに描画します。描画前にものを取得して、これらの値に関する操作を実行し、操作するデータにピクセル値で動作することも可能です。ラスタソースは、任意の数の入力ソースからデータに関するピクセル関連の操作を実行する方法を提供します。ソースはイメージ(Image)レイヤで使用されるとき、ラスタ操作の結果は、マップ上に描画されます。

In these exercises, we'll work with elevation data served as XYZ tiles. Instead of rendering the encoded elevation data directly, we'll run a pixel-wise operation on the data before rendering.

この演習で、 XYZ アイルとして供給される標高データを使って作業します。エンコードされた標高データを直接描画するかわりに、描画の前にデータに関するピクセル関連の操作を実行します。

● Map setup
● Render elevation data
● Render sea level

● マップ装備
● 標高データを描画
● 海抜を描画

4.1 Map setup
マップ装備

Edit your index.html so we're ready to render a full page map:

全画面マップを描画する準備のために index.html を編集します:
<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title>OpenLayers</title>
  <style>
   html, body, #map-container {
    margin: 0;
    height: 100%;
    width: 100%;
    font-family: sans-serif;
    }
  </style>
 </head>
 <body>
  <div id="map-container"></div>
 </body>
</html>
We'll start out with a map centered on Boston showing a single XYZ source. Update your main.js so it looks like this:

単一の XYZ ソースを表示するボストンを中心としたマップで始めます。このように見えるように main.js を更新します:
import 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import XYZSource from 'ol/source/XYZ';
import {fromLonLat} from 'ol/proj';
new Map({
 target: 'map-container',
 layers: [
  new TileLayer({
   source: new XYZSource({
    url: 'http://tile.stamen.com/terrain/{z}/{x}/{y}.jpg'
   })
  })
 ],
 view: new View({
  center: fromLonLat([-71.06, 42.37]),
  zoom: 12
 })
});
A map of Boston

■□ Debian9 で試します■□
「Map setup」の例を表示します。「Making things look bright」で使用した index.html のバックアップを保存して次のように修正します。

user@deb9-vmw:~/openlayers-workshop-en$ cp index.html index.html_bright
user@deb9-vmw:~/openlayers-workshop-en$ vim index.html
<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title>OpenLayers</title>
  <style>
   html, body, #map-container {
    margin: 0;
    height: 100%;
    width: 100%;
    font-family: sans-serif;
    }
  </style>
 </head>
 <body>
  <div id="map-container"></div>
 </body>
</html>
「Making things look bright」で使用した main.js のバックアップを保存して次のように修正します。

user@deb9-vmw:~/openlayers-workshop-en$ cp main.js main.js_bright
user@deb9-vmw:~/openlayers-workshop-en$ vim main.js
import 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import XYZSource from 'ol/source/XYZ';
import {fromLonLat} from 'ol/proj';
new Map({
 target: 'map-container',
 layers: [
  new TileLayer({
   source: new XYZSource({
    url: 'http://tile.stamen.com/terrain/{z}/{x}/{y}.jpg'
   })
  })
 ],
 view: new View({
  center: fromLonLat([-71.06, 42.37]),
  zoom: 12
 })
});
http://localhost:3000/ とブラウザでマップを開きます。(もし開かなければ、'npm start' を実行してください。