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>‘; } });
原文:https://www.cnblogs.com/zt2710/p/14777971.html