如何找到图层特征和点之间的距离?

时间:2014-08-07 13:59:48

标签: javascript openlayers distance layer

为什么以下代码无效?

   function showResult() {

      var pointA = new OpenLayers.LonLat(arxikoLon, arxikoLat).transform(fromProjection, toProjection);
      var minDistance = stationsMarkersLayer1a.features[0].geometry.distanceTo(pointA, {details: false, edge: true});
var index =0;
      for (var i = 1; i <= stationsMarkersLayer1a.features.length - 1; i++) {
         var dist = stationsMarkersLayer1a.features[i].geometry.distanceTo(pointA, {details: false, edge: true});
         if (dist < minDistance) {
            index = i;
            minDistance = dist; 
         }
     }
  }

stationsMarkersLayer是图层,arxikoLon和arxikoLat是在上面的代码中全局声明的变量!询问更多细节!

当我评论所有上述代码并且转换另一个函数时,就像这样:

   function showResult() { 
   document.getElementById('resultStasi').innerHTML = stationsMarkersLayer1a.features[0].attributes['description'];
   document.getElementById('resultDromologio').innerHTML = arxikoLat;
    } 

innerHTML的结果很好

0 个答案:

没有答案