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

2015年4月13日月曜日

2 - ol3.4ex 108b - XYZ with Retina tiles example 2

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

「2108-ol3ex.js」
var attribution = new ol.Attribution({
/** ol.Attribution
 * An attribution for a layer source.
 * レイヤソースの属性(ol3 API)
 */
 html: 'Tiles © USGS, rendered with ' +
  '<a href="http://www.maptiler.com/">MapTiler</a>'
});
var mapMinZoom = 1;
var mapMaxZoom = 15;
var mapExtent = [-112.261791, 35.983744, -112.113981, 36.132062];
var map = new ol.Map({
 target: 'map',
 layers: [
  new ol.layer.Tile({
   source: new ol.source.OSM()
   /** ol.source.OSM 
    * Layer source for the OpenStreetMap tile server.
    * OpenStreetMap タイルサーバのレイヤソース。(ol3 API)
    */
  }),
  new ol.layer.Tile({
   extent: ol.proj.transformExtent(mapExtent, 'EPSG:4326', 'EPSG:3857'),
   /** ol.proj.transformExtent(extent, source, destination)
    * Transforms an extent from source projection to 
    * destination projection. This returns a new extent
    *  (and does not modify the original).
    * ソース投影から変換先投影へ範囲を変換します。これは、新しい
    * 範囲を返します(オリジナルを変更しません)。(ol3 API)
    */
   source: new ol.source.XYZ({
   /** ol.source.XYZ
    * Layer source for tile data with URLs in a set XYZ 
    * format.
    * セットXYZ形式のURLを持つタイルデータのレイヤソース。
    * (ol3 API)
    */
    attributions: [attribution],
    url: 'http://tileserver.maptiler.com/grandcanyon@2x/{z}/{x}/{y}.png',
    tilePixelRatio: 2, // THIS IS IMPORTANT
    /** tilePixelRatio
     * The pixel ratio used by the tile service. For example,
     * if the tile service advertizes 256px by 256px tiles 
     * but actually sends 512px by 512px images (for 
     * retina/hidpi devices) then tilePixelRatio should be 
     * set to 2. Default is 1.
     * タイルサービスによって使用される画素比率。例えば、タイ
     * ルサービスが 256px x 256px によるタイルを告知し、実際
     * に(retina/hidpiデバイス用)512px x 512pxで画像を送信
     * した場合、その後 tilePixelRatio を 2 に設定する必要が
     * あります。デフォルトは 1 です。
     * (ol3 API[説明は Stable Only のチェックを外すと表示])
     */
    minZoom: mapMinZoom,
    maxZoom: mapMaxZoom
   })
  })
 ],
 view: new ol.View({
  projection: 'EPSG:3857',
  center: ol.proj.transform([-112.18688965, 36.057944835],
   'EPSG:4326', 'EPSG:3857'),
  zoom: 12
 })
});
 
この地図の完成イメージは、

http://tileserver.maptiler.com/grandcanyon@2x/ol3.html

を参照してください。

2 - ol3.4ex 108a - XYZ with Retina tiles example 1

「XYZ with Retina tiles example (xyz-retina.html)」を参考に地図を表示してみます。
説明に次のようにあります。

Example of Retina/HiDPI mercator tiles (512x512px) available as XYZ.
The ol.source.XYZ must contain tilePixelRatio parameter. The tiles were prepared from a GeoTIFF file with MapTiler.

XYZ として利用できる Retina/HiDPI のメルカトルタイル(512x512px)の例。
ol.source.XYZ は tilePixelRatio パラメータが含まれている必要があります。タイルは MapTiler とともに GeoTIFF のファイルから準備しました。


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





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





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



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








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











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

「2108-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.4.0/css/ol.css" type="text/css">
  <link rel="stylesheet" href="v3.4.0/resources/bootstrap/css/bootstrap.min.css" type="text/css">
  <link rel="stylesheet" href="v3.4.0/resources/layout.css" type="text/css">
  <link rel="stylesheet" href="v3.4.0/resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
  <title>XYZ Retina tiles example</title>
 </head>
 <body>
  <!-- 
  bootstrap.min.css, bootstrap-responsive.min.css 
   Examples用 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.4.0/examples/"><img src="v3.4.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">XYZ Retina tiles example</h4>
     <p id="shortdesc">Example of Retina / HiDPI 
      mercator tiles (512x512px) available as XYZ.</p>
     <div id="docs">
      <p>The ol.source.XYZ must contain 
      <code>tilePixelRatio</code> parameter. The tiles 
      were prepared from a GeoTIFF file with 
      <a href="http://www.maptiler.com/">MapTiler</a>.</p>
      <!--
      <p>See the <a href="xyz-retina.js" target="_blank">xyz-retina.js source</a> for details on how this is done.</p>
      -->
      <!-- ファイル修正 -->
      <p>See the <a href="2108-ol3ex.js" target="_blank">2108-ol3ex.js source</a> for details on how this is done.</p>
     </div>
     <div id="tags">retina, hidpi, xyz, maptiler, @2x, 
      devicePixelRatio</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.4.0/resources/jquery.min.js" type="text/javascript"></script>
  <script src="v3.4.0/resources/example-behaviour.js" type="text/javascript"></script>
  <!--
  <script src="loader.js?id=xyz-retina" type="text/javascript"></script>
  -->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=2108-ol3ex" type="text/javascript"></script>
  </body>
</html>