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

2018年11月30日金曜日

ol5.3ex 1 - Simple Map

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

A simple map with an OSM source.

OSM ソースを使用したシンプル(単純な)マップ。

次の内容で index.js と index.html を作成します。(テストで使ったファイルの内容と同じです。)
user@deb9-vmw:~/new-project$ vim index.js
import 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';
const map = new Map({
/** const[JavaScript]
 * Constants are block-scoped, much like variables defined 
 * using the let statement. The value of a constant cannot 
 * change through reassignment, and it can't be redeclared.
 * 定数(const)はブロックスコープで、let ステートメントを
 * 使用して定義された変数にとても似ています。定数の値は、再
 * 代入による変更はできず、再宣言されません。
 * (MDN[https://developer.mozilla.org/en-US/docs/Web/
 * JavaScript/Reference/Statements/const])
 */
/** Map[ol/Map]
 * The map is the core component of OpenLayers. For a map 
 * to render, a view, one or more layers, and a target 
 * container are needed:
 * map(マップ)は、OpenLayers のコアコンポーネントです。
 * map を描画するために、view(ビュー)と1つ以上の layers
 * (レイヤ)と target(ターゲット)コンテナが必要です:
 * (ol5 API)
 */
 target: 'map',
 /** target[new Map(options)]
  * The container for the map, either the element itself 
  * or the id of the element. If not specified at 
  * construction time, module:ol/Map~Map#setTarget must 
  * be called for the map to be rendered.
  * map のコンテナ、(HTML)エレメント自身、またはエレメント
  * の id。構築時に指定されていない場合、描画される map のた
  * めにモジュール:ol/Map~Map#setTarget が呼び出されなけれ
  * ばなりません。
  * (ol5 API)
  */
 layers: [
 /** layers[new Map(options)]
  * Layers. If this is not defined, a map with no layers 
  * will be rendered. Note that layers are rendered in 
  * the order supplied, so if you want, for example, a 
  * vector layer to appear on top of a tile layer, it 
  * must come after the tile layer.
  * layers(レイヤ)。これが定義されていない場合、layers のな
  * い map が描画されます。layers は提供される順番で描画され、
  * もし、例えば、タイルレイヤの上部にベクタレイヤを表示したい
  * なら、タイルレイヤの後に来なければなりません。
  * (ol5 API)
  */
  new TileLayer({
   source: new OSM()
  })
 ],
 view: new View({
 /** view[new Map(options)]
  * The map's view. No layer sources will be fetched unless
  * this is specified at construction time or through 
  * module:ol/Map~Map#setView.
  * map(マップ)の view(ビュー)。これが構築時に指定されてい
  * ないか、モジュール:ol/Map~Map#setView を通じてなければ、
  * 取るレイヤソースはありません。
  * (ol5 API)
  */
 /** View(ol/View)
  * A View object represents a simple 2D view of the map.
  * This is the object to act upon to change the center, 
  * resolution, and rotation of the map.
  * View(ビュー)オブジェクトは、map(マップ)の 単純な 2D 
  * view を表示します。
  * これは、map の center(中心)、resolution(解像度)、
  * rotation (回転)を変換を実行するためのオブジェクトです。
  * (ol5 API)
  */
  center: [0, 0],
  /** center[new View(opt_options)]
   * The initial center for the view. The coordinate system 
   * for the center is specified with the projection option. 
   * Layer sources will not be fetched if this is not set, 
   * but the center can be set later with #setCenter.
   * view(ビュー)の初期 center(中心)値。 center の座標系
   * は、projection(投影法)オプションで指定されます。これが
   * 設定されなければレイヤソースは取得されませんが、center は 
   * #setCenter で後で設定できます。
   * (ol5 API)
   */
  zoom: 2
  /** zoom[new View(opt_options)]
   * Only used if resolution is not defined. Zoom level used 
   * to calculate the initial resolution for the view. The 
   * initial resolution is determined using the 
   * #constrainResolution method.
   * resolution(解像度)が定義されていない場合のみ使用されま
   * す。view の初期 resolution(解像度)を計算するために使用
   * される zoom(ズーム)レベル。初期 resolution は、
   * #constrainResolution メソッドを使用して決定されます。
   * (ol5 API)
   */
 })
});

user@deb9-vmw:~/new-project$ vim index.html
<!doctype html>
<html>
 <head>
  <meta charset="utf-8">
  <title>Simple Map</title>
  <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
  <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
 </head>
 <body>
  <div id="map"></div>
  <script src="./index.js"></script>
 <body>
</html>
npm start を実行します。
user@deb9-vmw:~/new-project$ npm start
> new-project@1.0.0 start /home/user/ol5-examples01

> parcel index.html

Server running at http://localhost:1234

✨  Built in 16.23s.

Webブラウザのアドレス欄に

http://localhost:1234

と入力して Enter キーを押します。


2014年10月22日水曜日

2 - ol3ex 18b - Simple example 2

「simple.js(218-ol3ex.js)」は、地図を表示するのに必要な javascript です。「218-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)
    */
  })
 ],
 controls: ol.control.defaults({
 /** ol.control.defaults()
  * デフォルトでは、マップに含まコントロールのセット。
  * 特に設定しない限り、これは、以下の各コントロールの
  * インスタンスを含むコレクションを返します。(API Doc より)
  * ol.control.Zoom, ol.control.Rotate, ol.control.Attribution
  */
  attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
  /** @type 
   * 値のタイプ(型)の説明 - 式などで表示
   * attributionOptions の値の型は、
   * olx.control.AttributionOptions の型を使用。
   * (@use JSDoc[http://usejsdoc.org/]より)
   */
   collapsible: false // 折りたたみ
  })
 }),
 renderer: exampleNS.getRendererFromQueryString(),
 // 'example-behavior.js' により URL にある renderer を返します
 target: 'map',
 view: new ol.View({
  center: [0, 0],
  zoom: 2
 })
});

2 - ol3ex 18a - Simple example 1

Workshop に合わせてExamples をやってみましたが、他のものも試してみます。 「Simple example(simple.html)」を参考に地図を表示してみます。

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





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





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



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








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











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


「218-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>Simple 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.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">Simple example</h4>
     <p id="shortdesc">Example of a simple map.</p>
     <div id="docs">
<!--
      <p>See the <a href="simple.js" target="_blank">simple.js source</a> to see how this is done.</p>
-->
       <!-- ファイル修正 -->
      <p>See the <a href="218-ol3ex.js" target="_blank">218-ol3ex.js source</a> to see how this is done.</p>
     </div>
     <div id="tags">simple, openstreetmap</div>
    </div>
   </div>
  </div>
<!--
  <script src="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.0.0/examples/jquery.min.js" type="text/javascript"></script>
  <script src="v3.0.0/resources/example-behaviour.js" type="text/javascript"></script>
<!--
  <script src="loader.js?id=simple" type="text/javascript"></script>
-->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=218-ol3ex" type="text/javascript"></script>

 </body>
</html>