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

2015年3月4日水曜日

2 - ol3.2ex 76b - Regular Shape example 2

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

「276-ol3ex.js」
var stroke = new ol.style.Stroke({color: 'black', width: 2});
/** 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)
 */
var fill = new ol.style.Fill({color: 'red'});
/** ol.style.Fill 
 * Set fill style for vector features.
 * ベクタフィーチャの塗りつぶしスタイルを設定。(ol3 API)
 */
var styles = {
 'square': [new ol.style.Style({
 /** ol.style.Style 
  * Base class for vector feature rendering styles.
  * ベクタフィーチャがスタイルを描画するための基本クラス。
  * (ol3 API)
  */
  image: 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)
   */

  /** @type {olx.style.RegularShapeOptions} */({
   /** @type 
    * 値のタイプ(型)の説明 - 式などで表示
    * (@use JSDoc[http://usejsdoc.org/]より)
    */
    fill: fill,
    stroke: stroke,
    points: 4,
    /** 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 のチェックを外すと表示])
     */
    radius: 10,
    /** radius:
     * Radius of a regular polygon.
     * (ol3 API[説明は Stable Only のチェックを外すと表示]l
     */
    angle: Math.PI / 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 のチェックを外すと表示])
     */
    /** Math.PI()
     * 円周率。約 3.14159 です。
     * (MDN[https://developer.mozilla.org/ja/docs/Web
     * /JavaScript/Reference/Global_Objects/Math/PI])
     */
  }))
 })],
 'triangle': [new ol.style.Style({
  image: new ol.style.RegularShape(
   /** @type {olx.style.RegularShapeOptions} */({
    fill: fill,
    stroke: stroke,
    points: 3,
    radius: 10,
    rotation: Math.PI / 4,
    /** rotation:
     * Rotation in radians (positive rotation 
     * clockwise). Default is 0.
     * ラジウス単位の回転(時計回り)。デフォルトは 0 。
     */
    angle: 0
  }))
 })],
 'star': [new ol.style.Style({
  image: new ol.style.RegularShape(
   /** @type {olx.style.RegularShapeOptions} */({
    fill: fill,
    stroke: stroke,
    points: 5,
    radius: 10,
    radius2: 4,
    /** radius2:
     * Outer radius of a star.
     *(ol3 API[説明は Stable Only のチェックを外すと表示])
     */
    angle: 0
  }))
 })],
 'cross': [new ol.style.Style({
  image: new ol.style.RegularShape(
   /** @type {olx.style.RegularShapeOptions} */({
    fill: fill,
    stroke: stroke,
    points: 4,
    radius: 10,
    radius2: 0,
    angle: 0
  }))
 })],
 'x': [new ol.style.Style({
  image: new ol.style.RegularShape(
   /** @type {olx.style.RegularShapeOptions} */({
    fill: fill,
    stroke: stroke,
    points: 4,
    radius: 10,
    radius2: 0,
    angle: Math.PI / 4
  }))
 })]
};

var styleKeys = ['x', 'cross', 'star', 'triangle', 'square'];
var count = 250;
var features = new Array(count);
/** 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 e = 4500000;
for (var i = 0; i < count; ++i) {
 var coordinates = [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])
    */
 features[i] = new ol.Feature(new ol.geom.Point(coordinates));
 /** 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)
  */
 /** ol.geom.Point
  * Point geometry.(ol3 API)
  */
 features[i].setStyle(styles[styleKeys[Math.floor(Math.random() * 5)]]);
 /** 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)
  */
 /** Math.floor()
  * The Math.floor() function returns the largest 
  * integer less than or equal to a given number.
  * Math.floor() 関数は、指定された数以下の最大の整数、
  * または、等しい数を返します。
  * (MDN[https://developer.mozilla.org/en-US/docs/Web/
  * JavaScript/Reference/Global_Objects/Math/floor])
  */
}
var source = new ol.source.Vector({
 /*: ol.source.Vector 
  * Provides a source of features for vector layers.
  * ベクタレイヤのフィーチャのソースを提供します。(ol3 API)
  */
 features: features
});
var vectorLayer = new ol.layer.Vector({
/** ol.layer.Vector
 * Vector data that is rendered client-side.
 * クライアント側で描画されたベクタデータ。(ol3 API)
 */
 source: source
});
var map = new ol.Map({
 layers: [
  vectorLayer
 ],
 target: 'map',
 view: new ol.View({
  center: [0, 0],
  zoom: 2
 })
});

2 - ol3.2ex 76a - Regular Shape example 1

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

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





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





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



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








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











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


「276-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.2.1/css/ol.css" type="text/css">
  <link rel="stylesheet" href="v3.2.1/resources/bootstrap/css/bootstrap.min.css" type="text/css">
  <link rel="stylesheet" href="v3.2.1/resources/layout.css" type="text/css">
  <link rel="stylesheet" href="v3.2.1/resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
  <title>Regular Shape 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.2.1/examples/"><img src="v3.2.1/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">Regular Shape example</h4>
     <p id="shortdesc">Example of some Regular Shape styles.</p>
     <div id="docs">
      <!--
      <p>See the <a href="regularshape.js" target="_blank">regularshape.js source</a> to see how this is done.</p>
      -->
      <!-- ファイル修正 -->
      <p>See the <a href="276-ol3ex.js" target="_blank">276-ol3ex.js source</a> to see how this is done.</p>
     </div>
     <div id="tags">vector, symbol, regularshape, style, square, cross, star, triangle, x</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.2.1/resources/jquery.min.js" type="text/javascript"></script>
  <script src="v3.2.1/resources/example-behaviour.js" type="text/javascript"></script>
  <!--
  <script src="loader.js?id=regularshape" type="text/javascript"></script>
  -->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=276-ol3ex" type="text/javascript"></script>
 </body>
</html>