ํฐ์คํ ๋ฆฌ ๋ทฐ
โ Programming/โ GIS
[ Openlayers ] ๋ง์ฐ์ค ์ค๋ฒ์ ํน์ ๊ตฌ์ญ ํ์ด๋ผ์ดํ ํ๊ธฐ(with ol.interaction.select)
Kithub 2020. 4. 9. 12:22ํด๋ฆฌ๊ณค ํ์ถ ์ ํน์ ์ง์ญ์ ํ์ด๋ผ์ดํ ํด์ผํ๋ ๊ฒฝ์ฐ๊ฐ ์๋๋ฐ
์ด๋ ol.interaction.select ๊ฐ์ฒด๋ฅผ ํ์ฉํ๋ฉด ๊ฐ๋จํ ํ์ด๋ผ์ดํ ํจ๊ณผ๋ฅผ ์ค ์ ์์ต๋๋ค.
์์ค์ฝ๋
<!DOCTYPE html>
<html lang="">
<head>
<meta charset="utf-8">
<title>kithub example</title>
<meta name="author" content="Your Name">
<meta name="description" content="Example description">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.2.1/css/ol.css" type="text/css">
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.2.1/build/ol.js"></script>
<style>
.map {
height: 1000px;
width: 100%;
}
</style>
</head>
<body>
<div id="map" class="map"></div>
<script type="text/javascript">
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.XYZ({
url: 'https://xdworld.vworld.kr/2d/midnight/service/{z}/{x}/{y}.png'
})
})
],
view: new ol.View({
center: ol.proj.fromLonLat([126.978275264, 37.566642192]),
zoom: 7
})
});
// ํ์ ๊ตฌ์ญ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
var strUrl = 'http://localhost/geoserver/sqlite/wfs?service=' +
'WFS' +
'&version=2.0.0' +
'&request=GetFeature' +
'&typename=sqlite:ZONE_SIDO_Co2Intensity_auto_weekday_2016' +
'&outputFormat=application/json' +
'&srsname=EPSG:3857' +
'&bbox=' + extent.join(',') + ',EPSG:3857';
return strUrl;
},
strategy: ol.loadingstrategy.bbox
});
var vectorLayer = new ol.layer.Vector({
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 0)',
width: 2
}),
fill: new ol.style.Fill({
color: 'rgba(255,0,0,0.2)'
})
}),
source: vectorSource,
name: 'area'
});
//ํ์ ๊ตฌ์ญ ๋ ์ด์ด ์ถ๊ฐ
map.addLayer(vectorLayer);
// ๊ฐ ํ์ ๊ตฌ์ญ ๋ง์ฐ์ค ์ค๋ฒ์ ํ์ด๋ผ์ดํ
// ๋ง์ฐ์ค ์ค๋ฒ์ ์คํ์ผ ์ง์
var selectPointerMove = new ol.interaction.Select({
condition: ol.events.condition.pointerMove,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'white',
width: 2
}),
fill: new ol.style.Fill({
color: 'rgba(0,0,255,0.6)'
})
})
});
// interaction ์ถ๊ฐ
map.addInteraction(selectPointerMove);
</script>
</body></html>
๊ฒฐ๊ณผํ๋ฉด
'โ Programming > โ GIS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ GIS ] postgis data๋ฅผ shp์ผ๋ก ๋ค์ด๋ก๋ ํ๊ธฐ(feat. geotools) (1) | 2021.07.30 |
---|---|
[ GIS ] shp ๋ฐ์ดํฐ์ ์ง์ค๋ฉํธ๋ฆฌ ์ขํ ์์ ๋ณ๊ฒฝํ๊ธฐ ( feat. geotools ) (0) | 2021.07.20 |
[ OpenLayers ] ๋ ์ด์ด feature ๊ฐ ๊ฐ์ ธ์ค๊ธฐ (0) | 2020.11.04 |
[ OpenLayers ] ํน์ ๋ ์ด์ด ์ญ์ ํ๊ธฐ (0) | 2020.11.04 |
[ GIS ] geoserver - ์๋ฒ ๊ตฌ์ถํ๊ธฐ (0) | 2020.03.24 |
๋๊ธ
๋ฐ์ํ