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

2015年10月18日日曜日

OL3-Cesium 13 - ol3cesium lazy initialization 2

13-2 JavaScript ファイルの作成
「lazy.js(13-ol3cesium18.js)」は、マップを表示するための JavaScript ファイルです。

OL3-Cesium API は、現在、すべて実験的(experimental)なものです。

「13-ol3cesium18.js」
var ol2d = 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)
    */
  })
 ],
 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 // 折りたたみ
  })
 }),
 target: 'map',
 view: new ol.View({
  center: ol.proj.transform([25, 20], '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)
   */
  zoom: 3
 })
});

var ol3d;

function _doToggle() {
 ol3d.setEnabled(!ol3d.getEnabled());
 /** setEnabled(enable)
  * Enables/disables the Cesium. This modifies the 
  * visibility style of the container element.
  * セシウムを有効または無効にします。これは、コンテナ要素の可視
  * 性スタイルを変更します。
  * (OL3-Cesium API)
  */
 /** getEnabled()
  * (OL3-Cesium API に説明がありませんでした。)
  */
}
function toggle3D() {
 if (!ol3d) {
  var s = document.createElement("script");
  /** document.createElement
   * 指定の要素名の要素を生成します。
   * (MDN[https://developer.mozilla.org/ja/docs/Web/
   * API/document.createElement)
   */
  s.type = "text/javascript";
  // s.src = "../Cesium/Cesium.js";
  s.src = "./js/libs/ol3-cesium-v1.8/Cesium/Cesium.js";
  console.log('loading Cesium...');
  s.onload = function() {
  /** window.onload
   * window の load イベントに対応するイベントハンドラです。
   * (MDN[https://developer.mozilla.org/ja/docs/Web/API/
   * GlobalEventHandlers/onload])
   */
   init3D();
   _doToggle();
  };
  document.body.appendChild(s);
  /** Node.appendChild
   * 特定の親ノードの子ノードリストの末尾にノードを追加します。
   * 追加しようとしたノードが既に存在していたら、それは現在の
   * 親ノードから除かれ、新しい親ノードに追加されます。
   * (MDN[https://developer.mozilla.org/ja/docs/Web/
   * API/Node.appendChild])
   */
 } else {
  _doToggle();
 }
}
function init3D() {
 ol3d = new olcs.OLCesium({map: ol2d});
 /** new olcs.OLCesium(options)
  * map: The OpenLayers map we want to show on a Cesium 
  * scene.
  * Cesium シーンで表示したい OpenLayers マップ。
  * (OL3-Cesium API)
  */
 var scene = ol3d.getCesiumScene();
 /** getCesiumScene()
  * (OL3-Cesium API に説明がありませんでした。)
  */
 var terrainProvider = new Cesium.CesiumTerrainProvider({
 /** new CesiumTerrainProvider(options)
  * A TerrainProvider that access terrain data in a Cesium 
  * terrain format. The format is described on the Cesium 
  * wiki. 
  * セシウム地形(Cesium terrain)フォーマットの地形(terrain)
  * データにアクセスする TerrainProvider。フォーマットは、セシウ
  * ムウィキに記載されています。
  * (Cesium refdoc)
  */
  // url : '//cesiumjs.org/stk-terrain/tilesets/world/tiles'
  // 2015.10.2 変更
  url : '//assets.agi.com/stk-terrain/world'
  /** url
   * The URL of the Cesium terrain server.
   * セシウム地形(Cesium terrain)サーバの URL。
   * (Cesium refdoc)
   */
 });
 scene.terrainProvider = terrainProvider;
}
Chromium では表示できないので、Iceweasel(Firefox)のアドレスバーに

http://localhost/~user/ol3cesiumproj/public_html/13-ol3cesium18.html

と入力して表示します。

OL3-Cesium 13 - ol3cesium lazy initialization 1

OL3-Cesium Examples
http://openlayers.org/ol3-cesium/examples/

の例をみていきます。

13 - ol3cesium lazy initialization
「ol3cesium lazy initialization(lazy.html)」を参考に地図を表示してみます。
説明に次のようにあります。

Delay downloading the Cesium script and initializing the 3D globe.
This is an experimental feature.セシウムのスクリプトをダウンロードしと 3D 地球儀の初期化を遅らせます。
これは実験的な機能です。

13-1 HTML ファイルの作成
1 NetBeans を起動します。









2 「プロジェクト」ペインでツリーを ol3cesiumproj -> サイト・ルート -> js -> libs -> ol3-cesium-v1.8 -> examples とクリックして展開し lazy.html をダブルクリックして開きます。lazy.js もダブルクリックして開きます。



3 「新規ファイル」ボタンをクリックします。

4 ステップ「1.ファイル・タイプを選択」の「カテゴリ」で「HTML5」、「ファイルタイプ」で「HTMLファイル」を選択して「次>」ボタンをクリックします。






5 「new HTML ファイル」ダイアログで「ファイル名」を「13-ol3cesium18」と入力して「終了」ボタンをクリックします。







保存フォルダを変更するときは、「フォルダ」右の「参照」ボタンをクリックして「フォルダを参照」で「ol3cesiumproj-サイト・ルート」をクリックして選択し「フォルダを選択」ボタンをクリックします。









6 「lazy.html」の内容をコピーして「13-ol3cesium18.html」に貼り付け、修正します。

7 同じように、「新規ファイル」ボタンをクリックし、ステップ「1.ファイル・タイプを選択」の「カテゴリ」で「HTML5」、「ファイルタイプ」で「JavaScriptファイル」をクリックして選択し「次>」ボタンをクリック。「ファイル名」を「13-ol3cesium18」と入力して「終了」ボタンをクリック。「lazy.js」の内容をコピーして貼り付け、修正します。



「index.html」
<html>
 <head>
  <title>TODO supply a title</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
 </head>
 <body>
  <div>TODO write content</div>
  <div><a href="./3-ol3cesium17.html">3-ol3cesium17.html</a></div>
  <div><a href="./4-ol3cesium17.html">4-ol3cesium17.html</a></div>
  <div><a href="./5-ol3cesium17.html">5-ol3cesium17.html</a></div>
  <div><a href="./6-ol3cesium17.html">6-ol3cesium17.html</a></div>
  <div><a href="./7-ol3cesium17.html">7-ol3cesium17.html</a></div>
  <div><a href="./8-ol3cesium17.html">8-ol3cesium17.html</a></div>
  <div><a href="./9-ol3cesium17.html">9-ol3cesium17.html</a></div>
  <div><a href="./10-ol3cesium17.html">10-ol3cesium17.html</a></div>
  <div><a href="./11-ol3cesium17.html">11-ol3cesium17.html</a></div>
  <div><a href="./12-ol3cesium17.html">12-ol3cesium17.html</a></div>
  <div><a href="./13-ol3cesium18.html">13-ol3cesium18.html</a></div>
 </body>
</html>


「13-ol3cesium18.html」
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="robots" content="index, all" />
  <title>ol3cesium lazy initialization</title>
  <!-- ディレクトリ修正
  <link rel="stylesheet" href="../ol3/css/ol.css" type="text/css">
  -->
  <link rel="stylesheet" href="./js/libs/ol3-cesium-v1.8/ol3/css/ol.css" type="text/css">
 </head>
 <body>
  <div>Delay downloading the Cesium script and initializing 
   the 3D globe.</div>
  <div>This is an experimental feature.</div>
  <div id="map" style="width:600px;height:400px;float:left;"></div>
  <input type="button" value="Enable/disable 3D" onclick="javascript:toggle3D()" />
  <!-- ディレクトリ修正
  <script src="../ol3/ol-debug.js"></script>
  <script src="../Cesium/Cesium.js"></script>
  <script src="../ol3cesium.js"></script>
  -->
  <script src="./js/libs/ol3-cesium-v1.8/ol3/ol-debug.js"></script>
  <script src="./js/libs/ol3-cesium-v1.8/Cesium/Cesium.js"></script>
  <script src="./js/libs/ol3-cesium-v1.8/ol3cesium.js"></script>
  <!-- <script src="lazy.js"></script> -->
  <script src="13-ol3cesium18.js"></script>
 </body>
</html>