レイヤモジュールで見てきたように、ベクタとしてフィーチャを引き出し、ベースマップ の上にそれらを描くことができます。ベクタデータを提供することの利点の一つは、ユーザがデータとインターラクション(対話型操作)ができることです。この例では、ユーザが選択し、フィーチャ情報を表示することができるベクタレイヤを作成します。
前の例は、マップ上で ol.control.Control を使用してみました。Controls は、マップ上に視覚表現するか、ドキュメントに DOM エレメントを追加します。ol.interaction.Interaction は、ユーザの対話に反応しますが、一般的に視覚表現はしません。この例は、ベクタレイヤからフィーチャと対話するために ol.interactionSelect を使用しています。
3.2.1. ベクタレイヤと選択インターラクションを作成
タスク
1. 前のセクションからのベクタレイヤ例から始めます。テキストエディタで map.html を開き、以下のように修正して、確認します。
<!doctype html> <html lang="en"> <head>
<link rel="stylesheet" href="/ol.css" type="text/css">
<style>
#map {
height: 256px;
width: 512px;
}
</style>
<script src="/loader.js" type="text/javascript"></script> <title>OpenLayers example</title> </head>
<body> <h1>My Map</h1> <div id="map"></div>
<script type="text/javascript">
var map = new ol.Map({
// 追加 3.2.1
interactions: ol.interaction.defaults().extend([
new ol.interaction.Select({
style: new ol.style.Style({
image: new ol.style.Circle({
radius: 5,
fill: new ol.style.Fill({
color: '#FF0000'
}),
stroke: new ol.style.Stroke({
color: '#000000'
})
})
})
})
]),
target: 'map',
layers: [
new ol.layer.Tile({
title: "Global Imagery",
source: new ol.source.TileWMS({
url: 'https://ahocevar.com/geoserver/wms',
params: {LAYERS: 'nasa.bluemarble', TILED: true}
})
}),
new ol.layer.Vector({
title: 'Earthquakes',
source: new ol.source.Vector({
url: 'data/layers/7day-M2.5.json',
format: new ol.source.GeoJSON()
}),
style: new ol.style.Style({
image: new ol.style.Circle({
radius: 5,
fill: new ol.style.Fill({
color: '#0000FF'
}),
stroke: new ol.style.Stroke({
color: '#000000'
})
})
})
})
],
view: new ol.View({
projection: 'EPSG:4326',
center: [0, 0],
zoom: 1
})
});
</script>
</body>
</html>
ベクタレイヤからフィーチャを選択するためにインターラクションを利用。


0 件のコメント:
コメントを投稿