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

2015年3月8日日曜日

2 - ol3.3ex 80b - Tile load events example 2

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

「280-ol3ex.js」
/**
 * Renders a progress bar.
 * @param {Element} el The target element.
 * @constructor
 */
/** 「@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])
 */
/** 「@constructor(@class と同義)」
 * The @class tag marks a function as being a 
 * constructor, meant to be called with the new 
 * keyword to return an instance.
 * @classタグは、インスタンスを返すために、新しいキーワードで
 * 呼び出されることを意図し、コンストラクタとして function を
 * マークします。
 * (@use JSDoc [http://usejsdoc.org/tags-class.html])
 */
function Progress(el) {
 this.el = el;
 this.loading = 0;
 this.loaded = 0;
}

/**
 * Increment the count of loading tiles.
 * ローディングするタイルのカウントをインクリメント(増や)
 * します。
 */
Progress.prototype.addLoading = function() {
/** Object.prototype
 * The Object.prototype property represents the 
 * Object prototype object.
 * Object.prototype プロパティは、Object プロパティ
 * オブジェクトを表します。
 * (MDN[https://developer.mozilla.org/en-US/docs/Web/
 * JavaScript/Reference/Global_Objects/Object/prototype])
 */
 if (this.loading === 0) {
  this.show();
 }
 ++this.loading;
 this.update();
};

/**
 * Increment the count of loaded tiles.
 * ローディングしたタイルのカウントをインクリメント(増や)
 * します。
 */
Progress.prototype.addLoaded = function() {
 setTimeout(function() {
 /** setTimeout(func, dylay)
  * 指定された遅延の後に、コードの断片または関数を実行します。
  * func : delay ミリ秒後に実行したい関数。
  * delay : 関数呼び出しを遅延させるミリ秒(1/1000 秒)。
  * (MDN[https://developer.mozilla.org/ja/docs/Web/
  * API/Window/setTimeout])
  */
  ++this.loaded;
  this.update();
 }.bind(this), 100);
 /** Function.prototype.bind()
  * bind() メソッドは、呼び出された時に新しい関数を生成しま
  * す。最初の引数  thisArg は新しい関数の this キーワード
  * にセットされます。2 個目以降の引数は、新しい関数より前に、
  * ターゲット関数の引数として与えられます。
  * (下記ページ内「setTimeout とともに」も参照してください。)
  * (MDN[https://developer.mozilla.org/ja/docs/Web/
  * JavaScript/Reference/Global_Objects/Function/bind])
  */
};

/**
 * Update the progress bar.
 * プログレスバーを更新します。
 */
Progress.prototype.update = function() {
 var width = (this.loaded / this.loading * 100).toFixed(1) + '%';
 /** 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])
  */
 this.el.style.width = width;
 if (this.loading === this.loaded) {
  this.loading = 0;
  this.loaded = 0;
  setTimeout(this.hide.bind(this), 500);
 }
};

/**
 * Show the progress bar.
 * プログレスバーを表示します。
 */
Progress.prototype.show = function() {
 this.el.style.visibility = 'visible';
};

/**
 * Hide the progress bar.
 * プログレスバーを非表示にします。
 */
Progress.prototype.hide = function() {
 if (this.loading === this.loaded) {
  this.el.style.visibility = 'hidden';
  this.el.style.width = 0;
 }
};
var progress = new Progress(document.getElementById('progress'));
var 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/mapbox.world-bright.jsonp',
 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)
  */
});
source.on('tileloadstart', function(event) {
/** on()
 * Listen for a certain type of event.
 * Return:     Unique key for the listener.
 * (ol3 API)
 */
 progress.addLoading();
});
source.on('tileloadend', function(event) {
 progress.addLoaded();
});
source.on('tileloaderror', function(event) {
 progress.addLoaded();
});
var map = new ol.Map({
 logo: false,
 layers: [
  new ol.layer.Tile({source: source})
  /** 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)
   */
 ],
 renderer: exampleNS.getRendererFromQueryString(),
 //'example-behavior.js' により URL にある renderer を返します
 target: 'map',
 view: new ol.View({
  center: [0, 0],
  zoom: 2
 })
});

2 - ol3.3ex 80a - Tile load events example 1

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

Image tile sources fire events related to tile loading. You can listen for tileloadstart, tileloadend, and tileloaderror type events to monitor tile loading progress. This example registers listeners for these events and renders a tile loading progress bar at the bottom of the map.

画像タイルソースは、タイルのロードに関連するイベントを発生します。タイルロードの進行状況を監視するために、tileloadstart と tileloadend、tileloaderror タイプのイベントをリッスンすることができます。この例では、これらのイベントのリスナを登録し、マップの下部にあるタイルのロードプログレス(進行状況)バーをレンダリングします。


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





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





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



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








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











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


「280-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>Tile load events example</title>
  <style>
   .map {
    background: #E0ECED;
   }
   .wrapper {
    position: relative;
   }
   #progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    background: rgba(0, 60, 136, 0.4);
    width: 0;
    transition: width 250ms;
   }
  </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 wrapper">
     <div id="map" class="map"></div>
     <div id="progress"></div>
    </div>
   </div>
   <div class="row-fluid">
    <div class="span12">
    <h4 id="title">Tile load events example</h4>
     <p id="shortdesc">Example using tile load events.</p>
     <div id="docs">
     <p>Image tile sources fire events related to tile
      loading.  You can listen for <code>tileloadstart
      </code>, <code>tileloadend</code>, and
      <code>tileloaderror</code> type events to monitor 
      tile loading progress.  This example registers
      listeners for these events and renders a tile 
      loading progress bar at the bottom of the map.</p>
      <!--
      <p>See the <a href="tile-load-events.js" target="_blank">tile-load-events.js source</a> 
       for more detail on how this is done.</p>
      -->
      <!-- ファイル修正 -->
      <p>See the <a href="280-ol3ex.js" target="_blank">280-ol3ex.js source</a> 
       for more detail on how this is done.</p>
     </div>
     <div id="tags">tile, events, loading</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=tile-load-events" type="text/javascript"></script>
  -->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=280-ol3ex" type="text/javascript"></script>
 </body>
</html>