openlayers点击wms图层获取其信息

 

var wmsSource = new ol.source.ImageWMS({
    url:  buildIp+'/geoserver/tianjin/wms',
    params: {'LAYERS': 'tianjin:tianjin_build_leqn'},
    serverType: 'geoserver',
    crossOrigin: 'anonymous'
});
var mapview = new ol.View({
    center:[117.60013092,39.0839299033],
    projection: 'EPSG:4326',
    zoom: 9,
    minZoom:4,
    maxZoom:18
})
//注意:这个mapview只能有一个且必须是变量,声明的map实例的view也得是这个变量

if (wmsSource.getGetFeatureInfoUrl(e.coordinate, mapview.getResolution(), mapview.getProjection(),{ 'INFO_FORMAT': 'application/json' })) {
            $.ajax({
                type: "POST",
                url:wmsSource.getGetFeatureInfoUrl(e.coordinate, mapview.getResolution(), mapview.getProjection(),{ 'INFO_FORMAT': 'application/json' }),
                dataType: 'json',
                success: function (data) {
                    console.log(data)
                    //wms图层的信息
                    }
                },
                error: function(data){
                    alert("出错了!");
                }
            });
        }

 

你可能感兴趣的:(openlayers)