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

2014年11月30日日曜日

2 - ol3ex 40b - Overlay example 2

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

「240-ol3ex.js」の内容
var layer = 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.MapQuest({layer: 'sat'})
 /** ol.source.MapQuest
  * Layer source for the MapQuest tile server.
  * MapQuest タイルサーバのレイヤソース。(ol3 API
  * 2 - ol3ex 23b - MapQuest example 2 参照)
  */
});
var map = new ol.Map({
 layers: [layer],
 renderer: exampleNS.getRendererFromQueryString(),
 //'example-behavior.js' により URL にある renderer を返します
 target: 'map',
 view: new ol.View({
  center: [0, 0],
  zoom: 2
 })
});
var pos = ol.proj.transform([16.3725, 48.208889], 'EPSG:4326', 'EPSG:3857');
/** 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)
 */
// Vienna marker
var marker = new ol.Overlay({
/** ol.Overlay 
 * Like ol.control.Control, Overlays are visible widgets. 
 * Unlike Controls, they are not in a fixed position on 
 * the screen, but are tied to a geographical coordinate, 
 * so panning the map will move an Overlay but not a Control.
 * ol.control.Controlと同じように、オーバーレイは、目に見える
 * ウィジェットです。コントロールとは異なり、それらは画面上の
 * 固定された位置にありませんが、地理座標に関連付けられている
 * ので、オーバーレイを移動しますが、コントロールできない
 * マップをパンします。(ol3 API)
 */
 position: pos,
 positioning: 'center-center',
 element: document.getElementById('marker'),
 stopEvent: false
});
map.addOverlay(marker);
/** addOverlay()
 * Add the given overlay to the map.
 * 与えられたオーバーレイをマップに追加します。(ol3 API)
 */
// Vienna label
var vienna = new ol.Overlay({
 position: pos,
 element: document.getElementById('vienna')
});
map.addOverlay(vienna);
// Popup showing the position the user clicked
var popup = new ol.Overlay({
 element: document.getElementById('popup')
});
map.addOverlay(popup);
map.on('click', function(evt) {
/** on
 * Listen for a certain type of event.
 * あるタイプのイベントをリッスンします。(ol3 API)
 */
 var element = popup.getElement();
 /** getElement()
  * Get the DOM element of this overlay.
  * このオーバーレイの DOM エレメントを取得します。
  * (ol3 API)
  */
 var coordinate = evt.coordinate;
 var hdms = ol.coordinate.toStringHDMS(ol.proj.transform(
 /** ol.coordinate.toStringHDMS()
  * Returns: Hemisphere, degrees, minutes and seconds.
  * (ol3 API)
  */
  coordinate, 'EPSG:3857', 'EPSG:4326'));
 $(element).popover('destroy');
  /** Popovers popover.js
   * Add small overlays of content, like those on the iPad, 
   * to any element for housing secondary information. 
   * Popovers whose both title and content are zero-length 
   * are never displayed.
   * コンテンツの小さなオーバーレイを、iPad上のもののように、
   * ハウジング二次情報のための要素に追加します。
   * タイトルと内容の両方が長さゼロ(の文字列)である Popovers 
   * は、表示されません。
   * (Bootstrap[http://getbootstrap.com/javascript/
   * #popovers])
   */ 
 popup.setPosition(coordinate);
 /** etPosition(position))
  * Set the position for this overlay.
  * このオーバーレイの位置を設定します。(ol3 API)
  */
 /** the keys are quoted to prevent renaming in 
  * ADVANCED_OPTIMIZATIONS mode.
  * キーはADVANCED_OPTIMIZATIONSモードで名前変更を防ぐために、
  * ここで提示します。
  */
 $(element).popover({
  'placement': 'top',
  'animation': false,
  'html': true,
  'content': '<p>The location you clicked was:</p><code>' + hdms + '</code>'
 });
 $(element).popover('show');
});

2 - ol3ex 40a - Overlay example 1

「Overlay example(overlay.html)」を参考に地図を表示してみます。

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





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





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



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








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











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


「240-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.0.0/css/ol.css" type="text/css">
  <link rel="stylesheet" href="v3.0.0/resources/bootstrap/css/bootstrap.min.css" type="text/css">
  <link rel="stylesheet" href="v3.0.0/resources/layout.css" type="text/css">
  <link rel="stylesheet" href="v3.0.0/resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
  <title>Overlay example example</title>
  <style type="text/css">
   #marker {
    width: 20px;
    height: 20px;
    border: 1px solid #088;
    border-radius: 10px;
    background-color: #0FF;
    opacity: 0.5;
   }
   #vienna {
    text-decoration: none;
    color: white;
    font-size: 11pt;
    font-weight: bold;
    text-shadow: black 0.1em 0.1em 0.2em;
   }
   .popover {
    z-index: auto;
   }
   .popover-content {
    min-width: 180px;
   }
  </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.0.0/examples/"><img src="v3.0.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>
   </div>
   <div class="row-fluid">
    <div class="span12">
     <h4 id="title">Overlay example</h4>
     <p id="shortdesc">Demonstrates overlays.</p>
     <div id="docs">
      <p>The popups are created using
       <a href="http://twitter.github.com/bootstrap/javascript.html#popovers">Popovers</a> from Bootstrap.</p>
     <!--
      <p>See the <a href="overlay.js" target="_blank">overlay.js source</a> to see how this is done.</p>
     -->
       <!-- ファイル修正 -->
      <p>See the <a href="240-ol3ex.js" target="_blank">240-ol3ex.js source</a> to see how this is done.</p>
     </div>
     <div id="tags">overlay, popup, bootstrap, popover, mapquest, openaerial</div>
    </div>
   </div>
  </div>
  <div style="display: none;">
   <!-- Clickable label for Vienna -->
   <a class="overlay" id="vienna" target="_blank" href="http://en.wikipedia.org/wiki/Vienna">Vienna</a>
   <div id="marker" title="Marker"></div>
   <!-- Popup -->
   <div id="popup" title="Welcome to ol3"></div>
  </div>
  <!--
  <script src="jquery.min.js" type="text/javascript"></script>
  <script src="../resources/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
  <script src="../resources/example-behaviour.js" type="text/javascript"></script>
  -->
  <!-- ディレクトリ修正
   jQuery Minified版と
   bootstrap.min.js(tooltip など)
   example-behaviour.js(Examples用 JSコード[文字コードなど])
  -->
  <script src="v3.0.0/examples/jquery.min.js" type="text/javascript"></script>
  <script src="v3.0.0/resources/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
  <script src="v3.0.0/resources/example-behaviour.js" type="text/javascript"></script>
  <!--
  <script src="loader.js?id=overlay" type="text/javascript"></script>
  -->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=240-ol3ex" type="text/javascript"></script>

 </body>
</html>