首页 > 其他 > 详细

openlayer 鼠标点击获取一定范围内的要素信息

时间:2021-05-17 22:22:00      阅读:26      评论:0      收藏:0      [点我收藏+]

 

技术分享图片
var yourlayer= new ol.layer.Image({
   source: new ol.source.ImageWMS({
   ratio: 1,

   url: ‘http://192.168.0.164:5081/geoserver/pg/wms‘,
params: {‘FORMAT‘: format,
‘VERSION‘: ‘1.1.1‘,
LAYERS: ‘pg:power_line_750kv‘,
STYLES: ‘‘,
}
})
});
var yourlayer= new ol.layer.Tile({
visible: false,
source: new ol.source.TileWMS({
url: ‘http://192.168.0.164:5081/geoserver/pg/wms‘,
params: {‘FORMAT‘: format,
‘VERSION‘: ‘1.1.1‘,
tiled: true,
LAYERS: ‘pg:power_line_750kv‘,
STYLES: ‘‘,
}
})
});



map.on(‘singleclick‘, function(evt) {
document.getElementById(‘nodelist‘).innerHTML = "Loading... please wait...";
var view = map.getView();
var viewResolution = view.getResolution();
var source = yourlayer.getSource() ;
var url = source.getGetFeatureInfoUrl(
evt.coordinate, viewResolution, view.getProjection(),
{‘INFO_FORMAT‘: ‘text/html‘, ‘FEATURE_COUNT‘: 50});
if (url) {
$.ajax({
url: url,
success: function(data){
//console.info(data);
}
});

var coordinate = evt.coordinate;
var circleFeature = new ol.Feature({
geometry: new ol.geom.Circle(coordinate, 0.00005),
});
var polygon = new ol.geom.Polygon.fromCircle(new ol.geom.Circle(coordinate, 0.00005)); //圆转为多边形后才能进行分析
var offset = 10*viewResolution;
var polygon = new ol.geom.Polygon([[
[coordinate[0],coordinate[1]+offset],
[coordinate[0]+offset,coordinate[1]-offset],
[coordinate[0]-offset,coordinate[1]-offset],
[coordinate[0],coordinate[1]+offset]
]]);

getInfo(polygon);

var extent = polygon.getExtent(); // 拿到draw 框选的四至范围
var features1 = v.getSource().getFeaturesInExtent(extent); //先缩小feature的范围
if(features1.length>0){
console.info(features1);
console.info(features1[0].H);
}

var features = [];
vs.forEachFeatureIntersectingExtent (extent, feature => { // 用 ol 方法进行遍历
features.push(feature);
});
console.info(features);

document.getElementById(‘nodelist‘).innerHTML = ‘<iframe seamless src="‘ + url + ‘"></iframe>‘;
}
});
View Code

 

openlayer 鼠标点击获取一定范围内的要素信息

原文:https://www.cnblogs.com/zt2710/p/14777971.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!