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

2015年2月18日水曜日

2 - ol3.2ex 65b -Move end example 2

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

「265-ol3ex.js」
var map = new ol.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.OSM()
   /** ol.source.OSM 
    * Layer source for the OpenStreetMap tile server.
    * OpenStreetMap タイルサーバのレイヤソース。(ol3 API)
    */
  })
 ],
 renderer: exampleNS.getRendererFromQueryString(),
 //'example-behavior.js' により URL にある renderer を返します
 target: 'map',
 controls: ol.control.defaults({
 /** controls
  * Controls initially added to the map. 
  * If not specified, ol.control.defaults() is used.
  * 初期設定で、マップに追加されたコントロール。
  * 明示されていなければ、ol.control.defaults() が使用されます。
  * (ol3 API)
  */
 /** ol.control.defaults()
  * デフォルトでは、マップに含まコントロールのセット。
  * 特に設定しない限り、これは、以下の各コントロールの
  * インスタンスを含むコレクションを返します。(ol3 API)
  * ol.control.Zoom, ol.control.Rotate, ol.control.Attribution
  */
  attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
  /** @type 
   * 値のタイプ(型)の説明 - 式などで表示
   * (@use JSDoc[http://usejsdoc.org/]より)
   */
   collapsible: false // 折りたたみ
  })
 }),
 view: new ol.View({
  center: [0, 0],
  zoom: 2
 })
});
function display(id, value) {
 document.getElementById(id).value = value.toFixed(2);
 /** 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 wrapLon(value) {
 var worlds = Math.floor((value + 180) / 360);
 /** Math.floor()
  * The Math.floor() function returns the largest 
  * integer less than or equal to a given number.
  * Math.floor() 関数は、指定された数以下の最大の整数、
  * または、等しい数を返します。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/
  * JavaScript/Reference/Global_Objects/Math/floor])
  */
 return value - (worlds * 360);
}
function onMoveEnd(evt) {
 var map = evt.map;
 var extent = map.getView().calculateExtent(map.getSize());
 /** getView()
  * Get the view associated with this map. A view 
  * manages properties such as center and resolution.
  * このマップと関連するビューを取得します。ビューは、
  * 中心や解像度のような属性を管理します。
  * Return: The view that controls this map.(ol3 API)
  */
 /** calculateExtent
  * Calculate the extent for the current view state and 
  * the passed `size`. `size` is the size in pixels of 
  * the box into which the calculated extent should fit. 
  * In most cases you want to get the extent of the 
  * entire map, that is `map.getSize()`. 
  * 現在のビューステートと渡された`size`の範囲を計算します。 
  * `size`は、計算された範囲に収まるボックスのピクセル単位
  * のサイズです。ほとんどの場合、マップ全体の範囲を取得しま
  * すが、それは`map.getSize()`です。(ol/ol/view.js)
  */
 /** getSize()
  * Get the size of this map.
  * Returns: The size in pixels of the map in the DOM.
  * マップのサイズを取得。(ol3 API)
  */
 var bottomLeft = ol.proj.transform(ol.extent.getBottomLeft(extent),
 /** 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)
  */
 /** ol.extent.getBottomLeft
  * Return: Bottom Left coordinate.(ol3 API)
  */
  'EPSG:3857', 'EPSG:4326');
 var topRight = ol.proj.transform(ol.extent.getTopRight(extent),
 /** ol.extent.getTopRight
  * Return: Top Right coordinate.(ol3 API)
  */
  'EPSG:3857', 'EPSG:4326');
 display('left', wrapLon(bottomLeft[0]));
 display('bottom', bottomLeft[1]);
 display('right', wrapLon(topRight[0]));
 display('top', topRight[1]);
}
map.on('moveend', onMoveEnd);
/** on
 * Listen for a certain type of event.
 * あるタイプのイベントをリッスンします。(ol3 API)
 */

2 - ol3.2ex 65a - Move end example 1

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

Use of the moveend event.
In this example, a listener is registered for the map's moveend event. Whenever this listener is called, it updates the inputs below with the map extent in decimal degrees.

moveend イベントの使用。
この例では、リスナは、マップの moveend イベントに登録されています。このリスナが呼び出されるたびに、十進数の角度のマップ範囲を使って下の入力を更新します。


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





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





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



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








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











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


「265-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.2.1/css/ol.css" type="text/css">
  <link rel="stylesheet" href="v3.2.1/resources/bootstrap/css/bootstrap.min.css" type="text/css">
  <link rel="stylesheet" href="v3.2.1/resources/layout.css" type="text/css">
  <link rel="stylesheet" href="v3.2.1/resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
  <title>Moveend example</title>
 </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.2.1/examples/"><img src="v3.2.1/resources/logo.png"> OpenLayers 3 Examples</a>
    </div>
   </div>
  </div>
  <div class="container-fluid">
   <div class="row-fluid">
    <div class="span12 mapcontainer">
     <div id="map" class="map"></div>
    </div>
   </div>
   <div class="row-fluid">
    <div class="span12">
     <h4 id="title">Moveend example </h4>
     <p id="shortdesc">Use of the moveend event.</p>
     <div id="docs">
      <p>In this example, a listener is registered for the 
       map's <code>moveend</code> event.  Whenever this 
       listener is called, it updates the inputs below with 
       the map extent in decimal degrees.</p>
      <!--
      See the <a href="moveend.js" target="_blank">moveend.js source</a> to see how this is done.</p>
      -->
      <!-- ファイル修正 -->
      See the <a href="265-ol3ex.js" target="_blank">265-ol3ex.js source</a> to see how this is done.</p>
     </div>
     <div id="tags">moveend, map, event</div>
     <label>top</label><input type="text" id="top">
     <label>right</label><input type="text" id="right">
     <label>bottom</label><input type="text" id="bottom">
     <label>left</label><input type="text" id="left">
    </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.2.1/resources/jquery.min.js" type="text/javascript"></script>
  <script src="v3.2.1/resources/example-behaviour.js" type="text/javascript"></script>
  <!--
  <script src="loader.js?id=moveend" type="text/javascript"></script>
  -->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=265-ol3ex" type="text/javascript"></script>
 </body>
</html>