openlayer 3.5 从点获取功能 ID

openlayer 3.5 get feature id from point

我还在学习 openlayers,但遇到了问题。如果单击它,我的脚本需要一个点的 id。有了这个 id(那个函数作为一个变量)我想做一些编码。

在一些示例的帮助下,我设法在我的 website.I 上获得了 table 使用以下代码 (javascript):

map.on('singleclick', function(evt) {
    document.getElementById('nodelist').innerHTML = "Loading... please wait...";
    var view = map.getView();
    var viewResolution = view.getResolution();
    var source = untiled.get('visible') ? untiled.getSource() : tiled.getSource();
    var url = source.getGetFeatureInfoUrl(
      evt.coordinate, viewResolution, view.getProjection(),
      {'INFO_FORMAT': 'text/html', 'FEATURE_COUNT': 50});
    if (url) {
      document.getElementById('nodelist').innerHTML = '<iframe seamless src="' + url + '"></iframe>';
    }
  });

但我想要的是不显示 table 并从 table 中获取点的 ID。

有人可以给我一些提示吗?

如果您想访问功能 ID,则不能在 GetFeatureInfo 请求中使用 'text/html' 格式。相反,您将不得不使用 'application/vnd.ogc.gml' 或 'application/json' 格式。这仅在服务器允许 CORS 请求或服务器与您的应用程序位于同一来源时才有效。然后,您将不得不在 AJAX 请求中使用它,而不是在 IFRAME 中使用 source.getGetFeatureInfoUrl() 中的 url。使用 ol.format.WMSGetFeatureInfool.format.GeoJSON 解析响应,对于解析后的功能,您只需使用 ol.Feature#getId().

即可获取 id