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

2015年3月19日木曜日

2 - ol3.3ex 87b - Hue/saturation example 2

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

「287-ol3ex.js」
function setResetHueButtonHTML() {
 resetHue.innerHTML = 'Hue (' + layer.getHue().toFixed(2) + ')';
 /** element.innerHTML
  * innerHTML は、与えられた要素に含まれる全てのマークアップ
  * と内容を設定または取得します。
  * (MDN[https://developer.mozilla.org/ja/docs/Web/
  * API/element.innerHTML])
  */
 /** getHue()
  * Return: The hue of the layer.
  * (ol3 API[説明は Stable Only のチェックを外すと表示])
  */
 /** Number.prototype.toFixed()
  * The toFixed() method formats a number using 
  * fixed-point notation.
  * toFixed() メソッドは、固定小数点表記を使用して数値を
  * フォーマットします。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/
  * JavaScript/Reference/Global_Objects/Number/toFixed])
  */
}
function setResetSaturationButtonHTML() {
 resetSaturation.innerHTML = 'Saturation (' +
  layer.getSaturation().toFixed(2) + ')';
  /** getSaturation()
   * Return: The saturation of the layer.
   * (ol3 API[説明は Stable Only のチェックを外すと表示])
   */
}
if (!ol.has.WEBGL) {
/** ol.has.WEBGL{boolean}
 * True if browser supports WebGL.
 * ブラウザが WebGL をサポートしていたら true。(ol3 API)
 */
 var info = document.getElementById('no-webgl');
 /**
  * display error message
  */
  info.style.display = '';
} else {
 var layer = new ol.layer.Tile({
  source: new ol.source.BingMaps({
  /** ol.source.BingMaps
   * Layer source for Bing Maps tile data.
   * Bing Maps タイルデータのレイヤソース。(ol3 API)
   */
   key: 'Ak-dzM4w...(省略)',
   imagerySet: 'Aerial'
  })
 })
 var map = new ol.Map({
  layers: [layer],
  renderer: 'webgl',
  target: 'map',
  view: new ol.View({
   center: ol.proj.transform([-9.375, 51.483333], 'EPSG:4326', 'EPSG:3857'),
   zoom: 15
  })
 });
 var increaseHue = document.getElementById('increase-hue');
 var resetHue = document.getElementById('reset-hue');
 var decreaseHue = document.getElementById('decrease-hue');

 setResetHueButtonHTML();
 increaseHue.addEventListener('click', function() {
 /** EventTarget.addEventListener
  * addEventListener は、 1 つのイベントターゲットにイベント 
  * リスナーを1 つ登録します。イベントターゲットは、ドキュメント
  * 上の単一のノード、ドキュメント自身、ウィンドウ、あるいは、
  * XMLHttpRequest です。
  *(MDN[https://developer.mozilla.org/ja/docs/Web/API/
  * EventTarget.addEventListener])
  */
  layer.setHue(layer.getHue() + 0.25);
  /** setHue(hue) 
   * Apply a hue-rotation to the layer. A value of 0 
   * will leave the hue unchanged. Other values are 
   * radians around the color circle.
   * レイヤに色相回転を適用します。 0 の値は変わらない色合いを
   * 残します。他の値は色相環の周囲をラジアンで表します。
   * (ol3 API[説明は Stable Only のチェックを外すと表示])
   */
  /** getHue()
   * Return; The hue of the layer.
   * (ol3 API[説明は Stable Only のチェックを外すと表示])
   */
  setResetHueButtonHTML();
 }, false);
 resetHue.addEventListener('click', function() {
  layer.setHue(0);
  setResetHueButtonHTML();
 }, false);
 decreaseHue.addEventListener('click', function() {
  layer.setHue(layer.getHue() - 0.25);
  setResetHueButtonHTML();
 }, false);
 var increaseSaturation = document.getElementById('increase-saturation');
 var resetSaturation = document.getElementById('reset-saturation');
 var decreaseSaturation = document.getElementById('decrease-saturation');

 setResetSaturationButtonHTML();
 increaseSaturation.addEventListener('click', function() {
  layer.setSaturation(layer.getSaturation() + 0.25);
  /** setSaturation(saturation) 
   * Adjust layer saturation. A value of 0 will render 
   * the layer completely unsaturated. A value of 1 
   * will leave the saturation unchanged. Other values 
   * are linear multipliers of the effect (and values 
   * over 1 are permitted).
   * レイヤの彩度を調整します。 0の値は、レイヤが完全に不飽和
   * レンダリングされます。 1 の値は彩度変更がないままです。
   * 他の値は線形乗算効果(1 以上の値が許可されています)で
   * す。
   * (ol3 API[説明は Stable Only のチェックを外すと表示])
   */
  /** getSaturation()
   * Return: The saturation of the layer.
   * (ol3 API[説明は Stable Only のチェックを外すと表示])
   */
  setResetSaturationButtonHTML();
 }, false);
 resetSaturation.addEventListener('click', function() {
  layer.setSaturation(1);
   setResetSaturationButtonHTML();
 }, false);
 decreaseSaturation.addEventListener('click', function() {
  layer.setSaturation(Math.max(layer.getSaturation() - 0.25, 0));
  /** Math.max() 
   * 引数として与えた複数の数の中で最大の数を返します。
   * (MDN [https://developer.mozilla.org/ja/docs/Web/
   * JavaScript/Reference/Global_Objects/Math/max])
   */
  setResetSaturationButtonHTML();
 }, false);
}

2 - ol3.3ex 87a - Hue/saturation example 1

「Hue/saturation example (hue-saturation.html)」を参考に地図を表示してみます。

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





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





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



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








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











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


「287-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="../css/ol.css" type="text/css">
  <link rel="stylesheet" href="../resources/bootstrap/css/bootstrap.min.css" type="text/css">
  <link rel="stylesheet" href="../resources/layout.css" type="text/css">
  <link rel="stylesheet" href="../resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
-->
  <!-- ディレクトリ修正 -->
  <link rel="stylesheet" href="v3.3.0/css/ol.css" type="text/css">
  <link rel="stylesheet" href="v3.3.0/resources/bootstrap/css/bootstrap.min.css" type="text/css">
  <link rel="stylesheet" href="v3.3.0/resources/layout.css" type="text/css">
  <link rel="stylesheet" href="v3.3.0/resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
  <title>Hue/saturation example</title>
  <style>
   #reset-hue {
    min-width: 90px;
   }
   #reset-saturation {
    min-width: 124px;
   }
  </style>
 </head>
 <body>
  <!-- 
  bootstrap.min.css, bootstrap-responsive.min.css で設定されたセレクタを使用。
  -->
  <div class="navbar navbar-inverse navbar-fixed-top">
   <div class="navbar-inner">
    <div class="container">
     <!--
     <a class="brand" href="./"><img src="../resources/logo.png"> OpenLayers 3 Examples</a>
     -->
     <!-- ディレクトリ修正 -->
     <a class="brand" href="v3.3.0/examples/"><img src="v3.3.0/resources/logo.png"> OpenLayers 3 Examples</a>
    </div>
   </div>
  </div>
  <div class="container-fluid">
   <div class="row-fluid">
    <div class="span12">
     <div id="map" class="map"></div>
     <div id="no-webgl" class="alert alert-error" style="display: none">
      This example requires a browser that supports <a href="http://get.webgl.org/">WebGL</a>.
     </div>
     <div class="btn-group">
      <button id="increase-hue"><i class="icon-plus"></i></button>
      <button id="reset-hue">Hue</button>
      <button id="decrease-hue"><i class="icon-minus"></i></button>
     </div>
     <div class="btn-group">
      <button id="increase-saturation"><i class="icon-plus"></i></button>
      <button id="reset-saturation">Saturation</button>
      <button id="decrease-saturation"><i class="icon-minus"></i></button>
     </div>
    </div>
   </div>
   <div class="row-fluid">
    <div class="span12">
    <h4 id="title">Hue/saturation example</h4>
     <p id="shortdesc">Example of hue/saturation control on 
     the client (WebGL only). </p>
     <div id="docs">
      <!--
      <p>See the <a href="hue-saturation.js" target="_blank">hue-saturation.js source</a> 
       to see how this is done.</p>
      -->
      <!-- ファイル修正 -->
      <p>See the <a href="287-ol3ex.js" target="_blank">287-ol3ex.js source</a> 
       to see how this is done.</p>
     </div>
     <div id="tags">hue, saturation, webgl</div>
    </div>
   </div>
  </div>
  <!--
  <script src="../resources/jquery.min.js" type="text/javascript"></script>
  <script src="../resources/example-behaviour.js" type="text/javascript"></script>
  -->
  <!-- ディレクトリ修正
   jQuery Minified版と
   example-behaviour.js(Examples用 JSコード[文字コードなど])
  -->
  <script src="v3.3.0/resources/jquery.min.js" type="text/javascript"></script>
  <script src="v3.3.0/resources/example-behaviour.js" type="text/javascript"></script>
  <!--
  <script src="loader.js?id=hue-saturation" type="text/javascript"></script>
  -->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=287-ol3ex" type="text/javascript"></script>
 </body>
</html>