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

2015年3月19日木曜日

2 - ol3.3ex 90b - Symbols with WebGL example 2

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

「290-ol3ex.js」
var atlasManager = new ol.style.AtlasManager({
/** ol.style.AtlasManager(opt_options)
 * Manages the creation of image atlases.
 * Images added to this manager will be inserted into 
 * an atlas, which will be used for rendering. The 
 * size given in the constructor is the size for the 
 * first atlas. After that, when new atlases are 
 * created, they will have twice the size as the 
 * latest atlas (until maxSize is reached).
 * If an application uses many images or very large 
 * images, it is recommended to set a higher size 
 * value to avoid the creation of too many atlases.
 * 画像アトラスの作成を管理します。
 * このマネージャに追加された画像は、レンダリングするために
 * 使用されるアトラス内に挿入されます。コンストラクタで指定
 * されたサイズは、最初のアトラスのためのサイズです。その後、
 * 新しいアトラスが作成されたとき、それらは、(maxSize に
 * 到達するまで)最後のアトラスの倍のサイズがあります。
 * アプリケーションが多くの画像または非常に大きな画像を使用
 * している場合、あまりにも多くのアトラスの作成を避けるため
 * に、より高いサイズの値を設定することを推奨します。
 * (ol3 API[説明は Stable Only のチェックを外すと表示])
 */
 /** we increase the initial size so that all symbols 
  * fit into a single atlas image.
  * すべてのシンボルが単一のアトラス画像に修めるために、初期
  * サイズを増やします。
  */
 initialSize: 512
});
var symbolInfo = [{
 opacity: 1.0,
 scale: 1.0,
 fillColor: 'rgba(255, 153, 0, 0.4)',
 strokeColor: 'rgba(255, 204, 0, 0.2)'
}, {
 opacity: 0.75,
 scale: 1.25,
 fillColor: 'rgba(70, 80, 224, 0.4)',
 strokeColor: 'rgba(12, 21, 138, 0.2)'
}, {
 opacity: 0.5,
 scale: 1.5,
 fillColor: 'rgba(66, 150, 79, 0.4)',
 strokeColor: 'rgba(20, 99, 32, 0.2)'
}, {
 opacity: 1.0,
 scale: 1.0,
 fillColor: 'rgba(176, 61, 35, 0.4)',
 strokeColor: 'rgba(145, 43, 20, 0.2)'
}];

var radiuses = [3, 6, 9, 15, 19, 25];
var symbolCount = symbolInfo.length * radiuses.length * 2;
var symbols = [];
var i, j;
for (i = 0; i < symbolInfo.length; ++i) {
 var info = symbolInfo[i];
 for (j = 0; j < radiuses.length; ++j) {
  // circle symbol
  symbols.push(new ol.style.Circle({
  /** push(elem)
   * Insert the provided element at the end of the 
   * collection.
   * コレクションの最後に供給されたエレメントに挿入します。
   * Name: elem, Type: T, Description: Element
   * (ol3 API)
   */
  /** ol.style.Circle
   * Set circle style for vector features.
   * ベクタフィーチャの円のスタイルを設定。(ol3 API)
   */
   opacity: info.opacity,
   scale: info.scale,
   radius: radiuses[j],
   fill: new ol.style.Fill({
   /** ol.style.Fill 
    * Set fill style for vector features.
    * ベクタフィーチャの塗りつぶしスタイルを設定。(ol3 API)
    */
    color: info.fillColor
   }),
   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: info.strokeColor,
    width: 1
   }),
   /** by passing the atlas manager to the symbol,
    * the symbol will be added to an atlas.
    * シンボルにアトラスマネージャを通すことによって、
    * シンボルはアトラスに追加されます。
    */
   atlasManager: atlasManager
  }));
  // star symbol
  symbols.push(new ol.style.RegularShape({
  /** ol.style.RegularShape
   * Set regular shape style for vector features. The 
   * resulting shape will be a regular polygon when 
   * radius is provided, or a star when radius1 and 
   * radius2 are provided.
   * ベクタフィーチャの規則的な形状のスタイルを設定します。生じた
   * 形状は、radius が提供されたとき正多角形になり、または、
   * radius1 と radius2 が提供されたとき星形になります。
   * (ol3 API)
   */
   points: 8,
   /** points:
    * Number of points for stars and regular polygons. 
    * In case of a polygon, the number of points is 
    * the number of sides.
    * 星形と正多角形の点の数。ポリゴンの場合、点の数は辺の数です。
    * (ol3 API[説明は Stable Only のチェックを外すと表示])
    */
   opacity: info.opacity,
   scale: info.scale,
   radius: radiuses[j],
   /** radius:
    * Radius of a regular polygon.
    *(ol3 API[説明は Stable Only のチェックを外すと表示])
    */
   radius2: radiuses[j] * 0.7,
   /** radius2:
    * Outer radius of a star.
    *(ol3 API[説明は Stable Only のチェックを外すと表示])
    */
   angle: 1.4,
   /** angle:
    * Shape's angle in radians. A value of 0 will 
    * have one of the shape's point facing up. 
    * Default value is 0.
    * ラジウス単位の形状の角度。値 0 は、表を上にした一つの
    * 形状の点です。デフォル値は 0 です。
    * (ol3 API[説明は Stable Only のチェックを外すと表示])
    */
   fill: new ol.style.Fill({
   // Fill style.(ol3 API)
    color: info.fillColor
   }),
   stroke: new ol.style.Stroke({
   // Stroke style.(ol3 API)
    color: info.strokeColor,
    width: 1
   }),
   atlasManager: atlasManager
  }));
 }
}
var featureCount = 50000;
var features = new Array(featureCount);
/** Array(arraylength)
 * JavaScript は配列を扱うことができます。配列とは順序を持つ複数
 * のデータの集合であり、JavaScript のグローバルオブジェクトであ 
 * る Array は、高位の、(C言語等で云うところの)「リスト」の様
 * な、配列のコンストラクタです。
 * arraylength
 * Array コンストラクタに渡される唯一の引数(arrayLength)に 0 
 * から 4,294,967,295( 232-1 ) までの整数値を指定する場合は、そ
 * の値を要素数とする配列が作成されます。その際に範囲外の値を指
 * 定した場合には、例外: RangeError がスローされます。
 * (MDN[https://developer.mozilla.org/ja/docs/Web/
 * JavaScript/Reference/Global_Objects/Array])
 */
var feature, geometry;
var e = 25000000;
for (i = 0; i < featureCount; ++i) {
 geometry = new ol.geom.Point(
 /** ol.geom.Point
  * Point geometry.(ol3 API)
  */
  [2 * e * Math.random() - e, 2 * e * Math.random() - e]);
  /** Math.random()
   * The Math.random() function returns a floating-point, 
   * pseudo-random number in the range [0, 1) that is, 
   * from 0 (inclusive) up to but not including 1 
   * (exclusive), which you can then scale to your 
   * desired range. The implementation selects the 
   * initial seed to the random number generation 
   * algorithm; it cannot be chosen or reset by the 
   * user.
   * Math.random() 関数は浮動小数点を返し、0 と 1 の範囲の
   * 擬似乱数、すなわち 0 以上 1 未満、で、任意の範囲に合わせ
   * ることができます。インプリメンテーションは、乱数発生アル
   * ゴリズムのためにイニシャルシードを選択しますが、ユーザが
   * 選んだりリセットできません。
   * (MDN[https://developer.mozilla.org/en-US/docs/Web/
   * JavaScript/Reference/Global_Objects/Math/random])
   */
 feature = new ol.Feature(geometry);
 /** ol.Feature
  * A vector object for geographic features with a geometry 
  * and other attribute properties, similar to the features 
  * in vector file formats like GeoJSON.
  * GeoJSONのようなベクトルファイル形式のフィーチャに類似した、
  * ジオメトリとその他の属性プロパティを持つ地物フィーチャのため
  * のベクトルオブジェクト。(ol3 API)
  */
 feature.setStyle(
 /** setStyle
  * Set the style for the feature. This can be a 
  * single style object, an array of styles, or a 
  * function that takes a resolution and returns an 
  * array of styles. If it is null the feature has 
  * no style (a null style).
  * フィーチャのスタイルを設定します。これは、単一のスタイル
  * オブジェクト、スタイルの配列、または、解像度を取りスタイ
  * ルの配列を返す関数とすることができます。それが null の
  * 場合フィーチャは、スタイル(ヌルスタイル)を持っていませ
  * ん。(ol3 API)
  */
  new ol.style.Style({
  /** ol.style.Style 
   * Base class for vector feature rendering styles.
   * ベクタフィーチャがスタイルを描画するための基本クラス。
   * (ol3 API)
   */
   image: symbols[i % symbolCount]
   /** %(モジュロ)
    * 二項演算子です。2 つのオペランドで除算したときの、整数の余
    * りを返します。
    * (MDN[https://developer.mozilla.org/ja/docs/Web/
    * JavaScript/Guide/Expressions_and_Operators])
    */
  })
 );
 features[i] = feature;
}
var vectorSource = new ol.source.Vector({
/*: ol.source.Vector 
 * Provides a source of features for vector layers.
 * ベクタレイヤのフィーチャのソースを提供します。(ol3 API)
 */
 features: features
});
var vector = new ol.layer.Vector({
  source: vectorSource
});

// Use the "webgl" renderer by default.
var renderer = exampleNS.getRendererFromQueryString();
/** 'example-behavior.js' により URL にある renderer を返します */
if (!renderer) {
 renderer = 'webgl';
}

var map = new ol.Map({
 renderer: renderer,
 layers: [vector],
 target: document.getElementById('map'),
 view: new ol.View({
  center: [0, 0],
  zoom: 4
 })
});

2 - ol3.3ex 90a - Symbols with WebGL example 1

「Symbols with WebGL example (symbol-atlas-webgl.html)」を参考に地図を表示してみます。
説明に次のようにあります。

When using symbol styles with WebGL, OpenLayers would render the symbol on a temporary image and would create a WebGL texture for each image. For a better performance, it is recommended to use atlas images (similar to image sprites with CSS), so that the number of textures is reduced. OpenLayers provides an AtlasManager, which when passed to the constructor of a symbol style, will create atlases for the symbols.
WebGL のシンボルのスタイルを使用する場合は、OpenLayers は、一時的な画像上にシンボルを描画し、各画像のWebGLのテクスチャを作成します。パフォーマンスを向上させるためには、テクスチャの数が減少するように、(CSSの画像スプライトと同様)アトラスイメージを使用することを推奨します。 OpenLayers は、シンボルスタイルのコンストラクタに渡されたときに、シンボルのアトラスを作成する AtlasManager を提供します。


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





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





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



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








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











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


「290-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.3.0/css/ol.css" type="text/css">
  <link rel="stylesheet" href="v3.3.0/resources/bootstrap/css/bootstrap.min.css" type="text/css">
  <link rel="stylesheet" href="v3.3.0/resources/layout.css" type="text/css">
  <link rel="stylesheet" href="v3.3.0/resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
  <title>Symbols with WebGL 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.3.0/examples/"><img src="v3.3.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">Symbols with WebGL example</h4>
     <p id="shortdesc">Using symbols in an atlas with WebGL.</p>
     <div id="docs">
      <p>When using symbol styles with WebGL, OpenLayers 
       would render the symbol on a temporary image and would 
       create a WebGL texture for each image. For a better 
       performance, it is recommended to use atlas images 
       (similar to image sprites with CSS), so that the 
       number of textures is reduced. OpenLayers provides an 
       <code>AtlasManager</code>, which when 
       passed to the constructor of a symbol style, will 
       create atlases for the symbols.</p>
      <!--
      <p>See the <a href="symbol-atlas-webgl.js" target="_blank">symbol-atlas-webgl.js source</a> 
       to see how this is done.</p>
      -->
      <!-- ファイル修正 -->
      <p>See the <a href="290-ol3ex.js" target="_blank">290-ol3ex.js source</a> 
       to see how this is done.</p>
     </div>
     <div id="tags">webgl, symbol, atlas, vector, point</div>
    </div>
   </div>
  </div>
  <!--
  <script src="../resources/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.3.0/resources/jquery.min.js" type="text/javascript"></script>
  <script src="v3.3.0/resources/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
  <script src="v3.3.0/resources/example-behaviour.js" type="text/javascript"></script>
  <!--
  <script src="loader.js?id=symbol-atlas-webgl" type="text/javascript"></script>
  -->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=290-ol3ex" type="text/javascript"></script>
 </body>
</html>