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

2015年2月18日水曜日

2 - ol3.2ex 63b - Advanced View Positioning example 2

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

「263-ol3ex.js」
var source = new ol.source.GeoJSON({
/** ol.source.GeoJSON 
 * Static vector source in GeoJSON format
 * GeoJSON フォーマットの静的ベクタソース。(ol3 API)
 */
 projection: 'EPSG:3857',
// url: 'data/geojson/switzerland.geojson'
 url: 'v3.2.1/examples/data/geojson/switzerland.geojson'
 // 修正
});
var style = new ol.style.Style({
/** ol.style.Style 
 * Base class for vector feature rendering styles.
 * ベクタフィーチャがスタイルを描画するための基本クラス。
 * (ol3 API)
 */
 fill: new ol.style.Fill({
 /** ol.style.Fill 
  * Set fill style for vector features.
  * ベクタフィーチャの塗りつぶしスタイルを設定。(ol3 API)
  */
  color: 'rgba(255, 255, 255, 0.6)'
 }),
 stroke: new ol.style.Stroke({
 /** ol.style.Stroke 
  * Set stroke style for vector features. 
  * Note that the defaults given are the Canvas defaults, 
  * which will be used if option is not defined. 
  * The get functions return whatever was entered 
  * in the options;  they will not return the default.
  * ベクタフィーチャのためのストロークスタイルの設定。
  * デフォルトは、オプションが定義されていない場合に使用される
  * Canvas のデフォルトを与えられることに注意してください。 
  * GET関数は、オプションで入力されたものはすべて返します。
  * それらはデフォルトを返しません。(ol3 API)
  */
  color: '#319FD3',
  width: 1
 }),
 image: new ol.style.Circle({
 /** ol.style.Circle
  * Set circle style for vector features.
  * ベクタフィーチャの円のスタイルを設定。(ol3 API)
  */
  radius: 5,
  fill: new ol.style.Fill({
   color: 'rgba(255, 255, 255, 0.6)'
  }),
  stroke: new ol.style.Stroke({
   color: '#319FD3',
   width: 1
  })
 })
});
var vectorLayer = new ol.layer.Vector({
/** ol.layer.Vector
 * Vector data that is rendered client-side.
 * クライアント側で描画されたベクタデータ。(ol3 API)
 */
 source: source,
 style: style
});
var view = new ol.View({
 center: [0, 0],
 zoom: 1
});
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)
    */
  }),
  vectorLayer
 ],
 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: view
});
var zoomtoswitzerlandbest = document.getElementById('zoomtoswitzerlandbest');
zoomtoswitzerlandbest.addEventListener('click', function() {
/** EventTarget.addEventListener
 * addEventListener は、 1 つのイベントターゲットにイベント 
 * リスナーを1 つ登録します。イベントターゲットは、ドキュメント
 * 上の単一のノード、ドキュメント自身、ウィンドウ、あるいは、
 * XMLHttpRequest です。
 *(MDN[https://developer.mozilla.org/ja/docs/Web/API/
 * EventTarget.addEventListener])
 */
 var feature = source.getFeatures()[0];
 /** getFeatures()
  * Get all features on the source.
  * ソースのすべてのフィーチャを取得します。
  * Return: Features(ol3 API)
  */
 var polygon = /** @type {ol.geom.SimpleGeometry} */ (feature.getGeometry());
 /** getGeometry()
  * Returns the Geometry associated with this feature 
  * using the current geometry name property. By default, 
  * this is geometry but it may be changed by calling 
  * setGeometryName.
  * 現在のジオメトリネームプロパティを使用して、このフィーチャに
  * 関連したジオメトリを返します。デフォルトでは、ジオメトリです
  * が、setGeometryName を呼び出すことによって変更することがで
  * きます。(ol3 API)
  */
 var size = /** @type {ol.Size} */ (map.getSize());
 /** getSize()
  * Get the size of this map.
  * Returns: The size in pixels of the map in the DOM.
  * マップのサイズを取得。(ol3 API)
  */
 view.fitGeometry(
 /**fitGeometry()
  * Fit the given geometry based on the given map 
  * size and border. Take care on the map angle.
  * 与えられたマップサイズと境界線に基づいて、与えられた
  * ジオメトリーを合わせます。地図角度に注意してください。
  * (ol/ol/view.js)
  */
  polygon,
  size,
  {
   padding: [170, 50, 30, 150],
   constrainResolution: false
  }
 );
}, false);
var zoomtoswitzerlandconstrained =
 document.getElementById('zoomtoswitzerlandconstrained');
zoomtoswitzerlandconstrained.addEventListener('click', function() {
 var feature = source.getFeatures()[0];
 var polygon = /** @type {ol.geom.SimpleGeometry} */ (feature.getGeometry());
 var size = /** @type {ol.Size} */ (map.getSize());
 view.fitGeometry(
  polygon,
  size,
  {
   padding: [170, 50, 30, 150]
  }
 );
}, false);
var zoomtoswitzerlandnearest =
 document.getElementById('zoomtoswitzerlandnearest');
zoomtoswitzerlandnearest.addEventListener('click', function() {
 var feature = source.getFeatures()[0];
 var polygon = /** @type {ol.geom.SimpleGeometry} */ (feature.getGeometry());
 var size = /** @type {ol.Size} */ (map.getSize());
 view.fitGeometry(
  polygon,
  size,
  {
   adding: [170, 50, 30, 150],
   nearest: true
  }
 );
}, false);
var zoomtolausanne = document.getElementById('zoomtolausanne');
zoomtolausanne.addEventListener('click', function() {
 var feature = source.getFeatures()[1];
 var point = /** @type {ol.geom.SimpleGeometry} */ (feature.getGeometry());
 var size = /** @type {ol.Size} */ (map.getSize());
 view.fitGeometry(
  point,
  size,
  {
   padding: [170, 50, 30, 150],
   minResolution: 50
  }
 );
}, false);
var centerlausanne = document.getElementById('centerlausanne');
centerlausanne.addEventListener('click', function() {
 var feature = source.getFeatures()[1];
 var point = /** @type {ol.geom.Point} */ (feature.getGeometry());
 var size = /** @type {ol.Size} */ (map.getSize());
 view.centerOn(
  point.getCoordinates(),
 /** getCoordinates()
  * Returns: Coordinates.(ol3 API)
  */
  size,
  [570, 500]
 );
}, false);

2 - ol3.2ex 63a - Advanced View Positioning example 1

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

This example demonstrates how a map's view can be adjusted so a geometry or coordinate is positioned at a specific pixel location. The map above has top, right, bottom, and left padding applied inside the viewport. The view's fitGeometry method is used to fit a geometry in the view with the same padding. The view's centerOn method is used to position a coordinate (Lausanne) at a specific pixel location (the center of the black box).
Use Alt+Shift+drag to rotate the map.

この例では、マップのビューが、非常にジオメトリ、または特定のピクセル位置に配置される座標を調整することができる方法を示します。上記のマップは、ビューポートの内側に適用している上、右、下、左パディングがあります。ビューのfitGeometry メソッドは、同じパディングを持つビューにあるジオメトリに合わせるために使用されます。ビューの centerOn メソッドは、特定の画素位置(ブラックボックスの中心)の座標(ローザンヌ)に位置決めするために使用されます。
マップを回転させるには、Alt+Shift+ドラッグを使用してください。


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





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





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



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








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











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


「263-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">
  <style>
   .mapcontainer {
    position: relative;
    margin-bottom: 20px;
   }
   .map {
    width: 1000px;
    height: 600px;
   }
   div.ol-zoom {
    top: 178px;
    left: 158px;
   }
   div.ol-attribution {
    bottom: 30px;
    right: 50px;
   }
   .padding-top {
    position: absolute;
    top: 0;
    left: 0px;
    width: 1000px;
    height: 170px;
    background: rgba(255, 255, 255, 0.5);
   }
   .padding-left {
    position: absolute;
    top: 170px;
    left: 0;
    width: 150px;
    height: 400px;
    background: rgba(255, 255, 255, 0.5);
   }
   .padding-right {
    position: absolute;
    top: 170px;
    left: 950px;
    width: 50px;
    height: 400px;
    background: rgba(255, 255, 255, 0.5);
   }
   .padding-bottom {
    position: absolute;
    top: 570px;
    left: 0px;
    width: 1000px;
    height: 30px;
    background: rgba(255, 255, 255, 0.5);
   }
   .center {
    position: absolute;
    border: solid 1px black;
    top: 490px;
    left: 560px;
    width: 20px;
    height: 20px;
   }
  </style>
  <title>Advanced View Positioning 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 class="padding-top"></div>
     <div class="padding-left"></div>
     <div class="padding-right"></div>
     <div class="padding-bottom"></div>
     <div class="center"></div>
    </div>
   </div>
     <div class="row-fluid">
      <div class="span12">
       <button id="zoomtoswitzerlandbest">Zoom to Switzerland</button> (best fit),<br/>
       <button id="zoomtoswitzerlandconstrained">Zoom to Switzerland</button> (respect resolution constraint).<br/>
       <button id="zoomtoswitzerlandnearest">Zoom to Switzerland</button> (nearest),<br/>
       <button id="zoomtolausanne">Zoom to Lausanne</button> (with min resolution),<br/>
       <button id="centerlausanne">Center on Lausanne</button>
      </div>
     </div>
   <div class="row-fluid">
    <div class="span12">
     <h4 id="title">dvanced View Positioning example </h4>
     <p id="shortdesc">This example demonstrates how a map's view can be 
      adjusted so a geometry or coordinate is positioned at a specific
      pixel location. The map above has top, right, bottom, and left
      padding applied inside the viewport. The view's <code>fitGeometry</code> method
      is used to fit a geometry in the view with the same padding. The
      view's <code>centerOn</code> method is used to position a coordinate (Lausanne)
      at a specific pixel location (the center of the black box).
     <div id="docs">
      <p>Use <code>Alt</code>+<code>Shift</code>+drag to rotate the map.</p>
      <!--
      See the <a href="center.js" target="_blank">center.js source</a> to see how this is done.</p>
      -->
      <!-- ファイル修正 -->
      See the <a href="263-ol3ex.js" target="_blank">263-ol3ex.js source</a> to see how this is done.</p>
     </div>
     <div id="tags">center, rotation, openstreetmap</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.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=center" type="text/javascript"></script>
  -->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=263-ol3ex" type="text/javascript"></script>
 </body>
</html>