フィーチャの修正は、ol.interaction.Modify と組み合わせて ol.interaction.Select を使用して動作します。それらは、フィーチャの通常のコレクション(ol.Collection)を共有します。ol.interaction.Select で選択されたフィーチャは、ol.interaction.Modify で変形の候補になります。
3.4.1. ベクタレイヤと Modify インタラクションを作成
タスク
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">
// 追加 3.4.1
var source = new ol.source.Vector({
url: 'data/layers/7day-M2.5.json',
format: new ol.format.GeoJSON()
});
var style = 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
})
});
var select = new ol.interaction.Select({style: style});
var modify = new ol.interaction.Modify({
features: select.getfeatures()
});
var map = new ol.Map({
interactions: ol.interaction.defaults().extend([select, modify]), // 修正 3.4.1
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: source, // 修正 3.4.1
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>
3.4.2. 詳しく見る
フィーチャの修正が動作するしくみを調べてみます。
var style = 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
});
var select = new ol.interaction.Select({style: style});
var modify = new ol.interaction.Modify({
feature: select.getfeatures()
});

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