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

2015年8月25日火曜日

2 - ol3.8ex 127b - Shaded Relief 2

「shaded-relief.js(2127-ol3ex.js)」は、マップを表示するための JavaScript ファイルです。
「2127-ol3ex.js」
/**
 * Generates a shaded relief image given elevation data.  
 * Uses a 3x3 neighborhood for determining slope and aspect.
 * 標高データを与えられた陰影起伏画像を生成します。
 * 傾斜角と傾斜を決定するために3×3の近傍を使用します。
 * @param {Array.} inputs Array of input images.
 * @param {Object} data Data added in the "beforeoperations" event.
 * @return {Array.} Output images (only the first is rendered).
 */
function shade(inputs, data) {
 var elevationImage = inputs[0];
 var width = elevationImage.width;
 var height = elevationImage.height;
 var elevationData = elevationImage.data;
 var shadeData = new Uint8ClampedArray(elevationData.length);
 /** 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 dp = data.resolution * 2;
 var maxX = width - 1;
 var maxY = height - 1;
 var pixel = [0, 0, 0, 0];
 var twoPi = 2 * Math.PI;
 /** Math.PI()
  * 円周率。約 3.14159 です。
  * (MDN[https://developer.mozilla.org/ja/docs/Web
  * /JavaScript/Reference/Global_Objects/Math/PI])
  */
 var halfPi = Math.PI / 2;
 var sunEl = Math.PI * data.sunEl / 180;
 var sunAz = Math.PI * data.sunAz / 180;
 var cosSunEl = Math.cos(sunEl);
 /** Math.cos()
  * 引数として与えた数のコサインを返します。
  * (MDN[https://developer.mozilla.org/ja/docs/Web/
  * JavaScript/Reference/Global_Objects/Math/cos])
  */
 var sinSunEl = Math.sin(sunEl);
 /** Math.sin()
  * 引数として与えた数のサイン(正弦)を返します。
  * (MDN[https://developer.mozilla.org/ja/docs/Web/
  * JavaScript/Reference/Global_Objects/Math/sin])
  */
 var pixelX, pixelY, x0, x1, y0, y1, offset,
  z0, z1, dzdx, dzdy, slope, aspect, cosIncidence, scaled;
 for (pixelY = 0; pixelY <= maxY; ++pixelY) {
  y0 = pixelY === 0 ? 0 : pixelY - 1;
  y1 = pixelY === maxY ? maxY : pixelY + 1;
  for (pixelX = 0; pixelX <= maxX; ++pixelX) {
   x0 = pixelX === 0 ? 0 : pixelX - 1;
   x1 = pixelX === maxX ? maxX : pixelX + 1;
   // determine elevation for (x0, pixelY)
   // (x0, pixelY)に対する標高を決定します。
   offset = (pixelY * width + x0) * 4;
   pixel[0] = elevationData[offset];
   pixel[1] = elevationData[offset + 1];
   pixel[2] = elevationData[offset + 2];
   pixel[3] = elevationData[offset + 3];
   z0 = data.vert * (pixel[0] + pixel[1] * 2 + pixel[2] * 3);
   // determine elevation for (x1, pixelY)
   // (x1, pixelY)に対する標高を決定します。
   offset = (pixelY * width + x1) * 4;
   pixel[0] = elevationData[offset];
   pixel[1] = elevationData[offset + 1];
   pixel[2] = elevationData[offset + 2];
   pixel[3] = elevationData[offset + 3];
   z1 = data.vert * (pixel[0] + pixel[1] * 2 + pixel[2] * 3);
   dzdx = (z1 - z0) / dp;
   // determine elevation for (pixelX, y0)
   // (pixelX, y0)に対する標高を決定します。
   offset = (y0 * width + pixelX) * 4;
   pixel[0] = elevationData[offset];
   pixel[1] = elevationData[offset + 1];
   pixel[2] = elevationData[offset + 2];
   pixel[3] = elevationData[offset + 3];
   z0 = data.vert * (pixel[0] + pixel[1] * 2 + pixel[2] * 3);
   // determine elevation for (pixelX, y1)
   // (pixelX, y1)に対する標高を決定します。
   offset = (y1 * width + pixelX) * 4;
   pixel[0] = elevationData[offset];
   pixel[1] = elevationData[offset + 1];
   pixel[2] = elevationData[offset + 2];
   pixel[3] = elevationData[offset + 3];
   z1 = data.vert * (pixel[0] + pixel[1] * 2 + pixel[2] * 3);
   dzdy = (z1 - z0) / dp;
   slope = Math.atan(Math.sqrt(dzdx * dzdx + dzdy * dzdy));
   /** Math.atan()
    * 引数として与えた数のアークタンジェントをラジアン単位で返
    * します。
    * (MDN[https://developer.mozilla.org/ja/docs/Web/
    * JavaScript/Reference/Global_Objects/Math/atan])
    */
   /** Math.sqrt()
    * 引数として与えた数の平方根を返します。
    * (MDN[https://developer.mozilla.org/ja/docs/Web/
    * JavaScript/Reference/Global_Objects/Math/sqrt])
    */
   aspect = Math.atan2(dzdy, -dzdx);
   /** Math.atan2()
    * 引数の比率でのアークタンジェントを返します。
    * (MDN[https://developer.mozilla.org/ja/docs/Web/
    * JavaScript/Reference/Global_Objects/Math/atan2])
    */
   if (aspect < 0) {
    aspect = halfPi - aspect;
   } else if (aspect > halfPi) {
    aspect = twoPi - aspect + halfPi;
   } else {
    aspect = halfPi - aspect;
   }
   cosIncidence = sinSunEl * Math.cos(slope) +
    cosSunEl * Math.sin(slope) * Math.cos(sunAz - aspect);
   offset = (pixelY * width + pixelX) * 4;
   scaled = 255 * cosIncidence;
   shadeData[offset] = scaled;
   shadeData[offset + 1] = scaled;
   shadeData[offset + 2] = scaled;
   shadeData[offset + 3] = elevationData[offset + 3];
  }
 }             
 return new ImageData(shadeData, width, height);
}
var elevation = new ol.source.XYZ({
/** ol.source.XYZ
 * Layer source for tile data with URLs in a set XYZ 
 * format.
 * セットXYZ形式のURLを持つタイルデータのレイヤソース。
 * (ol3 API)
 */
 url: 'https://{a-d}.tiles.mapbox.com/v3/aj.sf-dem/{z}/{x}/{y}.png',
 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 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: [elevation],
 operationType: 'image',
 operation: shade
 /** 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 のチェックを外すと表示])
  */
});
var map = new ol.Map({
 target: 'map',
 layers: [
  new ol.layer.Tile({
 /** ol.layer.Tile 
  * For layer sources that provide pre-rendered, tiled 
  * images in grids that are organized by zoom levels for 
  * specific resolutions. 
  * プリレンダリング(事前描画)を提供するレイヤソースのための、
  * 特定の解像度でのズームレベルによって編成されているグリッドの
  * タイルイメージ。(ol3 API)
  */
   source: new ol.source.TileJSON({
   /** ol.source.TileJSON 
    * Layer source for tile data in TileJSON format.
    * TileJSON フォーマットのタイルデータのためのレイヤソース。
    *(ol3 API)
    */
    url: 'http://api.tiles.mapbox.com/v3/tschaub.miapgppd.jsonp'
   })
  }),
  new ol.layer.Image({
 /** ol.layer.Image
  * Server-rendered images that are available for arbitrary 
  * extents and resolutions. 
  * 任意の範囲と解像度で利用可能な server-rendered イメージ。
  * (ol3 API)
  */
   opacity: 0.3,
   source: raster
  })
 ],
 view: new ol.View({
  extent: [-13675026, 4439648, -13580856, 4580292],
  center: [-13615645, 4497969],
  minZoom: 10,
  maxZoom: 16,
  zoom: 13
 })
});
var controlIds = ['vert', 'sunEl', 'sunAz'];
var controls = {};
controlIds.forEach(function(id) {
/** forEach(f, opt_this)
 * Iterate over each element, calling the provided 
 * callback.
 * 提供されたコールバックを呼び出すため、各要素を反復処理しま
 * す。(ol3 API)
 */
 var control = document.getElementById(id);
 var output = document.getElementById(id + 'Out');
 control.addEventListener('input', function() {
/** EventTarget.addEventListener
 * addEventListener は、 1 つのイベントターゲットにイベント 
 * リスナーを1 つ登録します。イベントターゲットは、ドキュメント
 * 上の単一のノード、ドキュメント自身、ウィンドウ、あるいは、
 * XMLHttpRequest です。
 *(MDN[https://developer.mozilla.org/ja/docs/Web/API/
 * EventTarget.addEventListener])
 */
  output.innerText = control.value;
  raster.changed();
  /** changed()
   * Increases the revision counter and dispatches a 0
   * 'change' event.
   * リビジョンカウンタを増加し、「change」イベントを送出します。
   * (ol3 API[説明は Stable Only のチェックを外すと表示])
   */
 });
 output.innerText = control.value;
 controls[id] = control;
});
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
 // event.data オブジェクトが operation に渡されます。
 var data = event.data;
 data.resolution = event.resolution;
 for (var id in controls) {
  data[id] = Number(controls[id].value);
  /** Number 
   * The Number JavaScript object is a wrapper object 
   * allowing you to work with numerical values. A Number 
   * object is created using the Number() constructor.
   * Number JavaScriptオブジェクトは、数値で作業することを
   * 可能にする wrapper オブジェクトです。 Numberオブジェク
   * トは、Number() コンストラクタを使用して作成されます。
   * (MDN[https://developer.mozilla.org/en-US/docs/Web/
   * JavaScript/Reference/Global_Objects/Number])
   */
 }
});


2 - ol3.8ex 127a - Shaded Relief 1

「Shaded Relief (shaded-relief.html)」を参考に地図を表示してみます。
説明に次のようにあります。

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 elevation data is used as input. The shaded relief is calculated in a single "image" operation. By setting operationType: 'image' on the raster source, operations are called with an ImageData object for each of the input sources. Operations are also called with a general purpose data object. In this example, the sun elevation and azimuth data from the inputs above are assigned to this data object and accessed in the shading operation. The shading operation returns an array of ImageData objects. When the raster source is used by an image layer, the first ImageData object returned by the last operation in the pipeline is used for rendering.
この場合には、標高データの単一タイルソースは、入力(データ)として使用されます。陰影起伏は、単一「画像」の operation で計算されます。ラスタソースで operationType: 'image' を設定すると、operation が、それぞれの入力ソースのための ImageData オブジェクトと共に呼び出されます。operation は、汎用データオブジェクトと共に呼び出されます。この例では、上記入力(データ)からの太陽仰角および方位角データは、このデータオブジェクトに割り当てられ、シェーディング operation にアクセスされます。シェーディング operation は ImageData オブジェクトの配列を返します。ラスタソースは、i画像レイヤによって使用されるとき、パイプラインの最後の operation によって返される最初の ImageData オブジェクトがレンダリングに使用されます。


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





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





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



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








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











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

「2127-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="shaded-relief.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>Shaded Relief</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"></div>
     <table class="controls">
      <tr>
       <td>vertical exaggeration: <span id="vertOut"></span>x</td>
       <td><input id="vert" type="range" min="1" max="5" value="1"/></td>
      </tr>
      <tr>
       <td>sun elevation: <span id="sunElOut"></span>°</td>
       <td><input id="sunEl" type="range" min="0" max="90" value="45"/></td>
      </tr>
      <tr>
       <td>sun azimuth: <span id="sunAzOut"></span>°</td>
       <td><input id="sunAz" type="range" min="0" max="360" value="45"/></td>
      </tr>
     </table>
    </div>
   </div>
   <div class="row-fluid">
    <div class="span12">
     <h4 id="title">Shaded Relief</h4>
     <p id="shortdesc">Calculate shaded relief from elevation data</p>
     <div id="docs">
     <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 elevation 
     data is used as input.  The shaded relief is 
     calculated in a single "image" operation. 
     By setting <code>operationType: 'image'</code> 
     on the raster source, operations are called with 
     an <code>ImageData</code> object for each of the 
     input sources.  Operations are also called with a 
     general purpose <code>data</code> object.  In this 
     example, the sun elevation and azimuth data from 
     the inputs above are assigned to this <code>data</code> 
     object and accessed in the shading operation.  
     The shading operation returns an array of 
     <code>ImageData</code> objects.  When the raster 
     source is used by an image layer, the first
     <code>ImageData</code> object returned by the last 
     operation in the pipeline is used for rendering.</p>
     <div id="tags">raster, shaded relief</div>
     <div id="api-links">Related API documentation: 
      <ul class="inline">
       <li>
        <!--<a href="../apidoc/ol.Map.html" title="API documentation for ol.Map">ol.Map>/a> -->
        <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.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>,
       <li>
        <!-- <a href="../apidoc/ol.source.TileJSON.html" title="API documentation for ol.source.TileJSON">ol.source.TileJSON>/a> -->
        <a href="v3.8.2/apidoc/ol.source.TileJSON.html" title="API documentation for ol.source.TileJSON">ol.source.TileJSON</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.source.XYZ.html" title="API documentation for ol.source.XYZ">ol.source.XYZ>/a> -->
        <a href="v3.8.2/apidoc/ol.source.XYZ.html" title="API documentation for ol.source.XYZ">ol.source.XYZ</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/twitter-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=shaded-relief"></script>
  -->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=2127-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 のコンテキストメニューが表示されると動作しています。