function DrawLandSiteGeometry() {
var draw = new ol.interaction.Draw({
source: VectorSource,
type: "Point"
});
//清除所有原有元素
VectorLayer.getSource().clear();
//地图强制刷新
map.render();
let timeoutPromise = (timeout) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
swal({
title: '警告',
text: '图层服务连接已超时!',
type: "warning",
// showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "确定"
}, function () {
VectorSource.clear();
map.removeInteraction(draw);
$('.layer-anim').show();
$('.layui-layer-shade').show();
$('.widget.tiling').show();
reject(false);
});
}, timeout);
});
}
draw.on("drawend", function (callbackData) {
var coordinate = callbackData.feature.getGeometry().getCoordinates();
var lng = coordinate[0].toFixed(6);//保留小数点后6位
var lat = coordinate[1].toFixed(6);//保留小数点后6位
var h = 0;
var point = turf.point([lng, lat]);
var buffered = turf.buffer(point, 1, { units: 'kilometers' });//truf做一个缓冲区,也可以不做这一步
var format = new ol.format.GeoJSON();
var poyFeat = format.readFeature(buffered);
//设置超时
Promise.race([timeoutPromise(1000), CheackXiaoBan('Shape', poyFeat.getGeometry(),draw)])
.then(res => {
if (res) {
//执行成功
}).then(res => {
if (confirm('经度:' + lng + ' 纬度:' + lat + ' 高程:' + h + ' 你确定提交吗?')) {
map.removeInteraction(draw);
}
VectorSource.clear();
})
} else {
//执行失败,超时等
VectorSource.clear();
}
});
})
map.addInteraction(draw);
}
//field是geometry空间属性字段,一般是Shape
function CheackXiaoBan(field, geometry,draw) {
let featureRequest = new ol.format.WFS().writeGetFeature({
//坐标系统
srsName: 'EPSG:4326',
//命名空间
featureNS: 'http://www.openplans.org/spearfish',
//工作区名称
featurePrefix: featurePrefix,
//查询图层
featureTypes: [featureTypes],
outputFormat: 'application/json',
filter: ol.format.filter.intersects(field, geometry)
});
//WFS服务地址
return fetch(wfsservice, {
method: 'POST',
body: new XMLSerializer().serializeToString(featureRequest),
}).then(function (response) {
return response.json();
}).then(function (json) {
if (json.features.length > 0) {
setSwal('此处有小班!', 'warning');
isPointFlag = false;
reject(false);
} else {
isPointFlag = true;
resolve(true);
}
}).catch(function (e) {
swal({
title: '警告',
text: '图层服务调用不成功,请检查后重试!',
type: "warning",
// showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "确定"
}, function () {
VectorSource.clear();
map.removeInteraction(draw);
reject(false);
});
});
}
Openlayer+Geoserver 空间查询,判断要素和图层数据是否相交
最新推荐文章于 2023-08-31 15:51:10 发布