GIS
openlayers 5 bbox
degulv
2019. 8. 21. 16:56
반응형
function drawbbox() {
var bbox = map.getView().calculateExtent();
var coord = [[
[bbox[0], bbox[1]],
[bbox[0], bbox[3]],
[bbox[2], bbox[3]],
[bbox[2], bbox[1]],
[bbox[0], bbox[1]]
]];
var geojsonObject = {
'type': 'FeatureCollection',
'crs': {
'type': 'name',
'properties': {
'name': 'EPSG:3857'
}
},
'features': [{
'type': 'Feature',
'geometry': {
'type': 'Polygon',
'coordinates': coord
}
}]
};
var bboxSource = new ol.source.Vector({
features: new ol.format.GeoJSON().readFeatures(geojsonObject)
});
var bbox = new ol.layer.Vector({
name: 'Select',
source: bboxSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'blue'
}),
fill: new ol.style.Fill({
color: [0, 0, 255, 0.05]
})
})
});
map.addLayer(bbox);
}
반응형