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

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' を実行してください。



2015年11月30日月曜日

2 - ol3.11ex 139b - Raster reprojection example 2

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

「2139-ol3ex.js」
proj4.defs('EPSG:27700', '+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 ' +
 '+x_0=400000 +y_0=-100000 +ellps=airy ' +
 '+towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 ' +
 '+units=m +no_defs');
var proj27700 = ol.proj.get('EPSG:27700');
/** ol.proj.get(projectionLike)
 * Fetches a Projection object for the code specified.
 * 指定されたコードのプロジェクション·オブジェクトを取得
 * (ol3 API)
 */
proj27700.setExtent([0, 0, 700000, 1300000]);
/** setExtent(extent)
 * Set the validity extent for this projection.
 * この投影の有効範囲を設定します。(ol3 API)
 */
proj4.defs('EPSG:23032', '+proj=utm +zone=32 +ellps=intl ' +
 '+towgs84=-87,-98,-121,0,0,0,0 +units=m +no_defs');
var proj23032 = ol.proj.get('EPSG:23032');
proj23032.setExtent([-1206118.71, 4021309.92, 1295389.00, 8051813.28]);
proj4.defs('EPSG:5479', '+proj=lcc +lat_1=-76.66666666666667 +lat_2=' +
 '-79.33333333333333 +lat_0=-78 +lon_0=163 +x_0=7000000 +y_0=5000000 ' +
 '+ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');
var proj5479 = ol.proj.get('EPSG:5479');
proj5479.setExtent([6825737.53, 4189159.80, 9633741.96, 5782472.71]);
proj4.defs('EPSG:21781', '+proj=somerc +lat_0=46.95240555555556 ' +
 '+lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel ' +
 '+towgs84=674.4,15.1,405.3,0,0,0,0 +units=m +no_defs');
var proj21781 = ol.proj.get('EPSG:21781');
proj21781.setExtent([485071.54, 75346.36, 828515.78, 299941.84]);
proj4.defs('EPSG:3413', '+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 ' +
 '+x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs');
var proj3413 = ol.proj.get('EPSG:3413');
proj3413.setExtent([-4194304, -4194304, 4194304, 4194304]);
proj4.defs('EPSG:2163', '+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 ' +
 '+a=6370997 +b=6370997 +units=m +no_defs');
var proj2163 = ol.proj.get('EPSG:2163');
proj2163.setExtent([-8040784.5135, -2577524.9210, 3668901.4484, 4785105.1096]);
proj4.defs('ESRI:54009', '+proj=moll +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 ' +
 '+units=m +no_defs');
var proj54009 = ol.proj.get('ESRI:54009');
proj54009.setExtent([-18e6, -9e6, 18e6, 9e6]);
var layers = [];
layers['bng'] = new ol.layer.Tile({
/** ol.layer.Tile 
 * For layer sources that provide pre-rendered, tiled 
 * images in grids that are organized by zoom levels for 
 * specific resolutions. 
 * プリレンダリング(事前描画)を提供するレイヤソースのため
 * の、特定の解像度でのズームレベルによって編成されているグ
 * リッドのタイルイメージ。(ol3 API)
 */
 source: new ol.source.XYZ({
 /** ol.source.XYZ
  * Layer source for tile data with URLs in a set XYZ 
  * format that are defined in a URL template. By 
  * default, this follows the widely-used Google grid 
  * where x 0 and y 0 are in the top left. Grids like 
  * TMS where x 0 and y 0 are in the bottom left can 
  * be used by using the {-y} placeholder in the URL 
  * template, so long as the source does not have a 
  * custom tile grid. In this case, ol.source.TileImage 
  * can be used with a tileUrlFunction such as:
  *
  * tileUrlFunction: function(coordinate) { 
  *  return 'http://mapserver.com/' 
  *  + coordinate[0] + '/' 
  *  + coordinate[1] + '/' 
  *  + coordinate[2] + '.png'; }
  * 
  * URL テンプレートで定義されているセット XYZ 形式の URL 
  * を持つタイルデータのレイヤソース。デフォルトでは、これは、
  * x0 と y0 が左上にある広く使用されている Google のグリッド
  * に従います。x0 と y0 が左下にある TMS のようなグリッドは、
  * ソースがカスタムタイルグリッドを持っていない限り、URL テ
  * ンプレートに {-y} プレースホルダを使用して使用することが
  * できます。この場合、ol.source.TileImage は tileUrlFunction 
  * で次のように使用できます。(ol3 API)
  */
  projection: 'EPSG:27700',
  url: 'http://tileserver.maptiler.com/miniscale/{z}/{x}/{y}.png',
  /** 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 オプションでそれぞれを個別に定義する代わりに、
   * 使用することができます。(ol3 API)
   */
  crossOrigin: '',
  /** crossOrigin
   * 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のレンダ
   * ラーを使用している場合、または、キャンバスレンダラでピ
   * クセルデータにアクセスする場合、crossOrigin 値を提供な
   * ければならないことに注意してください。詳細は 
   * https://developer.mozilla.org/en-US/docs/Web/HTML/
   * CORS_enabled_image を参照してください。(ol3 API)
   */
  maxZoom: 6
 })
});
layers['mapquest'] = new ol.layer.Tile({
 source: new ol.source.MapQuest({layer: 'osm'})
 /** ol.source.MapQuest
  * Layer source for the MapQuest tile server.
  * MapQuest タイルサーバのレイヤソース。(ol3 API
  * 2 - ol3ex 23b - MapQuest example 2 参照)
  */
});
layers['wms4326'] = new ol.layer.Tile({
 source: new ol.source.TileWMS({
 /** ol.source.TileWMS
  * Layer source for tile data from WMS servers.
  * WMS サーバからのタイルデータのレイヤソース。
  * (ol3 API)
  */
  url: 'http://demo.boundlessgeo.com/geoserver/wms',
  crossOrigin: '',
  params: {
  /** params
   * WMS request parameters. At least a LAYERS param is 
   * required. STYLES is '' by default. VERSION is 
   * 1.3.0 by default. WIDTH, HEIGHT, BBOX and CRS (SRS 
   * for WMS version < 1.3.0) will be set dynamically. 
   * Required.
   * WMSは、パラメータを要求します。少なくとも LAYERS の 
   * param が必要です。スタイルは「デフォルト」に従います。 
   * VERSION は、デフォルトでは 1.3.0 です。WIDTH、HIGHT、
   * BBOX と CRS(WMS バージョン 1.3.0 未満用 SRS)は、動的
   * に設定されます。 必須。(ol3 API)
   */
   'LAYERS': 'ne:NE1_HR_LC_SR_W_DR'
  },
  projection: 'EPSG:4326'
 })
});
layers['wms21781'] = new ol.layer.Tile({
 source: new ol.source.TileWMS({
  attributions: [new ol.Attribution({
  /** ol.Attribution
   * An attribution for a layer source.
   * レイヤソースの属性(ol3 API)
   */
   html: '&copy; ' +
    '<a href="http://www.geo.admin.ch/internet/geoportal/' +
    'en/home.html"≶' +
    'Pixelmap 1:1000000 / geo.admin.ch</a≶'
  })],
  crossOrigin: 'anonymous',
  params: {
   'LAYERS': 'ch.swisstopo.pixelkarte-farbe-pk1000.noscale',
   'FORMAT': 'image/jpeg'
  },
  url: 'http://wms.geo.admin.ch/',
  projection: 'EPSG:21781'
 })
});
var parser = new ol.format.WMTSCapabilities();
/** ol.format.WMTSCapabilities
 * Format for reading WMTS capabilities data
 * WMTS capabilities データを読み込むためのフォーマット。
 * (ol3 API)
 */
$.ajax('http://map1.vis.earthdata.nasa.gov/wmts-arctic/' +
 'wmts.cgi?SERVICE=WMTS&request=GetCapabilities').then(function(response) {
/** jQuery.ajax()
 * Perform an asynchronous HTTP (Ajax) request.
 * 非同期 HTTP(Ajax)リエストを実行します。
 * (jQuery[http://api.jquery.com/jquery.ajax/])
 */
/** deferred.then()
 * Add handlers to be called when the Deferred object is 
 * resolved, rejected, or still in progress. 
 * deferred オブジェクトが resolved、rejected か、まだ処理
 * 途中(progress)のとき呼び出されるハンドラを追加します。
 * (juery[http://api.jquery.com/deferred.then/])
 */
 var result = parser.read(response);
 /** read()
  * Read a WMTS capabilities document.
  * (ol3 API[説明は Stable Only のチェックを外すと表示])
  */
 var options = ol.source.WMTS.optionsFromCapabilities(result,
 /** ol.source.WMTS.optionsFromCapabilities
  * Return: WMTS source options object.
  * (ol3 API[説明は Stable Only のチェックを外すと表示])
  */
  {layer: 'OSM_Land_Mask', matrixSet: 'EPSG3413_250m'});
 options.crossOrigin = '';
 options.projection = 'EPSG:3413';
 options.wrapX = false;
 layers['wmts3413'] = new ol.layer.Tile({
  source: new ol.source.WMTS(options)
 });
});
layers['grandcanyon'] = new ol.layer.Tile({
 source: new ol.source.XYZ({
  url: 'http://tileserver.maptiler.com/grandcanyon@2x/{z}/{x}/{y}.png',
  crossOrigin: '',
  tilePixelRatio: 2,
  /** tilePixelRatio
   * The pixel ratio used by the tile service. For 
   * example, if the tile service advertizes 256px by 
   * 256px tiles but actually sends 512px by 512px 
   * tiles (for retina/hidpi devices) then 
   * tilePixelRatio should be set to 2. Default is 1.
   * タイルサービスによって使用されるピクセル比。たとえば、タ
   * イルサービスが 256px x 256px タイルを通知する場合、実際
   * には 512px x 512px  タイル(retina / hidpiデバイス用)
   * を送信し、それから、タイル Pixel Ratio は 2 に設定しな
   * ければなりません。デフォルトは 1 です。
  * (ol3 API[説明は Stable Only のチェックを外すと表示])
   */
  maxZoom: 15,
  attributions: [new ol.Attribution({
   html: 'Tiles © USGS, rendered with ' +
    '<a href="http://www.maptiler.com/"≶MapTiler</a≶'
  })]
 })
});
var startResolution =
 ol.extent.getWidth(ol.proj.get('EPSG:3857').getExtent()) / 256;
 /** ol.extent.getWidth(extent)
  * Return: Width.(ol3 API)
  */
/** ol.proj.get(projectionLike)
 * Fetches a Projection object for the code specified.
 * 指定されたコードのプロジェクション·オブジェクトを取得
 * (ol3 API)
 */
/** getExtent()
 * Get the validity extent for this projection.
 * この投影の有効範囲を取得。(ol3 API)
 */
var resolutions = new Array(22);
/** Array(arraylength)
 * JavaScript は配列を扱うことができます。配列とは順序を持つ複
 * 数のデータの集合であり、JavaScript のグローバルオブジェクト 
 * である Array は、高位の、(C言語等で云うところの)「リス
 * ト」の様な、配列のコンストラクタです。
 * arraylength
 * Array コンストラクタに渡される唯一の引数(arrayLength)に 
 * 0 から 4,294,967,295( 232-1 ) までの整数値を指定する場合
 * その値を要素数とする配列が作成されます。その際に範囲外の値
 * は、を指定した場合には、例外: RangeError がスローされます。
 * (MDN[https://developer.mozilla.org/ja/docs/Web/
 * JavaScript/Reference/Global_Objects/Array])
 */
for (var i = 0, ii = resolutions.length; i < ii; ++i) {
 resolutions[i] = startResolution / Math.pow(2, i);
 /** Math.pow(base, exponent)
  * base を exponent 乗した値、つまり、base^exponent の
  * 値を返します。
  * (MDN[https://developer.mozilla.org/ja/docs/Web/
  * JavaScript/Reference/Global_Objects/Math/pow])
  */
}
layers['states'] = new ol.layer.Tile({
 source: new ol.source.TileWMS({
  url: 'http://demo.boundlessgeo.com/geoserver/wms',
  crossOrigin: '',
  params: {'LAYERS': 'topp:states', 'TILED': true},
  serverType: 'geoserver',
  /** serverType
   * The type of the remote WMS server. Currently 
   * only used when hidpi is true. Default is 
   * undefined.
   * リモート WMS サーバのタイプ。 現在、hidpi が true 
   * の場合のみ使用。デフォルトでは定義されていません。
  * (ol3 API[説明は Stable Only のチェックを外すと表示])
   */
  tileGrid: new ol.tilegrid.TileGrid({
  /** tileGrid
   * Tile grid. Base this on the resolutions, 
   * tilesize and extent supported by the server. 
   * If this is not defined, a default grid will be 
   * used: if there is a projection extent, the 
   * grid will be based on that; if not, a grid 
   * based on a global extent with origin at 
   * 0,0 will be used.
   * タイルグリッド。サーバーがサポートしていル解像度、タイル
   * サイズと範囲に関してこれに基づいています。これが定義され
   * ていない場合、デフォルトのグリッドが使用されます:投影範
   * 囲が存在する場合、グリッドはそれに基づくことになります。
   * そうでない場合は、0, 0 を原点とするグローバルな範囲に基
   * づいたグリッドが使用されます。(ol3 API)
   */
  /** ol.tilegrid.TileGrid
   * Base class for setting the grid pattern for 
   * sources accessing tiled-image servers.
   * タイル画像サーバにアクセスするソースのグリッドパターンを
   * 設定するための基本クラス。(ol3 API)
   */
   extent: [-13884991, 2870341, -7455066, 6338219],
   /** extent
    * Extent for the tile grid. No tiles outside this 
    * extent will be requested by ol.source.Tile 
    * sources. When no origin or origins are 
    * configured, the origin will be set to the 
    * top-left corner of the extent.
    * タイルグリッドの範囲。この範囲外ではタイルは 
    * ol.source.Tile ソースによって要求されません。origin 
    * がない、または、origins が構成されていない場合には、原点
    * は exten の左上隅に設定されます。
   * (ol3 API[説明は Stable Only のチェックを外すと表示])
    */
   resolutions: resolutions,
   /** resolutions
    * Resolutions. The array index of each resolution 
    * needs to match the zoom level. This means that 
    * even if a minZoom is configured, the resolutions 
    * array will have a length of maxZoom + 1. Required.
    * 解像度。各解像度の配列インデックスは、ズームレベルを一
    * 致させる必要があります。これは minZoom が設定されている
    * 場合でも、解像度配列は maxZoom+1 の長さを有することを意
    * 味します。必須。(ol3 API)
    */
   tileSize: [512, 256]
  }),
  projection: 'EPSG:3857'
 })
});
var map = new ol.Map({
 layers: [
  layers['mapquest'],
  layers['bng']
 ],
 renderer: common.getRendererFromQueryString(),
// 'common.js' により URL にある renderer を返します
 target: 'map',
 view: new ol.View({
  projection: 'EPSG:3857',
  center: [0, 0],
  zoom: 2
 })
});
var baseLayerSelect = document.getElementById('base-layer');
var overlayLayerSelect = document.getElementById('overlay-layer');
var viewProjSelect = document.getElementById('view-projection');
var renderEdgesCheckbox = document.getElementById('render-edges');
var renderEdges = false;
function updateViewProjection() {
 var newProj = ol.proj.get(viewProjSelect.value);
 var newProjExtent = newProj.getExtent();
 var newView = new ol.View({
  projection: newProj,
  center: ol.extent.getCenter(newProjExtent || [0, 0, 0, 0]),
  /** ol.extent.getCenter(extent)
   * Get the center coordinate of an extent.
   * 範囲の中心座標を取得します。(ol3 API)
   */
  zoom: 0,
  extent: newProjExtent || undefined
 });
 map.setView(newView);
 /** setView(view)
  * Set the view for this map.
  * map の view を設定します。(ol3 API)
  */
  // Example how to prevent double occurence of 
  // map by limiting layer extent
  // レイヤの範囲を制限することで、マップの二重の発生を防止
  // する方法の例。
 if (newProj == ol.proj.get('EPSG:3857')) {
  layers['bng'].setExtent([-1057216, 6405988, 404315, 8759696]);
 } else {
  layers['bng'].setExtent(undefined);
 }
}
/**
 * @param {Event} e Change event.
 */
/** 「@param」
 * The @param tag provides the name, type, and 
 * description of a function parameter.
 * The @param tag requires you to specify the name of 
 * the parameter you are documenting. You can also 
 * include the parameter's type, enclosed in curly 
 * brackets, and a description of the parameter.
 * @paramタグは、関数パラメータの名前と型、説明を提供します。
 * @paramタグを使用すると、文書化されたパラメータの名前を
 * 指定する必要があります。また、パラメータのタイプと、中括
 * 弧で囲まれたおよびパラメータの説明を含めることができます。
 * (@use JSDoc [http://usejsdoc.org/tags-param.html])
 */
viewProjSelect.onchange = function(e) {
/** GlobalEventHandlers.onchange()
 * The onchange property sets and returns the event handler 
 * for the change event.
 * onchange プロパティは、change イベントに対してイベントハ
 * ンドラを設定、および、返します。
 * (MDN[https://developer.mozilla.org/en-US/docs/Web/
 * API/GlobalEventHandlers/onchange])
 */
 updateViewProjection();
};

updateViewProjection();

var updateRenderEdgesOnLayer = function(layer) {
 if (layer instanceof ol.layer.Tile) {
 /** instanceof
  * instanceof 演算子は、オブジェクトが自身のプロトタイプに
  * コンストラクタの prototype プロパティを持っているかを確
  * 認します。
  * (MDN[https://developer.mozilla.org/ja/docs/
  * JavaScript/Reference/Operators/instanceof])
  */
  var source = layer.getSource();
  /** getSource()
   * Return the associated tilesource of the the layer.
   * タイルレイヤの関連するタイルソースを返します。(ol3 API)
   */
  if (source instanceof ol.source.TileImage) {
  /** ol.source.TileImage 
   * Base class for sources providing images divided into 
   * a tile grid.
   * タイルグリッドに分割された画像を提供するソースの基本ク
   * ラス。(ol3 API)
   */
   source.setRenderReprojectionEdges(renderEdges);
   /** setRenderReprojectionEdges(render)
    * Sets whether to render reprojection edges or not 
    * (usually for debugging).
    * 再投影エッジをレンダリングするかしないか(通常はデバッ
    * グ用)を設定します。
   * (ol3 API[説明は Stable Only のチェックを外すと表示])
    */
  }
 }
};
/**
 * @param {Event} e Change event.
 */
baseLayerSelect.onchange = function(e) {
 var layer = layers[baseLayerSelect.value];
 if (layer) {
  layer.setOpacity(1);
  /** setOpacity(opacity)
   * Set the opacity of the layer, allowed values range 
   * from 0 to 1.
   * レイヤの不透明度を設定します。許可される値は0から1まで
   * の範囲。(ol3 API)
   */
  updateRenderEdgesOnLayer(layer);
  map.getLayers().setAt(0, layer);
  /** getLayers()
   * Get the collection of layers associated with this 
   * map.
   * このマップと関連するレイヤのコレクションを取得します。
   * (ol3 API)
   */
  /** setAt(index, elem)
   * Set the element at the provided index
   * 提供されたインデックス位置にあるエレメントを設定します
   * (ol3 API)
   */
 }
};
/**
 * @param {Event} e Change event.
 */
overlayLayerSelect.onchange = function(e) {
 var layer = layers[overlayLayerSelect.value];
 if (layer) {
  layer.setOpacity(0.7);
  updateRenderEdgesOnLayer(layer);
  map.getLayers().setAt(1, layer);
 }
};
/**
 * @param {Event} e Change event.
 */
renderEdgesCheckbox.onchange = function(e) {
  renderEdges = renderEdgesCheckbox.checked;
  map.getLayers().forEach(function(layer) {
  /** forEach(f, opt_this)
   * Iterate over each element, calling the provided 
   * callback.
   * 提供されるコールバックを呼び出して、各エレメントを反復
   * 処理します。(ol3 API)
   */
  updateRenderEdgesOnLayer(layer);
 });
};

2 - ol3.11ex 139a - Raster reprojection example 1

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

This example shows client-side raster reprojection between various projections.この例では、様々な投影法間のクライアント側のラスタ(ソース)の再投影を示しています。

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





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





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




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








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











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

「2139-ol3ex.html」
<!doctype html>
<html lang="en">
 <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="chrome=1">
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  <link rel="stylesheet" href="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.5/css/bootstrap-combined.min.css" type="text/css">
  <!--
  <link rel="stylesheet" href="../css/ol.css" type="text/css">
  <link rel="stylesheet" href="./resources/layout.css" type="text/css">

  <link rel="stylesheet" href="./resources/prism/prism.css" type="text/css">
  <script src="./resources/zeroclipboard/ZeroClipboard.min.js"></script>
  「resources」の位置が変わりました。
  -->
  <!-- ディレクトリ修正 -->
  <link rel="stylesheet" href="v3.11.2/css/ol.css" type="text/css">
  <link rel="stylesheet" href="v3.11.2/examples/resources/layout.css" type="text/css">

  <link rel="stylesheet" href="v3.11.2/examples/resources/prism/prism.css" type="text/css">
  <script src="v3.11.2/examples/resources/zeroclipboard/ZeroClipboard.min.js"></script>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.6/proj4.js">&lt/script>
  <title>Raster reprojection example</title>
 </head>
 <body>
  <!-- 
  bootstrap-combined.min.css, ol.css, layout.css,
  CSSファイルで設定されたセレクタを使用。
  -->
  <header class="navbar" role="navigation">
   <div class="container" id="navbar-inner-container">
    <!--
    <a class="navbar-brand" href="./"><img src="./resources/logo-70x70.png"> OpenLayers 3 Examples</a>
    -->
    <!-- ディレクトリ修正 -->
    <a class="navbar-brand" href="v3.11.2/examples/"><img src="v3.11.2/examples/resources/logo-70x70.png"> OpenLayers 3 Examples</a>
   </div>
  </header>
  <div class="container-fluid">
   <div class="row-fluid">
    <div class="span12">
     <div id="map" class="map"></div>
    </div>
    <form class="form-inline">
     <div class="col-md-3">
      <label>Base map:</label>
      <select id="base-layer">
       <option value="mapquest">MapQuest (EPSG:3857)</option>
       <option value="wms4326">WMS (EPSG:4326)</option>
      </select>
     </div>
     <div class="col-md-4">
      <label>Overlay map:</label>
      <select id="overlay-layer">
       <option value="bng">British National Grid (EPSG:27700)</option>
       <option value="wms21781">Swisstopo WMS (EPSG:21781)</option>
       <option value="wmts3413">NASA Arctic WMTS (EPSG:3413)</option>
       <option value="grandcanyon">Grand Canyon HiDPI (EPSG:3857)</option>
       <option value="states">United States (EPSG:3857)</option>
      </select>
     </div>
     <div class="col-md-5">
      <label>View projection:</label>
      <select id="view-projection">
       <option value="EPSG:3857">Spherical Mercator (EPSG:3857)</option>
       <option value="EPSG:4326">WGS 84 (EPSG:4326)</option>
       <option value="ESRI:54009">Mollweide (ESRI:54009)</option>
       <option value="EPSG:27700">British National Grid (EPSG:27700)</option>
       <option value="EPSG:23032">ED50 / UTM zone 32N (EPSG:23032)</option>
       <option value="EPSG:2163">US National Atlas Equal Area (EPSG:2163)</option>
       <option value="EPSG:3413">NSIDC Polar Stereographic North (EPSG:3413)</option>
       <option value="EPSG:5479">RSRGD2000 / MSLC2000 (EPSG:5479)</option>
      </select>
     </div>
     <label for="render-edges"><input type="checkbox" id="render-edges" />
      Render reprojection edges</label> (only displayed on reprojected data)
    </form>
   </div>
   <div class="row-fluid">
    <div class="span12">
     <h4 id="title">Raster reprojection example</h4>
     <p id="shortdesc">Demonstrates client-side raster 
      reprojection between various projections.</p>
     <div id="docs"><p>This example shows client-side 
      raster reprojection between various projections. </p>
     </div>
     <div id="tags">reprojection, projection, proj4js, 
      mapquest, wms, wmts, hidpi</div>
     <div id="api-links">Related API documentation: 
      <ul class="inline">
       <li>
      <!-- <a href="../apidoc/ol.Attribution.html" title="API documentation for ol.Attribution">ol.Attribution</a> -->
       <a href="v3.11.2/apidoc/ol.Attribution.html" title="API documentation for ol.Attribution">ol.Attribution</a>
       </li>,
      <li>
       <!-- <a href="../apidoc/ol.Map.html" title="API documentation for ol.Map">ol.Map</a> -->
       <a href="v3.11.2/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> -->
        <a href="v3.11.2/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> -->
        <a href="v3.11.2/apidoc/ol.extent.html" title="API documentation for ol.extent">ol.extent</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.format.WMTSCapabilities.html" title="API documentation for ol.format.WMTSCapabilities">ol.format.WMTSCapabilities</a> -->
        <a href="v3.11.2/apidoc/ol.format.WMTSCapabilities.html" title="API documentation for ol.format.WMTSCapabilities">ol.format.WMTSCapabilities</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.layer.Tile.html" title="API documentation for ol.layer.Tile">ol.layer.Tile</a> -->
        <a href="v3.11.2/apidoc/ol.layer.Tile.html" title="API documentation for ol.layer.Tile">ol.layer.Tile</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.proj.html" title="API documentation for ol.proj">ol.proj</a> -->
        <a href="v3.11.2/apidoc/ol.proj.html" title="API documentation for ol.proj">ol.proj</a>
       </li>,
      <li>
        <!-- <a href="../apidoc/ol.source.MapQuest.html" title="API documentation for ol.source.MapQuest">ol.source.MapQuest</a> -->
        <a href="v3.11.2/apidoc/ol.source.MapQuest.html" title="API documentation for ol.source.MapQuest">ol.source.MapQuest</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.source.TileImage.html" title="API documentation for ol.source.TileImage">ol.source.TileImage</a> -->
        <a href="v3.11.2/apidoc/ol.source.TileImage.html" title="API documentation for ol.source.TileImage">ol.source.TileImage</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.source.TileWMS.html" title="API documentation for ol.source.TileWMS">ol.source.TileWMS</a> -->
        <a href="v3.11.2/apidoc/ol.source.TileWMS.html" title="API documentation for ol.source.TileWMS">ol.source.TileWMS</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.source.WMTS.html" title="API documentation for ol.source.WMTS">ol.source.WMTS</a> -->
        <a href="v3.11.2/apidoc/ol.source.WMTS.html" title="API documentation for ol.source.WMTS">ol.source.WMTS</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.source.XYZ.html" title="API documentation for ol.source.XYZ">ol.source.XYZ</a> -->
        <a href="v3.11.2/apidoc/ol.source.XYZ.html" title="API documentation for ol.source.XYZ">ol.source.XYZ</a>
       </li>,
        <li>
        <!-- <a href="../apidoc/ol.tilegrid.TileGrid.html" title="API documentation for ol.tilegrid.TileGrid">ol.tilegrid.TileGrid</a> -->
        <a href="v3.11.2/apidoc/ol.tilegrid.TileGrid.html" title="API documentation for ol.tilegrid.TileGrid">ol.tilegrid.TileGrid</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="jsfiddle-button">
      <i class="fa fa-jsfiddle"></i> Edit
     </a>
    </div>
    <form method="POST" id="jsfiddle-form" target="_blank" action="http://jsfiddle.net/api/post/jquery/1.11.0/">
    <textarea class="hidden" name="js">
// --- 省略 ---
&lt;/html&gt;</code></pre>
   </div>
  </div>
  <script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <!--
  <script src="./resources/common.js"></script>
  <script src="./resources/prism/prism.min.js"></script>
  -->
  <!-- ディレクトリ修正
   CommonJS と
   prism.js
 -->
  <script src="v3.11.2/examples/resources/common.js"></script>
  <script src="v3.11.2/examples/resources/prism/prism.min.js"></script>
  <!-- 
  <script src="loader.js?id=reprojection"></script>
  -->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=2139-ol3ex"></script>
  </body>
</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 8 では動作しませんでした。ボタンを右クリックしたときに flash のコンテキストメニューが表示されると動作しています。

2015年10月18日日曜日

OL3-Cesium 6 - ol3cesium raster layer synchronization example 2

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

OL3-Cesium API は、現在、すべて実験的(experimental)なものです。

「6-ol3cesium18.js」
var view = new ol.View({
 center: ol.proj.transform([-112.2, 36.06], 'EPSG:4326', 'EPSG:3857'),
 /** ol.proj.transform(coordinate, source, destination)
  * Transforms a coordinate from source projection to 
  * destination projection. This returns a new coordinate 
  * (and does not modify the original).
  * ソース投影から変換先投影に座標変換します。これは、新しい座標
  * を返します(オリジナルを変更しません)。(ol3 API)
  */
 zoom: 11
});
var layer0 = new ol.layer.Tile({
/** ol.layer.Tile 
 * For layer sources that provide pre-rendered, tiled 
 * images in grids that are organized by zoom levels for 
 * specific resolutions. 
 * プリレンダリング(事前描画)を提供するレイヤソースのための、
 * 特定の解像度でのズームレベルによって編成されているグリッドの
 * タイルイメージ。(ol3 API)
 */
 source: new ol.source.MapQuest({layer: 'sat'})
 /** ol.source.MapQuest
  * Layer source for the MapQuest tile server.
  * MapQuest タイルサーバのレイヤソース。(ol3 API
  * 2 - ol3ex 23b - MapQuest example 2 参照)
  */
});
var layer1 = new ol.layer.Tile({
 source: new ol.source.TileJSON({
 /** ol.source.TileJSON 
  * Layer source for tile data in TileJSON format.
  * TileJSON フォーマットのタイルデータのためのレイヤソース。
  *(ol3 API)
  */
  url: 'http://tileserver.maptiler.com/grandcanyon.json',
  crossOrigin: 'anonymous'
  /** crossOrigin
   * 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のレンダ
   * ラーを使用している場合、または、キャンバスレンダラでピ
   * クセルデータにアクセスする場合、crossOrigin 値を提供な
   * ければならないことに注意してください。詳細は 
   * https://developer.mozilla.org/en-US/docs/Web/HTML/
   * CORS_enabled_image を参照してください。(ol3 API)
   */
 })
});
var layer2 = new ol.layer.Tile({
 source: new ol.source.TileJSON({
  url: 'http://api.tiles.mapbox.com/v3/' +
   'mapbox.world-borders-light.jsonp',
  crossOrigin: 'anonymous'
 })
});
var ol2d = new ol.Map({
 layers: [layer0, new ol.layer.Group({layers: [layer1, layer2]})],
 /** ol.layer.Group
  * A ol.Collection of layers that are handled together.
  * A generic change event is triggered when the 
  * group/Collection changes.
  * 同時に扱うレイヤの ol.Collection。グループ/コレクション
  * が変更されるとき、一般的な変更イベントがトリガされます。
  * (ol3 API)
  */
 target: 'map2d',
 view: view,
 renderer: 'webgl'
});
var ol3d = new olcs.OLCesium({map: ol2d, target: 'map3d'});
/** new olcs.OLCesium(options)
 * map: The OpenLayers map we want to show on a Cesium scene.
 * Cesium シーンで表示したい OpenLayers マップ。
 * (OL3-Cesium API)
 */
var scene = ol3d.getCesiumScene();
/** getCesiumScene()
 * (OL3-Cesium API に説明がありませんでした。)
 */
var terrainProvider = new Cesium.CesiumTerrainProvider({
/** new CesiumTerrainProvider(options)
 * A TerrainProvider that access terrain data in a Cesium 
 * terrain format. The format is described on the Cesium 
 * wiki. 
 * セシウム地形(Cesium terrain)フォーマットの地形(terrain)
 * データにアクセスする TerrainProvider。フォーマットは、セシウ
 * ムウィキに記載されています。
 * (Cesium refdoc)
 */
 // url : '//cesiumjs.org/stk-terrain/tilesets/world/tiles'
 // 2015.10.2 変更
 url : '//assets.agi.com/stk-terrain/world'
 /** url
  * The URL of the Cesium terrain server.
  * セシウム地形(Cesium terrain)サーバの URL。
  * (Cesium refdoc)
  */
});
scene.terrainProvider = terrainProvider;
ol3d.setEnabled(true);

var addBingMaps = function() {
 ol2d.addLayer(new ol.layer.Tile({
 /** addLayer(layer)
  * Adds the given layer to the top of this map. If you 
  * want to add a layer elsewhere in the stack, use 
  * getLayers() and the methods available on ol.Collection.
  * 与えられたレイヤをこのマップの一番上に追加します。あなたは、
  * スタックの他の箇所にレイヤを追加したい場合は、getLayers()と
  * ol.Collection で使用可能なメソッドを使用します。(ol3 API)
  */
  source: new ol.source.BingMaps({
  /** ol.source.BingMaps
   * Layer source for Bing Maps tile data.
   * Bing Maps タイルデータのレイヤソース。(ol3 API)
   */
   key: 'Ak-dzM...(省略)',
   imagerySet: 'Aerial'
  })
 }));
};

var addOSM = function() {
 ol2d.addLayer(new ol.layer.Tile({
  opacity: 0.7,
  source: new ol.source.OSM()
  /** ol.source.OSM 
   * Layer source for the OpenStreetMap tile server.
   * OpenStreetMap タイルサーバのレイヤソース。(ol3 API)
   */
 }));
};

var addStamen = function() {
 ol2d.addLayer(new ol.layer.Tile({
  source: new ol.source.Stamen({
  /** ol.source.Stamen
   * Layer source for the Stamen tile server.
   * Stamen タイルサーバのレイヤソース。(ol3 API)
   * (2 - ol3ex 24b - Stamen example 1 参照)
   */
   opacity: 0.7,
   layer: 'watercolor'
  })
 }));
};
var tileWMSSource = new ol.source.TileWMS({
/** ol.source.TileWMS
 * Layer source for tile data from WMS servers.
 * WMS サーバからのタイルデータのレイヤソース。
 * (ol3 API)
 */
 url: 'http://demo.boundlessgeo.com/geoserver/wms',
 params: {'LAYERS': 'topp:states', 'TILED': true},
 serverType: 'geoserver',
 crossOrigin: 'anonymous'
});

var addTileWMS = function() {
 ol2d.addLayer(new ol.layer.Tile({
  opacity: 0.5,
  extent: [-13884991, 2870341, -7455066, 6338219],
  source: tileWMSSource
 }));
};

var changeI = 0;
var changeTileWMSParams = function() {
 tileWMSSource.updateParams({
 /** updateParams(params)
  * Update the user-provided params.
  * ユーザ提供パラメータを更新します。(ol3 API)
  */
  'LAYERS': (changeI++) % 2 == 0 ? 'nurc:Img_Sample' : 'topp:states'
   /** 条件演算子 condition ? expr1 : expr2 
    * condition: true か false かを評価する条件文です。
    * expr1, expr2: 各々の値の場合に実行する式です。
    * condition が true の場合、演算子は expr1 の値を選択します。
    * そうでない場合は expr2 の値を選択します。
    * (MDN[https://developer.mozilla.org/ja/docs/Web/
    * JavaScript/Guide/Expressions_and_Operators])
    */
 });
};

var addTileJSON = function() {
 ol2d.addLayer(layer2);
};
Chromium では表示できないので、Iceweasel(Firefox)のアドレスバーに

http://localhost/~user/ol3cesiumproj/public_html/6-ol3cesium18.html

と入力して表示します。

OL3-Cesium 6 - ol3cesium raster layer synchronization example 1

OL3-Cesium Examples
http://openlayers.org/ol3-cesium/examples/

の例をみていきます。

6 - ol3cesium raster layer synchronization example
「ol3cesium raster layer synchronization example (rastersync.html)」を参考に地図を表示してみます。
3-1 HTML ファイルの作成
1 NetBeans を起動します。









2 「プロジェクト」ペインでツリーを ol3cesiumproj -> サイト・ルート -> js -> libs -> ol3-cesium-v1.8 -> examples とクリックして展開し rastersync.html をダブルクリックして開きます。rastersync.js もダブルクリックして開きます。



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

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






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







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









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

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



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


「6-ol3cesium18.html」
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="robots" content="index, all" />
  <title>ol3cesium raster layer synchronization example</title>
  <!-- ディレクトリ修正
  <link rel="stylesheet" href="../ol3/css/ol.css" type="text/css">
  -->
  <link rel="stylesheet" href="./js/libs/ol3-cesium-v1.8/ol3/css/ol.css" type="text/css">
  <style>
   fieldset {display:inline-block;float:left;}
   label {display:block;}
   body.hideLayerInputs fieldset {display:none;}
  </style>
 </head>
 <body>
  <div id="map2d" style="width:600px;height:400px;float:left;"></div>
  <div id="map3d" style="width:600px;height:400px;float:left;position:relative;"></div>
  <input type="button" value="Remove all layers" onclick="ol2d.getLayers().clear();document.body.className='hideLayerInputs';" />
  <input type="button" value="Add Bing Maps" onclick="addBingMaps();" />
  <input type="button" value="Add OSM" onclick="addOSM();" />
  <input type="button" value="Add Stamen" onclick="addStamen();" />
  <input type="button" value="Add TileWMS" onclick="addTileWMS();" />
  <input type="button" value="Add TileJSON" onclick="addTileJSON();" />
  <br /><br />
  <input type="button" value="TileWMS change" onclick="changeTileWMSParams();" />
  <fieldset id="layer0">
   <label class="checkbox" for="visible0">
    <input id="visible0" class="visible" type="checkbox" onchange="layer0.setVisible(this.checked)" checked/>OpenAerial layer
   </label>
   <label>opacity</label>
   <input class="opacity" type="range" min="0" max="1" step="0.01" value="1" oninput="layer0.setOpacity(this.value)"/>
   <label>saturation</label>
   <input class="saturation" type="range" min="0" max="5" step="0.01" oninput="layer0.setSaturation(this.value)"/>
   <label>contrast</label>
   <input class="contrast" type="range" min="0" max="2" step="0.01" oninput="layer0.setContrast(this.value)"/>
   <label>brightness</label>
   <input class="brightness" type="range" min="-1" max="1" step="0.01" oninput="layer0.setBrightness(this.value)"/>
  </fieldset>
  <fieldset id="layer1">
   <label class="checkbox" for="visible10">
    <input id="visible1" class="visible" type="checkbox" onchange="layer1.setVisible(this.checked)" checked/>Grand Canyon overlay
   </label>
   <label>opacity</label>
   <input class="opacity" type="range" min="0" max="1" step="0.01" value="1" oninput="layer1.setOpacity(this.value)"/>
   <label>saturation</label>
   <input class="saturation" type="range" min="0" max="5" step="0.01" oninput="layer1.setSaturation(this.value)"/>
   <label>contrast</label>
   <input class="contrast" type="range" min="0" max="2" step="0.01" oninput="layer1.setContrast(this.value)"/>
   <label>brightness</label>
   <input class="brightness" type="range" min="-1" max="1" step="0.01" oninput="layer1.setBrightness(this.value)"/>
  </fieldset>
  <fieldset id="layer2">
   <label class="checkbox" for="visible10">
    <input id="visible1" class="visible" type="checkbox" onchange="layer2.setVisible(this.checked)" checked/>World borders
   </label>
   <label>opacity</label>
   <input class="opacity" type="range" min="0" max="1" step="0.01" value="1" oninput="layer2.setOpacity(this.value)"/>
   <label>saturation</label>
   <input class="saturation" type="range" min="0" max="5" step="0.01" oninput="layer2.setSaturation(this.value)"/>
   <label>contrast</label>
   <input class="contrast" type="range" min="0" max="2" step="0.01" oninput="layer2.setContrast(this.value)"/>
   <label>brightness</label>
   <input class="brightness" type="range" min="-1" max="1" step="0.01" oninput="layer2.setBrightness(this.value)"/>
  </fieldset>
  <!-- ディレクトリ修正
  <script src="../ol3/ol-debug.js"></script>
  <script src="../Cesium/Cesium.js"></script>
  <script src="../ol3cesium.js"></script>
  -->
  <script src="./js/libs/ol3-cesium-v1.8/ol3/ol-debug.js"></script>
  <script src="./js/libs/ol3-cesium-v1.8/Cesium/Cesium.js"></script>
  <script src="./js/libs/ol3-cesium-v1.8/ol3cesium.js"></script>
  <!-- <script src="rastersync.js"></script> -->
  <script src="6-ol3cesium18.js"></script>
 </body>
</html>

2015年8月25日火曜日

2 - ol3.8ex 126b - Region Growing 2

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

「2126-ol3ex.js」
function growRegion(inputs, data) {
 var image = inputs[0];
 var seed = data.pixel;
 var delta = parseInt(data.delta);
 /** parseInt(string, radix)
  * str: 文字列, radix: 基数(進法)
  * 文字列の引数をパースし、指定された基数の整数を返します。
  * (MDN[https://developer.mozilla.org/ja/docs/Web/
  * JavaScript/Reference/Global_Objects/parseInt])
  */
 if (!seed) {
  return image;
 }
 seed = seed.map(Math.round);
 /** Math.round()
  * 引数として与えた数を四捨五入して、最も近似の整数を返します。
  * (MDN[https://developer.mozilla.org/ja/docs/Web/
  * JavaScript/Reference/Global_Objects/Math/round])
  */
 var width = image.width;
 var height = image.height;
 var inputData = image.data;
 var outputData = new Uint8ClampedArray(inputData);
 /** Uint8ClampedArray
  * The Uint8ClampedArray typed array represents an 
  * array of 8-bit unsigned integers clamped to 0-255. 
  * The contents are initialized to 0. Once established, 
  * you can reference elements in the array using the 
  * object's methods, or using standard array index 
  * syntax (that is, using bracket notation).
  * Uint8ClampedArray に分類された配列は、0〜255に固定された
  * 8 ビット符号なし整数の配列を表します。コンテンツは、0に初期
  * 化されます。一度確立されると、オブジェクトメソッドを使用し
  * て、または、標準配列インデックス構文を使用(つまり、ブラケッ
  * ト表記を使用)して、配列内の要素を参照することができます。
  * (MDN[https://developer.mozilla.org/ja/docs/Web/
  * JavaScript/Reference/Global_Objects/Uint8ClampedArray])
  */
 var seedIdx = (seed[1] * width + seed[0]) * 4;
 var seedR = inputData[seedIdx];
 var seedG = inputData[seedIdx + 1];
 var seedB = inputData[seedIdx + 2];
 var edge = [seed];
 while (edge.length) {
  var newedge = [];
  for (var i = 0, ii = edge.length; i < ii; i++) {
 /** As noted in the Raster source constructor, this 
  * function is provided using the `lib` option. Other 
  * functions will NOT be visible unless provided using 
  * the `lib` option.
  * ラスターソースのコンストラクタで述べたように、この関数は 
  * `lib` オプションを使用して提供されます。 他の関数は、`lib` 
  * オプションを使用して提供しない限り、表示されません。
  */
   var next = nextEdges(edge[i]);
   for (var j = 0, jj = next.length; j < jj; j++) {
    var s = next[j][0], t = next[j][1];
    if (s >= 0 && s < width && t >= 0 && t < height) {
     var ci = (t * width + s) * 4;
     var cr = inputData[ci];
     var cg = inputData[ci + 1];
     var cb = inputData[ci + 2];
     var ca = inputData[ci + 3];
     // if alpha is zero, carry on
     if (ca === 0) {
      continue;
     }
     if (Math.abs(seedR - cr) < delta && Math.abs(seedG - cg)
      < delta && Math.abs(seedB - cb) < delta) {
  /** Math.abs()
   * 引数として与えた数の絶対値を返します。
   * (MDN[https://developer.mozilla.org/ja/docs/Web/
   * JavaScript/Reference/Global_Objects/Math/abs])
   */
       outputData[ci] = 255;
       outputData[ci + 1] = 0;
       outputData[ci + 2] = 0;
       outputData[ci + 3] = 255;
       newedge.push([s, t]);
     }
     // mark as visited
     inputData[ci + 3] = 0;
    }
   }
  }
  edge = newedge;
 }
 return new ImageData(outputData, width, height);
}
function next4Edges(edge) {
 var x = edge[0], y = edge[1];
 return [
  [x + 1, y],
  [x - 1, y],
  [x, y + 1],
  [x, y - 1]
 ];
}
var key = 'Ak-dzM...(省略)';
var imagery = new ol.layer.Tile({
/** ol.layer.Tile 
 * For layer sources that provide pre-rendered, tiled 
 * images in grids that are organized by zoom levels for 
 * specific resolutions. 
 * プリレンダリング(事前描画)を提供するレイヤソースのための、
 * 特定の解像度でのズームレベルによって編成されているグリッドの
 * タイルイメージ。(ol3 API)
 */
 source: new ol.source.BingMaps({key: key, imagerySet: 'Aerial'})
 /** ol.source.BingMaps
  * Layer source for Bing Maps tile data.
  * Bing Maps タイルデータのレイヤソース。(ol3 API)
  */
});
var raster = new ol.source.Raster({
/** ol.source.Raster
 * A source that transforms data from any number of input 
 * sources using an array of ol.raster.Operation functions 
 * to transform input pixel values into output pixel values.
 * 入力画素値を出力画素値に変換するために ol.raster.Operation
 * 関数の配列を使用して、任意の数の入力ソースからデータを変換す
 * るソース。
 * (ol3 API[説明は Stable Only のチェックを外すと表示])
 */
 sources: [imagery.getSource()],
 /** getSource()
  * Return the associated source of the image layer.
  * 画像レイヤの関連するソースを返します。(ol3 API)
  */
 operationType: 'image',
 operation: growRegion,
 /** operation
  * Raster operation. The operation will be called with data 
  * from input sources and the output will be assigned to the
  * raster source.
  * ラスタオペレーション。operation は入力ソースからデータととも
  * に呼び出され、出力データはラスタ·ソースに割り当てられます。
  * (ol3 API[説明は Stable Only のチェックを外すと表示])
  */
 // Functions in the `lib` object will be available to the 
 // operation run in the web worker.
 lib: {
 /** lib
  * Functions that will be made available to operations 
  * run in a worker.
  * ワーカで実行される operation が利用可能となる関数。
  * (ol3 API[説明は Stable Only のチェックを外すと表示])
  */
  nextEdges: next4Edges
 }
});
var rasterImage = new ol.layer.Image({
/** ol.layer.Image
 * Server-rendered images that are available for arbitrary 
 * extents and resolutions. 
 * 任意の範囲と解像度で利用可能な server-rendered イメージ。
 * (ol3 API)
 */
 opacity: 0.7,
 source: raster
});
var map = new ol.Map({
 layers: [imagery, rasterImage],
 target: 'map',
 view: new ol.View({
  center: ol.proj.fromLonLat([-119.07, 47.65]),
 /** ol.proj.fromLonLat(coordinate, opt_projection)
  * Transforms a coordinate from longitude/latitude to a 
  * different projection.
  * 緯度/経度座標から異なる投影に変換します。(ol3 API)
  */
  zoom: 11
 })
});
var coordinate;
map.on('click', function(event) {
/** on(type, listener, opt_this)
 * Listen for a certain type of event.
 * あるタイプのイベントをリッスンします。(ol3 API)
 */
 coordinate = event.coordinate;
 raster.changed();
 /** changed()
  * Increases the revision counter and dispatches a 'change' 
  * event.
  * リビジョンカウンタを増加し、「change」イベントを送出します。
  * (ol3 API[説明は Stable Only のチェックを外すと表示])
  */
});
raster.on('beforeoperations', function(event) {
/** on(type, listener, opt_this)
 * Listen for a certain type of event.
 * あるタイプのイベントをリッスンします。(ol3 API)
 */
 // the event.data object will be passed to operations
 var data = event.data;
 data.delta = thresholdControl.value;
 if (coordinate) {
  data.pixel = map.getPixelFromCoordinate(coordinate);
 /** getPixelFromCoordinate(coordinate)
  * Get the pixel for a coordinate. This takes a coordinate 
  * in the map view projection and returns the 
  * corresponding pixel.
  * 座標のピクセルを取得します。これは、マップビューの投影で座標
  * を取得し、対応するピクセルを返します。(ol3 API)
  */
 }
});
var thresholdControl = document.getElementById('threshold');
function updateControlValue() {
 document.getElementById('threshold-value').innerText = thresholdControl.value;
}
updateControlValue();
thresholdControl.addEventListener('input', function() {
/** EventTarget.addEventListener
 * addEventListener は、 1 つのイベントターゲットにイベント 
 * リスナーを1 つ登録します。イベントターゲットは、ドキュメント
 * 上の単一のノード、ドキュメント自身、ウィンドウ、あるいは、
 * XMLHttpRequest です。
 *(MDN[https://developer.mozilla.org/ja/docs/Web/API/
 * EventTarget.addEventListener])
 */
 updateControlValue();
 raster.changed();
  /** changed()
   * Increases the revision counter and dispatches a 0
   * 'change' event.
   * リビジョンカウンタを増加し、「change」イベントを送出します。
   * (ol3 API[説明は Stable Only のチェックを外すと表示])
   */
});

2 - ol3.8ex 126a - Region Growing 1

「Region Growing (region-growing.html)」を参考に地図を表示してみます。
説明に次のようにあります。

Click a region on the map. The computed region will be red.
地図上の領域をクリックします。計算された領域は赤になります。

This example uses a ol.source.Raster to generate data based on another source. The raster source accepts any number of input sources (tile or image based) and runs a pipeline of operations on the input data. The return from the final operation is used as the data for the output source.
この例では、別のソースに基づいてデータを生成する ol.source.Raster を使用しています。ラスタソースは、任意の数の入力ソース(タイルまたは画像ベース)を受け取り、入力データに対する operation のパイプラインを実行します。最後の operation からのリターンは、出力ソースのデータとして使用されます。

In this case, a single tiled source of imagery data is used as input. The region is calculated in a single "image" operation using the "seed" pixel provided by the user clicking on the map. The "threshold" value determines whether a given contiguous pixel belongs to the "region" - the difference between a candidate pixel's RGB values and the seed values must be below the threshold.
この場合、画像データの単一のタイルソースは、入力として使用されます。領域は、マップ上のユーザのクリックにより提供される「種」の画素を使用して、単一の「画像」の operation で計算されます。「しきい」値は、与えられた連続したピクセルが「領域」に属しているかどうかを判定します。候補画素の RGB 値及びシード値の差がしきい値以下でなければならななりません。

This example also shows how an additional function can be made available to the operation.
この例では、追加関数を operation に利用可能にさせる方法も示しています。


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





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





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



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








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











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

「2126-ol3ex.html」
<!doctype html>
<html lang="en">
 <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="chrome=1">
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-combined.min.css" type="text/css">
  <link rel="stylesheet" href="region-growing.css">
  <!--
  <link rel="stylesheet" href="../css/ol.css" type="text/css">
  <link rel="stylesheet" href="./resources/layout.css" type="text/css">

  <link rel="stylesheet" href="./resources/prism/prism.css" type="text/css">
  <script src="./resources/zeroclipboard/ZeroClipboard.min.js"></script>
  「resources」の位置が変わりました。
  -->
  <!-- ディレクトリ修正 -->
  <link rel="stylesheet" href="v3.8.2/css/ol.css" type="text/css">
  <link rel="stylesheet" href="v3.8.2/examples/resources/layout.css" type="text/css">

  <link rel="stylesheet" href="v3.8.2/examples/resources/prism/prism.css" type="text/css">
  <script src="v3.8.2/examples/resources/zeroclipboard/ZeroClipboard.min.js"></script>
  <title>Region Growing</title>
 </head>
 <body>
  <!-- 
  bootstrap-combined.min.css, ol.css, layout.css,
  CSSファイルで設定されたセレクタを使用。
  -->
  <header class="navbar" role="navigation">
   <div class="container" id="navbar-inner-container">
    <!--
    <a class="navbar-brand" href="./"><img src="./resources/logo-70x70.png"> OpenLayers 3 Examples</a>
    -->
    <!-- ディレクトリ修正 -->
    <a class="navbar-brand" href="v3.8.2/examples/"><img src="v3.8.2/examples/resources/logo-70x70.png"> OpenLayers 3 Examples</a>
   </div>
  </header>
  <div class="container-fluid">
   <div class="row-fluid">
    <div class="span12">
     <div id="map" class="map" style="cursor: pointer"></div>
     <table class="controls">
      <tr>
       <td>Threshold: <span id="threshold-value"></span></td>
       <td><input id="threshold" type="range" min="1" max="50" value="20"></td>
      </tr>
     </table>
    </div>
   </div>
   <div class="row-fluid">
    <div class="span12">
     <h4 id="title">Region Growing</h4>
     <p id="shortdesc">Grow a region from a seed pixel</p>
     <div id="docs">
     <p>
     Click a region on the map. The computed region will 
     be red.</p> <p>
     This example uses a <code>ol.source.Raster</code> 
     to generate data based on another source. The raster 
     source accepts any number of input sources (tile or 
     image based) and runs a pipeline of operations on 
     the input data. The return from the final operation 
     is used as the data for the output source.</p> <p>
     In this case, a single tiled source of imagery data 
     is used as input. The region is calculated in a 
     single "image" operation using the  
     "seed" pixel provided by the user clicking on 
     the map. The "threshold" value determines 
     whether a given contiguous pixel belongs to the 
     "region" - the difference between a candidate 
     pixel's RGB values and the seed values must
     be below the threshold.</p> <p>
     This example also shows how an additional function 
     can be made available to the operation.</p>
     <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> -->
        <a href="v3.8.2/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> -->
        <a href="v3.8.2/apidoc/ol.View.html" title="API documentation for ol.View">ol.View</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.layer.Image.html" title="API documentation for ol.layer.Image">ol.layer.Image>/a> -->
        <a href="v3.8.2/apidoc/ol.layer.Image.html" title="API documentation for ol.layer.Image">ol.layer.Image</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.layer.Tile.html" title="API documentation for ol.layer.Tile">ol.layer.Tile>/a> -->
        <a href="v3.8.2/apidoc/ol.layer.Tile.html" title="API documentation for ol.layer.Tile">ol.layer.Tile</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.proj.html" title="API documentation for ol.proj">ol.proj>/a> -->
        <a href="v3.8.2/apidoc/ol.proj.html" title="API documentation for ol.proj">ol.proj</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.source.BingMaps.html" title="API documentation for ol.source.BingMaps">ol.source.BingMaps>/a> -->
        <a href="v3.8.2/apidoc/ol.source.BingMaps.html" title="API documentation for ol.source.BingMaps">ol.source.BingMaps</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.source.Raster.html" title="API documentation for ol.source.Raster">ol.source.Raster>/a> -->
        <a href="v3.8.2/apidoc/ol.source.Raster.html" title="API documentation for ol.source.Raster">ol.source.Raster</a>
       </li>
      </ui>
     </div>
   </div>
  </div>
  <div class="row-fluid">
   <hr>
   <form method="POST" target="_blank" action="http://jsfiddle.net/api/post/jquery/1.11.0/">
    <input type="button" class="btn btn-info" id="copy-button" value="Copy example code">
    <input type="submit" class="btn btn-primary" id="jsfiddle-button" value="Create JSFiddle">
    <textarea class="hidden" name="js">
// --- 省略 ---
&lt;/html&gt;</code></pre>
    </div>
   </div>
  </div>
  <script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <!--
  <script src="./resources/common.js"></script>
  <script src="./resources/prism/prism.min.js"></script>
  -->
  <!-- ディレクトリ修正
   CommonJS と
   prism.js
 -->
  <script src="v3.8.2/examples/resources/common.js"></script>
  <script src="v3.8.2/examples/resources/prism/prism.min.js"></script>
  <!-- 
  <script src="loader.js?id=region-growing"></script>
  -->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=2126-ol3ex"></script>
  </body>
</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 8 では動作しませんでした。ボタンを右クリックしたときに flash のコンテキストメニューが表示されると動作しています。