// 防抖
_this.mapLayer = _this.olmap.getLayerGroup().getLayers().array_[2];
function debounce(fn, wait) {
var timeout;
return function() {
var context = this;
var args = arguments;
clearTimeout(timeout);
timeout = setTimeout(function() {
fn.apply(context, args);
}, wait);
};
}
//调用图层数据
function mapEvt(evt) {
var view = _this.olmap.getView();
var viewResolution = view.getResolution();
var source = _this.mapLayer.get("visible")
? _this.mapLayer.getSource()
: _this.mapLayer.getSource();
var url = source.getGetFeatureInfoUrl(
evt.coordinate,
viewResolution,
view.getProjection(),
{
INFO_FORMAT: "text/javascript",
FEATURE_COUNT: 1,
format_options: "callback: getJson",
}
);
if (url) {
$.ajax({
type: "POST",
url: url,
async: true,
dataType: "jsonp",
jsonpCallback: "getJson",
success: function(data) {
if (data.features.length != 0) {
_this.nodelistShow = true;
_this.mapEvent = data.features[0].properties;
} else {
_this.nodelistShow = false;
}
},
});
}
}
_this.olmap.on("pointermove", debounce(mapEvt, 100));
openlayers点击直接获取图层数据
最新推荐文章于 2024-04-27 12:38:20 发布