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

2015年10月14日水曜日

2 - ol3.10ex 131b - JSTS example 2

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

「2131-ol3ex.js」
var source = new ol.source.Vector();
/** ol.source.Vector
 * Provides a source of features for vector layers.
 * ベクタレイヤのフィーチャのソースを用意します。(ol3 API)
 */
// $.ajax('data/geojson/roads-seoul.geojson').then(function(response) {
$.ajax('v3.10.1/examples/data/geojson/roads-seoul.geojson').then(function(response) {
/** jQuery.ajax( url [, settings ] )
 * Perform an asynchronous HTTP (Ajax) request.
 * 非同期HTTP(Ajax)要求を実行します。
 * (jQuery[http://api.jquery.com/jQuery.ajax/])
 */
 var format = new ol.format.GeoJSON();
 /** ol.format.GeoJSON 
  * Feature format for reading and writing data in the 
  * GeoJSON format.
  * GeoJSON フォーマットのデータを読み書きするためのフィーチャ
  * フォーマット。(ol3 API)
  */
 var features = format.readFeatures(response,
  {featureProjection: 'EPSG:3857'});
 /** readFeatures(source, opt_options)
  * Read all features from a GeoJSON source.
  * Works with both Feature and FeatureCollection 
  * sources.
  * GeoJSON ソースからすべてのフィーチャを読み取ります。
  * フィーチャとフィーチャコレクションソースの両方で動作し
  * ます。
  * (ol3 API)
  */
 var parser = new jsts.io.olParser();
 /** jsts.io.olParser()
  * 
  */
 for (var i = 0; i < features.length; i++) {
  var feature = features[i];
  // convert the OpenLayers geometry to a JSTS geometry
  // OpenLayers ジオメトリを JSTS ジオメトリへ変換
  var jstsGeom = parser.read(feature.getGeometry());
  /** read()
   *  
   */
  /** getGeometry()
   * Get the feature's default geometry. A feature may have 
   * any number of named geometries. The "default" geometry 
   * (the one that is rendered by default) is set when 
   * calling ol.Feature#setGeometry.
   * フィーチャのデフォルトのジオメトリを取得します。フィーチャ
   * は、任意の数の指定のジオメトリのを有することができます。 
   * 「デフォルト」のジオメトリ(デフォルトでレンダリングされる
   * もの)が ol.Feature#setGeometry を呼び出すときに設定され
   * ています。(ol3 API)
   */
  // create a buffer of 40 meters around each line
  // 各線の周囲 40m のバッファを作成
  var buffered = jstsGeom.buffer(40);
  /** buffer()
   * 
   */
  // convert back from JSTS and replace the geometry on the 
  // feature
  // JSTS から変換し、フィーチャのジオメトリを置換する
  feature.setGeometry(parser.write(buffered));
  /** setGeometry()
   * Set the geometry for this feature. This will 
   * update the property with the current name 
   * returned by ol.Feature#getGeometryName. 
   * このフィーチャのジオメトリを設定します。これは、
   * ol.Feature#getGeometryName によって返された、現在の
   * 名前とともにプロパティを更新します。
   * (ol3 API)
   */
  /** write() 
   *  
   */
 }
 source.addFeatures(features);
 /** addFeatures(features)
  * Add a batch of features to the source.
  * フィーチャのバッチをソースに追加します。(ol3 API)
  */
});
var vectorLayer = new ol.layer.Vector({
/** ol.layer.Vector
 * Vector data that is rendered client-side.
 * クライアント側で描画されたベクタデータ。(ol3 API)
 */
 source: source
});
var rasterLayer = 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.MapQuest({
 /** ol.source.MapQuest
  * Layer source for the MapQuest tile server.
  * MapQuest タイルサーバのレイヤソース。(ol3 API
  * 2 - ol3ex 23b - MapQuest example 2 参照)
  */
  layer: 'osm'
 })
});
var map = new ol.Map({
 layers: [rasterLayer, vectorLayer],
 target: document.getElementById('map'),
 view: new ol.View({
  center: ol.proj.fromLonLat([126.979293, 37.528787]),
  /** ol.proj.fromLonLat(coordinate, opt_projection)
   * Transforms a coordinate from longitude/latitude to a 
   * different projection.
   * 緯度/経度座標から異なる投影に変換します。(ol3 API)
   */
  zoom: 15
 })
});

2 - ol3.10ex 131a - JSTS example 1

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

JSTS Topology Suite は、

bjornharrtell/jsts GitHub
https://github.com/bjornharrtell/jsts

に次のようにあります。

The JSTS Topology Suite is a JavaScript library of spatial predicates and functions for processing geometry conforming to the Simple Features Specification for SQL published by the Open Geospatial Consortium. JSTS Topology Suite is also a JavaScript port of the well established Java library JTS Topology Suite with a built in parser for OpenLayers geometries.

JSTS トポロジスイートは、Open Geospatial Consortium(OGC)のによって公開されたSQLのための Simple Features 仕様に準拠するジオメトリを処理するための空間述語と関数の JavaScript ライブラリです。 JSTS トポロジスイートは、OpenLayers ジオメトリのための組込みパーサでよく確立された Java ライブラリ JTS トポロジースイートの JavaScript のポートでもあります。

SWECO Position AB (my current employer) has gratiously provided sponsoring for this project.

SWECO Position AB(現在の雇用主)が、懇切丁寧にこのプロジェクトのために後援してきました。

The primary goal of the project is to provide OpenLayers applications with a complete library for processing and analysing simple geometries, but as of version 0.11.0 hard dependencies to OpenLayers was removed which makes it possible to use JSTS Topology Suite as a free standing geometry library.

プロジェクトの主な目的は、単純なジオメトリを処理や分析するための完全なライブラリとともに OpenLayers アプリケーションに提供することですが、OpenLayers と堅固な依存関係の 0.11.0 バージョンは、それが可能な自立ジオメトリライブラリとして JSTS Topology Suite を使用を可能にさせることが削除されました。


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





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





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



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








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











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

「2131-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="http://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" type="text/css">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-combined.min.css" type="text/css">
  <!--
  <link rel="stylesheet" href="../css/ol.css" type="text/css">
  <link rel="stylesheet" href="./resources/layout.css" type="text/css">

  <link rel="stylesheet" href="./resources/prism/prism.css" type="text/css">
  <script src="./resources/zeroclipboard/ZeroClipboard.min.js"></script>
  「resources」の位置が変わりました。
  -->
  <!-- ディレクトリ修正 -->
  <link rel="stylesheet" href="v3.10.1/css/ol.css" type="text/css">
  <link rel="stylesheet" href="v3.10.1/examples/resources/layout.css" type="text/css">

  <link rel="stylesheet" href="v3.10.1/examples/resources/prism/prism.css" type="text/css">
  <script src="v3.10.1/examples/resources/zeroclipboard/ZeroClipboard.min.js"></script>
  <script src="https://cdn.rawgit.com/bjornharrtell/jsts/gh-pages/lib/0.16.0/javascript.util.min.js"></script>
  <script src="https://cdn.rawgit.com/bjornharrtell/jsts/gh-pages/lib/0.16.0/jsts.min.js"></script>
  <title>JSTS example</title>
 </head>
 <body>
  <!-- 
  bootstrap-combined.min.css, ol.css, layout.css,
  CSSファイルで設定されたセレクタを使用。
  -->
  <header class="navbar" role="navigation">
   <div class="container" id="navbar-inner-container">
    <!--
    <a class="navbar-brand" href="./"><img src="./resources/logo-70x70.png"> OpenLayers 3 Examples</a>
    -->
    <!-- ディレクトリ修正 -->
    <a class="navbar-brand" href="v3.10.1/examples/"><img src="v3.10.1/examples/resources/logo-70x70.png"> OpenLayers 3 Examples</a>
   </div>
  </header>
  <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">JSTS example</h4>
     <p id="shortdesc">Example on how to use JSTS with 
      OpenLayers 3. </p>
     <div id="docs"><p>Example showing the integration of 
      <a href="https://github.com/bjornharrtell/jsts"<JSTS>/a> 
      with OpenLayers 3.</p>
     </div>
     <div id="tags">vector, jsts, buffer</div>
     <div id="api-links">Related API documentation: 
      <ul class="inline">
       <li>
        <!--<a href="../apidoc/ol.Feature.html" title="API documentation for ol.Feature">ol.Feature>/a> -->
        <a href="v3.10.1/apidoc/ol.Feature.html" title="API documentation for ol.Feature">ol.Feature</a>
       </li>,
       <li>
        <!--<a href="../apidoc/ol.Map.html" title="API documentation for ol.Map">ol.Map>/a> -->
        <a href="v3.10.1/apidoc/ol.Map.html" title="API documentation for ol.Map">ol.Map</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.View.html" title="API documentation for ol.View">ol.View>/a> -->
        <a href="v3.10.1/apidoc/ol.View.html" title="API documentation for ol.View">ol.View</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.format.GeoJSON.html" title="API documentation for ol.format.GeoJSON">ol.format.GeoJSON>/a> -->
        <a href="v3.10.1/apidoc/ol.format.GeoJSON.html" title="API documentation for ol.format.GeoJSON">ol.format.GeoJSON</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.layer.Tile.html" title="API documentation for ol.layer.Tile">ol.layer.Tile>/a> -->
        <a href="v3.10.1/apidoc/ol.layer.Tile.html" title="API documentation for ol.layer.Tile">ol.layer.Tile</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.layer.Vector.html" title="API documentation for ol.layer.Vector">ol.layer.Vector>/a> -->
        <a href="v3.10.1/apidoc/ol.layer.Vector.html" title="API documentation for ol.layer.Vector">ol.layer.Vector</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.proj.html" title="API documentation for ol.proj">ol.sproj>/a> -->
        <a href="v3.10.1/apidoc/ol.proj.html" title="API documentation for ol.proj">ol.proj</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.source.MapQuest.html" title="API documentation for ol.source.MapQuest">source.MapQuest>/a> -->
        <a href="v3.10.1/apidoc/ol.source.MapQuest.html" title="API documentation for ol.source.MapQuest">ol.source.MapQuest</a>
       </li>,
       <li>
        <!-- <a href="../apidoc/ol.source.Vector.html" title="API documentation for ol.source.Vector">ol.source.Vector>/a> -->
        <a href="v3.10.1/apidoc/ol.source.Vector.html" title="API documentation for ol.source.Vector">ol.source.Vector</a>
       </li>
      </ui>
     </div>
   </div>
  </div>
  <div class="row-fluid">
    <div id="source-controls">
     <a id="copy-button">
      <i class="fa fa-clipboard"></i> Copy
     </a>
     <a id="jsfiddle-button">
      <i class="fa fa-jsfiddle"></i> Edit
     </a>
    </div>
    <form method="POST" id="jsfiddle-form" target="_blank" action="http://jsfiddle.net/api/post/jquery/1.11.0/">
    <textarea class="hidden" name="js">
// --- 省略 ---
&lt;/html&gt;</code></pre>
   </div>
  </div>
  <script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <!--
  <script src="./resources/common.js"></script>
  <script src="./resources/prism/prism.min.js"></script>
  -->
  <!-- ディレクトリ修正
   CommonJS と
   prism.js
 -->
  <script src="v3.10.1/examples/resources/common.js"></script>
  <script src="v3.10.1/examples/resources/prism/prism.min.js"></script>
  <!-- 
  <script src="loader.js?id=jsts"></script>
  -->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=2131-ol3ex"></script>
  </body>
</html>


COMMONJS は

COMMONJS
http://webpack.github.io/docs/commonjs.html

に、次のようにあります。

The CommonJS group defined a module format to solve JavaScript scope issues by making sure each module is executed in its own namespace.
This is achieved by forcing modules to explicitly export those variables it wants to expose to the “universe”, and also by defining those other modules required to properly work.
To achieve this CommonJS give you two tools:
the require() function, which allows to import a given module into the current scope.
the module object, which allows to export something from the current scope.

CommonJSグループは、それ自身の名前空間内で実行されている各モジュールを確認することによって、JavaScriptのスコープ問題を解決するためのモジュールフォーマットを定義しました。
これは、それが「universe(?)」に公開したい変数を明示的にエクスポートするモジュールを強制することによって、同じように、正常に動作するのに必要な他のモジュールを定義することによって、達成されます。
この CommonJS を達成するために2つのツールを与えます:
require()関数、指定したモジュールを現在のスコープにインポートすることができます。
モジュールオブジェクト、現在のスコープからエクスポートすることができます。


Prism は、

Prism
http://prismjs.com/

に、次のようにあります。

Prism is a lightweight, extensible syntax highlighter, built with modern web standards in mind. It’s a spin-off from Dabblet and is tested there daily by thousands.
Prismは、最新のWeb標準に構築されたことを考慮し軽量で拡張可能なシンタックスハイライトです。それは Dabblet からスピンオフで、何千人も日々そこで試験されています。


ZeroClipboard は

ZeroClipboard v2.x
http://zeroclipboard.org/

に、次のようにあります。

The ZeroClipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie and a JavaScript interface.
ZeroClipboard ライブラリは、見えない Adobe Flash ムービーとJavaScript のインターフェイスを使用してテキストをクリップボードにコピーする簡単な方法を提供します。

Debian 8 では動作しませんでした。ボタンを右クリックしたときに flash のコンテキストメニューが表示されると動作しています。