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

2015年2月3日火曜日

2 - ol3.1ex 54b - Draw and modify features example 2

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

「254-ol3ex.js」
var raster = 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({layer: 'sat'})
  * Layer source for the MapQuest tile server.
  * MapQuest タイルサーバのレイヤソース。(ol3 API
  * 2 - ol3ex 23b - MapQuest example 2 参照)
  */
});
var map = new ol.Map({
 layers: [raster],
 target: 'map',
 view: new ol.View({
  center: [-11000000, 4600000],
  zoom: 4
 })
});
/** The features are not added to a regular vector 
 * layer/source, but to a feature overlay which holds a 
 * collection of features. This collection is passed to 
 * the modify and also the draw interaction, so that 
 * both can add or modify features.
 * フィーチャは、通常、ベクター層/ソースに追加するが、フィーチャ
 * のコレクションを保持するフィーチャオーバーレイには追加されませ
 * ん。このコレクションは、変更、または、描画インターラクションに
 * 渡されます。そのため、フィーチャを追加または変更の両方ができま
 * す。
 */
var featureOverlay = new ol.FeatureOverlay({
/** ol.FeatureOverlay
 * A mechanism for changing the style of a small number of 
 * features on a temporary basis, for example highlighting. 
 * This is necessary with the Canvas renderer, where, unlike
 * in SVG, features cannot be individually referenced.
 * ハイライトのように、一時的に少数のフィーチャがスタイルの変更す
 * るためのメカニズム。これは Canvas レンダラが必要で、SVGとは異
 * なり、フィーチャを個別に参照することはできません。(ol3 API)
 */
 style: new ol.style.Style({
 /** ol.style.Style 
  * Base class for vector feature rendering styles.
  * ベクタフィーチャがスタイルを描画するための基本クラス。
  * (ol3 API)
  */
  fill: new ol.style.Fill({
  /** ol.style.Fill 
   * Set fill style for vector features.
   * ベクタフィーチャの塗りつぶしスタイルを設定。(ol3 API)
   */
   color: 'rgba(255, 255, 255, 0.2)'
  }),
  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: '#ffcc33',
   width: 2
  }),
  image: new ol.style.Circle({
  /** ol.style.Circle
   * Set circle style for vector features.
   * ベクタフィーチャの円のスタイルを設定。(ol3 API)
   */
   radius: 7,
   fill: new ol.style.Fill({
    color: '#ffcc33'
   })
  })
 })
});
featureOverlay.setMap(map);
/** setMap(map)
 * Set the map to be associated with this overlay.
 * このオーバレイに関連付けられているマップを設定します。
 * (ol3 API)
 */
var modify = new ol.interaction.Modify({
/** ol.interaction.Modify 
 * Interaction for modifying vector data.
 * ベクタデータを変形するためのインタラクション。
 * (ol3 API)
 */
 features: featureOverlay.getFeatures(),
 /** the SHIFT key must be pressed to delete vertices, so
  * that new vertices can be drawn at the same position
  * of existing vertices
  * Shift キーは、頂点を削除するために押す必要があります。
  * そうすると、新たな頂点が既存の頂点と同じ位置に描画できます、
  */
 deleteCondition: function(event) {
  return ol.events.condition.shiftKeyOnly(event) &&
 /** ol.events.condition.shiftKeyOnly
  * Returns: True if only the shift key is pressed.
  * (ol3 API)
  */
   ol.events.condition.singleClick(event);
   /** ol.events.condition.singleClick
    * Returns: True if the event is a map singleclick event.
    * (ol3 API)
    */
 }
});
map.addInteraction(modify);
/** addInteraction(interaction)
 * Add the given interaction to the map.
 * マップへ与えられたインターラクションを追加します。(ol3 API)
 */
var draw; // global so we can remove it later
function addInteraction() {
 draw = new ol.interaction.Draw({
 /** ol.interaction.Draw 
  * Interaction that allows drawing geometries.
  * ジオメトリの描画を認めるインターラクション。(ol3 API)
  */
  features: featureOverlay.getFeatures(),
  /** getFeatures()
   * Get the selected features.
   * 選択されたフィーチャを取得します。
   * Return: Features collection(ol3 API)
   */
  type: /** @type {ol.geom.GeometryType} */ (typeSelect.value)
  /** @type 
  * 値のタイプ(型)の説明 - 式などで表示
  * (@use JSDoc[http://usejsdoc.org/]より)
  */
 });
 map.addInteraction(draw);
}
var typeSelect = document.getElementById('type');

/**
 * Let user change the geometry type.
 * @param {Event} e Change event.
 */
/** 「@param」
 * The @param tag provides the name, type, and 
 * description of a function parameter.
 * The @param tag requires you to specify the name of 
 * the parameter you are documenting. You can also 
 * include the parameter's type, enclosed in curly 
 * brackets, and a description of the parameter.
 * @paramタグは、関数パラメータの名前と型、説明を提供します。
 * @paramタグを使用すると、文書化されたパラメータの名前を
 * 指定する必要があります。また、パラメータのタイプと、中括弧
 * で囲まれたおよびパラメータの説明を含めることができます。
 * (@use JSDoc [http://usejsdoc.org/tags-param.html])
 */
typeSelect.onchange = function(e) {
 map.removeInteraction(draw);
 /** removeInteraction(()
  * Remove the given interaction from the map.
  * マップから与えられたインターラクションを削除します。
  * (ol3 API)
  */
 addInteraction();
};
addInteraction();

2 - ol3.1ex 54a - Draw and modify features example 1

「Draw and modify features example(draw-and-modify-features.html)」を参考に地図を表示してみます。

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





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





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



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








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











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



「254-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.1.1/css/ol.css" type="text/css">
  <link rel="stylesheet" href="v3.1.1/resources/bootstrap/css/bootstrap.min.css" type="text/css">
  <link rel="stylesheet" href="v3.1.1/resources/layout.css" type="text/css">
  <link rel="stylesheet" href="v3.1.1/resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
  <title>Draw and modify features 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.1.1/examples/"><img src="v3.1.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">Draw and modify features example</h4>
     <p id="shortdesc">Example of using the ol.interaction.Draw interaction 
      together with the ol.interaction.Modify interaction.</p>
     <form class="form-inline">
      <label>Geometry type &nbsp;</label>
       <select id="type">
        <option value="Point">Point</option>
        <option value="LineString">LineString</option>
        <option value="Polygon">Polygon</option>
       </select>
      </form>
     <div id="docs">
      <!--
      See the <a href="draw-and-modify-features.js" target="_blank">draw-and-modify-features.js source</a> to see how this is done.</p>
      -->
      <!-- ファイル修正 -->
      See the <a href="254-ol3ex.js" target="_blank">254-ol3ex.js source</a> to see how this is done.</p>
     </div>
     <div id="tags">draw, edit, modify, vector, featureoverlay</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.1.1/resources/jquery.min.js" type="text/javascript"></script>
  <script src="v3.1.1/resources/example-behaviour.js" type="text/javascript"></script>
  <!--
  <script src="loader.js?id=draw-and-modify-features" type="text/javascript"></script>
  -->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=254-ol3ex" type="text/javascript"></script>
 </body>
</html>

2 - ol3.1ex 53b - Modify features test 2

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

「253-ol3ex.js」
var styleFunction = (function() {
 /* jshint -W069 */
/* 予約語でないプロパティ名のとき 、[](角括弧、ブラケット)
 * 内の文字列リテラルを使用してプロパティにアクセスする試み
 * を検出したとき投げられる警告を発行しないように JSHint に
 * 伝えることを意味します。
 * (['{a}'] is better written in dot notation[https://
 * jslinterrors.com/a-is-better-written-in-dot-notation])
 */
 var styles = {};
 var image = new ol.style.Circle({
 /** ol.style.Circle
  * Set circle style for vector features.
  * ベクタフィーチャの円のスタイルを設定。(ol3 API)
  */
  radius: 5,
  fill: null,
  stroke: new ol.style.Stroke({color: 'orange', 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)
   */
 });
 styles['Point'] = [new ol.style.Style({image: image})];
 /** ol.style.Style 
  * Base class for vector feature rendering styles.
  * ベクタフィーチャがスタイルを描画するための基本クラス。
  * (ol3 API)
  */
 styles['Polygon'] = [new ol.style.Style({
  stroke: new ol.style.Stroke({
   color: 'blue',
   width: 3
  }),
  fill: new ol.style.Fill({
  /** ol.style.Fill 
   * Set fill style for vector features.
   * ベクタフィーチャの塗りつぶしスタイルを設定。(ol3 API)
   */
   color: 'rgba(0, 0, 255, 0.1)'
  })
 })];
 styles['MultiLinestring'] = [new ol.style.Style({
  stroke: new ol.style.Stroke({
   color: 'green',
   width: 3
  })
 })];
 styles['MultiPolygon'] = [new ol.style.Style({
  stroke: new ol.style.Stroke({
   color: 'yellow',
   width: 1
  }),
  fill: new ol.style.Fill({
   color: 'rgba(255, 255, 0, 0.1)'
  })
 })];
 styles['default'] = [new ol.style.Style({
  stroke: new ol.style.Stroke({
   color: 'red',
   width: 3
  }),
  fill: new ol.style.Fill({
   color: 'rgba(255, 0, 0, 0.1)'
  }),
  image: image
 })];
 return function(feature, resolution) {
  return styles[feature.getGeometry().getType()] || styles['default'];
  /** getGeometry()
   * Returns the Geometry associated with this feature 
   * using the current geometry name property. By  
   * default,this is geometry but it may be changed 
   * by calling setGeometryName.
   * 現在のジオメトリネームプロパティを使用して、このフィーチャ
   * に関連したジオメトリを返します。デフォルトでは、ジオメトリ
   * ですが、setGeometryName を呼び出すことによって変更するこ
   * とができます。(ol3 API)
   */
  /** getType()
   * Get the type of this geometry. 
   * ジオメトリの型を取得。(ol3 API)
   */
 };
 /* jshint +W069 */
})();
var source = new ol.source.GeoJSON(
/** ol.source.GeoJSON 
 * Static vector source in GeoJSON format
 * GeoJSON フォーマットの静的ベクタソース。(ol3 API)
 */
 /** @type {olx.source.GeoJSONOptions} */ ({
 /** @type 
 * 値のタイプ(型)の説明 - 式などで表示
 * (@use JSDoc[http://usejsdoc.org/]より)
 */
 object: {
  'type': 'FeatureCollection',
  'crs': {
   'type': 'name',
   'properties': {
    'name': 'EPSG:3857'
   }
  },
  'features': [
   {
    'type': 'Feature',
    'geometry': {
     'type': 'Point',
     'coordinates': [0, 0]
    }
   },
   {
    'type': 'Feature',
    'geometry': {
    'type': 'MultiPoint',
    'coordinates': [[-2e6, 0], [0, -2e6]]
    }
   },
   {
    'type': 'Feature',
    'geometry': {
     'type': 'LineString',
     'coordinates': [[4e6, -2e6], [8e6, 2e6], [9e6, 2e6]]
    }
   },
   {
    'type': 'Feature',
    'geometry': {
     'type': 'LineString',
     'coordinates': [[4e6, -2e6], [8e6, 2e6], [8e6, 3e6]]
    }
   },
   {
    'type': 'Feature',
    'geometry': {
     'type': 'Polygon',
     'coordinates': [[[-5e6, -1e6], [-4e6, 1e6],
      [-3e6, -1e6], [-5e6, -1e6]], [[-4.5e6, -0.5e6],
      [-3.5e6, -0.5e6], [-4e6, 0.5e6], [-4.5e6, -0.5e6]]]
    }
   },
   {
    'type': 'Feature',
    'geometry': {
     'type': 'MultiLineString',
     'coordinates': [
      [[-1e6, -7.5e5], [-1e6, 7.5e5]],
      [[1e6, -7.5e5], [1e6, 7.5e5]],
      [[-7.5e5, -1e6], [7.5e5, -1e6]],
      [[-7.5e5, 1e6], [7.5e5, 1e6]]
     ]
    }
   },
   {
    'type': 'Feature',
    'geometry': {
     'type': 'MultiPolygon',
     'coordinates': [
      [[[-5e6, 6e6], [-5e6, 8e6], [-3e6, 8e6],
       [-3e6, 6e6], [-5e6, 6e6]]],
      [[[-2e6, 6e6], [-2e6, 8e6], [0, 8e6],
       [0, 6e6], [-2e6, 6e6]]],
      [[[1e6, 6e6], [1e6, 8e6], [3e6, 8e6],
       [3e6, 6e6], [1e6, 6e6]]]
     ]
    }
   },
   {
    'type': 'Feature',
    'geometry': {
     'type': 'GeometryCollection',
     'geometries': [
      {
       'type': 'LineString',
       'coordinates': [[-5e6, -5e6], [0, -5e6]]
      },
      {
       'type': 'Point',
       'coordinates': [4e6, -5e6]
      },
      {
       'type': 'Polygon',
       'coordinates': [
        [[1e6, -6e6], [2e6, -4e6], [3e6, -6e6], [1e6, -6e6]]
       ]
      }
     ]
    }
   }
  ]
 }
}));
var layer = new ol.layer.Vector({
/** ol.layer.Vector
 * Vector data that is rendered client-side.
 * クライアント側で描画されたベクタデータ。(ol3 API)
 */
 source: source,
 style: styleFunction
});
var overlayStyle = (function() {
 /* jshint -W069 */
 var styles = {};
 styles['Polygon'] = [
  new ol.style.Style({
   fill: new ol.style.Fill({
    color: [255, 255, 255, 0.5]
   })
  }),
  new ol.style.Style({
   stroke: new ol.style.Stroke({
    color: [255, 255, 255, 1],
    width: 5
   })
  }),
  new ol.style.Style({
   stroke: new ol.style.Stroke({
    color: [0, 153, 255, 1],
    width: 3
   })
  })
 ];
 styles['MultiPolygon'] = styles['Polygon'];
pre style="overflow: auto;"> styles['LineString'] = [   new ol.style.Style({    stroke: new ol.style.Stroke({     color: [255, 255, 255, 1],     width: 5    })   }),   new ol.style.Style({    stroke: new ol.style.Stroke({     color: [0, 153, 255, 1],     width: 3    })   })  ];  styles['MultiLineString'] = styles['LineString'];
 styles['Point'] = [
  new ol.style.Style({
   image: new ol.style.Circle({
    radius: 7,
    fill: new ol.style.Fill({
     color: [0, 153, 255, 1]
    }),
    stroke: new ol.style.Stroke({
     color: [255, 255, 255, 0.75],
     width: 1.5
    })
   }),
   zIndex: 100000
  })
 ];
 styles['MultiPoint'] = styles['Point'];
 styles['GeometryCollection'] = styles['Polygon'].concat(styles['Point']);
 return function(feature, resolution) {
  return styles[feature.getGeometry().getType()];
 };
 /* jshint +W069 */
})();
var select = new ol.interaction.Select({
/** ol.interaction.Select 
 * Handles selection of vector data. A 
 * ol.FeatureOverlay is maintained internally to 
 * store the selected feature(s). Which features 
 * are selected is determined by the condition 
 * option, and optionally the toggle or add/remove 
 * options.
 * ベクタデータの選択を処理します。 ol.FeatureOverlay 
 * は、選択したフィーチャを格納するために内部的に維持され
 * ています。選択されているどのフィーチャでも条件オプショ
 * ン、そして部分的にトグルまたは追加/削除オプションによっ
 * て決定されます。(ol3 API)
 */
 style: overlayStyle
});
var modify = new ol.interaction.Modify({
/** ol.interaction.Modify 
 * Interaction for modifying vector data.
 * ベクタデータを変形するためのインタラクション。
 * (ol3 API)
 */
 features: select.getFeatures(),
 /** getFeatures()
  * Get the selected features.
  * 選択されたフィーチャを取得します。
  * Return: Features collection(ol3 API)
  */
 style: overlayStyle
});
var map = new ol.Map({
 interactions: ol.interaction.defaults().extend([select, modify]),
 /** ol.control.defaults()
  * デフォルトでは、マップに含まコントロールのセット。
  * 特に設定しない限り、これは、以下の各コントロールの
  * インスタンスを含むコレクションを返します。(ol3 API)
  * ol.control.Zoom, ol.control.Rotate, ol.control.Attribution
  */
 layers: [layer],
 target: 'map',
 view: new ol.View({
  center: [0, 1000000],
  zoom: 2
 })
});

2 - ol3.1ex 53a - Modify features test 1

「 Modify features test(modify-test.html)」を参考に地図を表示してみます。

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





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





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



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








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











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



「253-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.1.1/css/ol.css" type="text/css">
  <link rel="stylesheet" href="v3.1.1/resources/bootstrap/css/bootstrap.min.css" type="text/css">
  <link rel="stylesheet" href="v3.1.1/resources/layout.css" type="text/css">
  <link rel="stylesheet" href="v3.1.1/resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
  <title>Modify features test</title>
  <style>
   .map {
    background: grey;
   }
  </style>
 </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.1.1/examples/"><img src="v3.1.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">Modify features test</h4>
     <p id="shortdesc">Example for testing feature modification.</p>
     <div id="docs">
      <!--
      See the <a href="modify-test.js" target="_blank">modify-test.js source</a> to see how this is done.</p>
      -->
      <!-- ファイル修正 -->
      See the <a href="253-ol3ex.js" target="_blank">253-ol3ex.js source</a> to see how this is done.</p>
     </div>
     <div id="tags">modify, edit, vector</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.1.1/resources/jquery.min.js" type="text/javascript"></script>
  <script src="v3.1.1/resources/example-behaviour.js" type="text/javascript"></script>
  <!--
  <script src="loader.js?id=modify-test" type="text/javascript"></script>
  -->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=253-ol3ex" type="text/javascript"></script>
 </body>
</html>

2014年10月5日日曜日

2 - ol3ex 17b - Modify features example 2

「modify-features.js(217-ol3ex.js)」は、地図を表示するのに必要な javascript です。
「217-ol3ex.js」
var raster = 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: 'sat'
 })
});
var vector = new ol.layer.Vector({
/** ol.layer.Vector 
 * Vector data that is rendered client-side. Note that any 
 * property set in the options is set as a ol.Object property
 * on the layer object; for example, setting title: 'My 
 * Title' in the options means that title is observable, and 
 * has get/set accessors.
 * クライアント側で描画されたベクタデータ。オプションで設定した任
 * 意のプロパティは、レイヤオブジェクトで ol.Object プロパティ
 * として設定されていることに注意してください。たとえば、オプショ
 * ンで、title:'My Title' を設定することは、タイトルは 
 * observable で、アクセサを取得/設定することを意味します。
 * (ol3 API)
 */
 source: new ol.source.GeoJSON({
 /** ol.source.GeoJSON 
  * Static vector source in GeoJSON format
  * GeoJSON フォーマットの静的ベクタソース。(ol3 API)
  */
  projection: 'EPSG:3857',
//url: 'data/geojson/countries.geojson'
  url: 'v3.0.0/examples/data/geojson/countries.geojson'
 })
});
var select = new ol.interaction.Select();
/** ol.interaction.Select 
 * Handles selection of vector data. A 
 * ol.FeatureOverlay is maintained internally to 
 * store the selected feature(s). Which features 
 * are selected is determined by the condition 
 * option, and optionally the toggle or add/remove 
 * options.
 * ベクタデータの選択を処理します。 ol.FeatureOverlay 
 * は、選択したフィーチャを格納するために内部的に維持され
 * ています。選択されているどのフィーチャでも条件オプショ
 * ン、そして部分的にトグルまたは追加/削除オプションによっ
 * て決定されます。(ol3 API)
 */

var modify = new ol.interaction.Modify({
/** ol.interaction.Modify 
 * Interaction for modifying vector data.
 * ベクタデータを変形するためのインタラクション。
 * (ol3 API)
 */
 features: select.getFeatures()
 /** getFeatures()
  * Get the selected features.
  * 選択されたフィーチャを取得します。
  * Return: Features collection(ol3 API)
  */
});
var map = new ol.Map({
 interactions: ol.interaction.defaults().extend([select, modify]),
 /** ol.interaction.defaults
  * Set of interactions included in maps by default. 
  * Specific interactions can be excluded by setting 
  * the appropriate option to false in the constructor 
  * options, but the order of the interactions is fixed. 
  * If you want to specify a different order for 
  * interactions, you will need to create your own 
  * ol.interaction.Interaction instances and insert 
  * them into a ol.Collection in the order you want 
  * before creating your ol.Map instance.
  * デフォルトでマップに含まれるインターラクションのセット。
  * 具体的なインターラクションは、コンストラクタのオプションで
  * 適切なオプションをfalseに設定することで除外することができます
  * が、インターラクションの順番は固定されています。インターラク
  * ションに対して別の順番を指定したい場合は、独自の
  * ol.interaction.Interaction インスタンスを作成し、ol.Map
  *  インスタンスを作成する前に望む順番で ol.Collection にそれら
  * を挿入する必要があります。(ol3 API)
  *  (訳注:インターラクションの順番は、API を参照してください。)
  */
 layers: [raster, vector],
 target: 'map',
 view: new ol.View({
  center: [0, 0],
  zoom: 2
 })
});


2 - ol3ex 17a - Modify features example 1

「Modify features example(modify-features.html)」を参考に地図を表示してみます。
HTML ファイルの作成
a Eclipse のメニューの「ファイル」->「ファイルを開く」をクリックします。





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





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



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








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











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


「217-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>Modify features example</title>
 </head>
 <body>

  <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">Modify features example</h4>
     <p id="shortdesc">Editing features with the modify interaction.</p>
     <div id="docs">
      <p>This example demonstrates how the modify and select interactions can be used together.
      Zoom in to an area of interest and select a feature for editing.
      Then drag points around to modify the feature.
      You can preserve topology by selecting multiple features before editing
      (<code>Shift</code>+click to select multiple features).</p>
<!--
      <p>See the <a href="modify-features.js" target="_blank">modify-features.js source</a> to see how this is done.</p>
-->
       <!-- ファイル修正 -->
      <p>See the <a href="217-ol3ex.js" target="_blank">217-ol3ex.js source</a> to see how this is done.</p>
     </div>
     <div id="tags">modify, edit, vector</div>
    </div>
   </div>
  </div>
<!--
  <script src="jquery.min.js" type="text/javascript"></script>
  <script src="../resources/example-behaviour.js" type="text/javascript"></script>
-->
  <!-- ディレクトリ修正 -->
  <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=draw-features" type="text/javascript"></script>
-->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=217-ol3ex" type="text/javascript"></script>

 </body>
</html>

2014年7月24日木曜日

2 - ol3-beta.5ex 18b - Modify features example 2

「modify-features.js(218-ol3ex.js)」は、地図を表示するのに必要な javascript です。

「218-ol3ex.js」
var raster = new ol.layer.Tile({
 source: new ol.source.MapQuest({
  layer: 'sat'
 })
});
var vector = new ol.layer.Vector({
 source: new ol.source.GeoJSON({
  projection: 'EPSG:3857',
//url: 'data/geojson/countries.geojson'
  url: 'v3.0.0-beta.5/examples/data/geojson/countries.geojson'
 })
});
var select = new ol.interaction.Select();

var modify = new ol.interaction.Modify({
 features: select.getFeatures()
});
ar map = new ol.Map({
 interactions: ol.interaction.defaults().extend([select, modify]),
 layers: [raster, vector],
 target: 'map',
 view: new ol.View2D({
  center: [0, 0],
  zoom: 2
 })
});



ol3 のバージョンが v3.0.0-gamma.2 になり、example の内容も変更がありましたが、ダウンロードしたフォルダに変更が完全に反映されていなかったので、反映されてから再開します。

2 - ol3-beta.5ex 18a - Modify features example 1

「Modify features example(modify-features.html)」を参考に地図を表示してみます。

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





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





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



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








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











f 「modify-features.html」の内容をコピーして「218-ol3ex.html」に貼り付け、修正します。
g 同じように、新規に「218-ol3ex.js」ファイルを作成し、「File Template」ウィンドウで「JavaScript Template」をクリックして選択し、「完了」ボタンをクリックして、「modify-features.js」の内容をコピーして貼り付け、修正します。「modify-features-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-beta.5/css/ol.css" type="text/css">
  <link rel="stylesheet" href="v3.0.0-beta.5/resources/bootstrap/css/bootstrap.min.css" type="text/css">
  <link rel="stylesheet" href="v3.0.0-beta.5/resources/layout.css" type="text/css">
  <link rel="stylesheet" href="v3.0.0-beta.5/resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
  <title>Modify features example</title>
 </head>
 <body>

  <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-beta.5/examples/"><img src="v3.0.0-beta.5/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">Modify features example</h4>
     <p id="shortdesc">Editing features with the modify interaction.</p>
     <div id="docs">
      <p>This example demonstrates how the modify and select interactions can be used together.
      Zoom in to an area of interest and select a feature for editing.
      Then drag points around to modify the feature.
      You can preserve topology by selecting multiple features before editing
      (<code>Shift</code>+click to select multiple features).</p>
<!--
      <p>See the <a href="modify-features.js" target="_blank">modify-features.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">modify, edit, vector</div>
    </div>
   </div>
  </div>
<!--
  <script src="jquery.min.js" type="text/javascript"></script>
  <script src="../resources/example-behaviour.js" type="text/javascript"></script>
-->
  <!-- ディレクトリ修正 -->
  <script src="v3.0.0-beta.5/examples/jquery.min.js" type="text/javascript"></script>
  <script src="v3.0.0-beta.5/resources/example-behaviour.js" type="text/javascript"></script>
<!--
  <script src="loader.js?id=draw-features" type="text/javascript"></script>
-->
  <!-- ファイル修正 -->  <!-- ディレクトリ修正 -->
  <script src="loader.js?id=218-ol3ex" type="text/javascript"></script>

 </body>
</html>

2014年1月21日火曜日

34 - 編集ツールバー(Editing Toolbar) 4 - 変形ボタンを追加

34-4 Editing Toolbar に変形ボタンを追加する
「ol015-nippon_bmi_akiruno_pgis.html」 ファイルを続けて使います。
変形ボタンは次のようなものを作成して、"OpenLayers-2.13.1/theme/default/img/ に保存しました。


modify_feature_on.png

modify_feature_off.png


<style> に変形ボタンのスタイルを追加

---
// ここから追加
 .olControlModifyFeatureItemActive { 
  background-image: url(OpenLayers-2.13.1/theme/default/img/modify_feature_on.png);
  background-repeat: no-repeat;
  background-position: 0px 1px;
 }
 .olControlModifyFeatureItemInactive { 
  background-image: url(OpenLayers-2.13.1/theme/default/img/modify_feature_off.png);
  background-repeat: no-repeat;
  background-position: 0px 1px;
 }
// ここまで
---

移動ボタンのコードを追加

---
  new OpenLayers.Control.DragFeature(
   vectors,
   {
   title: "Drag Feature",
   displayClass: 'olControlDragFeature'
  }),
// ここから追加
  new OpenLayers.Control.ModifyFeature(vectors,{
   title: "Modify Feature",
   displayClass: "olControlModifyFeature"
  }),
// ここまで
  new OpenLayers.Control.SelectFeature(
---

2014年1月14日火曜日

33 - マウスでフィーチャを描画 4 - ポリゴン(多角形)を変形する

33-4 ポリゴン(多角形)を変形する
examples フォルダにある「OpenLayers Modify Feature Example(modify-feature.html)」を参考に マウスで移動してみます。
「ol014-nippon_bmi_akiruno_pgis.html」 ファイルを続けて使います。

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







b 「ファイルを開く」ウィンドウで、「OpenLayers-2.13.1」->「examples」->「modify-feature.html」をクリックして選択し、「OK」ボタンをクリックします。






c 次のように「modify-feature.html」の内容の一部をコピーして「ol014-nippon_bmi_akiruno_pgis.html」に貼り付け、修正します。
---
  <link rel="stylesheet" href="OpenLayers-2.13.1/theme/default/style.css" type="text/css">
  <link rel="stylesheet" href="OpenLayers-2.13.1/examples/style.css" type="text/css">
  <style type="text/css">
/* ここから追加 */
   #controls {
    width: 512px;
   }
   #controlToggle {
    padding-left: 1em;
   }
/* ここまで */
   #controlToggle li {
    list-style: none;
   }
   p {
    width: 512px;
   }
   /* avoid pink tiles */
   .olImageLoadError {
    background-color: transparent !important;
   }
  </style>
  <title>WMS Example BMI Akiruno PGIS2</title>
---
     map.addLayers([layer0, layer3, layer1, layer2, layer4, vectors]);
// ここから追加
     if (console && console.log) {
      function report(event) {
       console.log(event.type, event.feature ? event.feature.id : event.components);
      }
      vectors.events.on({
       "beforefeaturemodified": report,
       "featuremodified": report,
       "afterfeaturemodified": report,
       "vertexmodified": report,
       "sketchmodified": report,
       "sketchstarted": report,
       "sketchcomplete": report
      });
     }
// ここまで
     drawControls = {
      polygon: new OpenLayers.Control.DrawFeature(
       vectors, OpenLayers.Handler.Polygon),
      drag1: new OpenLayers.Control.DragFeature( // "drag" を "drag1" に修正
       vectors,
       {
        onStart: startDrag,
        onDrag: doDrag,
        onComplete: endDrag
       }
      ),
      modify: new OpenLayers.Control.ModifyFeature(vectors), // 追加
      select: new OpenLayers.Control.SelectFeature(
       vectors,
---
   function update() {
    var clickout = document.getElementById("clickout").checked;
    if(clickout != drawControls.select.clickout) {
     drawControls.select.clickout = clickout;
    }
// ここから追加 "controls" を "drawControls" に修正
    // reset modification mode
    drawControls.modify.mode = OpenLayers.Control.ModifyFeature.RESHAPE;
    var rotate = document.getElementById("rotate").checked;
    if(rotate) {
        drawControls.modify.mode |= OpenLayers.Control.ModifyFeature.ROTATE;
    }
    var resize = document.getElementById("resize").checked;
    if(resize) {
        drawControls.modify.mode |= OpenLayers.Control.ModifyFeature.RESIZE;
        var keepAspectRatio = document.getElementById("keepAspectRatio").checked;
        if (keepAspectRatio) {
            drawControls.modify.mode &= ~OpenLayers.Control.ModifyFeature.RESHAPE;
        }
    }
    var drag = document.getElementById("drag").checked;
    if(drag) {
        drawControls.modify.mode |= OpenLayers.Control.ModifyFeature.DRAG;
    }
    if (rotate || drag) {
        drawControls.modify.mode &= ~OpenLayers.Control.ModifyFeature.RESHAPE;
    }
    drawControls.modify.createVertices = document.getElementById("createVertices").checked;
    var sides = parseInt(document.getElementById("sides").value);
    sides = Math.max(3, isNaN(sides) ? 0 : sides);
    drawControls.regular.handler.sides = sides;
    var irregular =  document.getElementById("irregular").checked;
    drawControls.regular.handler.irregular = irregular;
// ここまで     
   var box = document.getElementById("box").checked;
    if(box != drawControls.select.box) {
     drawControls.select.box = box;
     if(drawControls.select.active) {
      drawControls.select.deactivate();
      drawControls.select.activate();
     }
    }
   }
  </script>
 </head>
 <body onload="init()">
---
  <div id="controls"> <!-- 追加 -->
  <ul id="controlToggle">
---
<!-- "drag" を "drag1" に修正 -->
 <li>
   <input type="radio" name="type" value="drag1" id="dragToggle" onclick="toggleControl(this);" />
   <label for="dragToggle">drag feature</label>
 </li>
---
<!-- ここから追加 -->
  <li>
   <input type="radio" name="type" value="modify" id="modifyToggle" onclick="toggleControl(this);" />
   <label for="modifyToggle">modify feature</label>
   <ul>
    <li>
     <input id="createVertices" type="checkbox" checked name="createVertices" onchange="update()" />
     <label for="createVertices">allow vertices creation</label>
    </li>
    <li>
     <input id="rotate" type="checkbox" name="rotate" onchange="update()" />
     <label for="rotate">allow rotation</label>
    </li>
    <li>
     <input id="resize" type="checkbox" name="resize" onchange="update()" />
     <label for="resize">allow resizing</label>
     (<input id="keepAspectRatio" type="checkbox" name="keepAspectRatio" onchange="update()" checked="checked" />
     <label for="keepAspectRatio">keep aspect ratio</label>)
    </li>
    <li>
     <input id="drag" type="checkbox" name="drag" onchange="update()" />
     <label for="drag">allow dragging</label>
    </li>
   </ul>
  </li>
<!--  ここまで -->
  </ul>
  </div> <!-- 追加 -->
 </body>
</html>
modify feature
 allow vertices creation: 角数を増やす(他のオプションと同時に動作しません)









 allow rotation: 点をドラッグして回転させる










 allow resizing: 点をドラッグして大きさを変える
 (keep aspect ratio: 比率を変えない)









 allow dragging: 点をドラッグして移動させる
(このドラッグでは複数のフィーチャを同時に移動する方法が見つかりませんでした。)