使用JasonSanford / geojson-google-maps(GeoJSON Parser)的googleVector元素无效

时间:2014-01-08 15:52:24

标签: google-maps geojson

我正在尝试使用Google推荐的解析器(JasonSanford - https://github.com/JasonSanford/geojson-google-maps)在Google地图上显示有效GeoJSON输出中的一些元素

我的脚本基于上述网站提供的示例和Google的GeoJson支持规范。

googleVector变量输出一个有效的向量,但是当迭代向量元素时,它会失败 currentFeature_or_Features.setMap(map);

我的map变量是在body onload = initFunc()

上初始化的全局变量

这是错误:

  

Uncaught InvalidValueError:setMap:不是Map的实例,而不是   StreetViewPanorama的实例

GeoJSON输出:

{
  "type" : "FeatureCollection",
  "features" : [ {
    "type" : "Feature",
    "properties" : { },
    "geometry" : {
      "type" : "Point",
      "coordinates" : [ -59.112137, -37.33122 ]
    }
  }, {
    "type" : "Feature",
    "properties" : { },
    "geometry" : {
      "type" : "Point",
      "coordinates" : [ -59.150223, -37.330055 ]
    }
  }, {
    "type" : "Feature",
    "properties" : { },
    "geometry" : {
      "type" : "Point",
      "coordinates" : [ -59.135563, -37.329433 ]
    }
  } ]
}

这是js代码:

function loadData(geojson){

googleVector = new GeoJSON(JSON.parse(geojson));

if (googleVector.error){
    // Handle the error.
}else{      
    display(googleVector);      
}   
}

function display(currentFeature_or_Features){
if (currentFeature_or_Features.length){
    for (var i = 0; i < currentFeature_or_Features.length; i++){
        if(currentFeature_or_Features[i].length){
            for(var j = 0; j < currentFeature_or_Features[i].length; j++){
                currentFeature_or_Features[i][j].setMap(map);
                if(currentFeature_or_Features[i][j].geojsonProperties) {
                    setInfoWindow(currentFeature_or_Features[i][j]);
                }
            }
        }
        else{
            currentFeature_or_Features[i].setMap(map);
        }
        if (currentFeature_or_Features[i].geojsonProperties) {
            setInfoWindow(currentFeature_or_Features[i]);
        }
    }
}else{
    currentFeature_or_Features.setMap(map);
    if (currentFeature_or_Features.geojsonProperties) {
        setInfoWindow(currentFeature_or_Features);
    }
}
}

错误的实际图像: http://i.stack.imgur.com/fHJLc.png

提前感谢任何推荐。

0 个答案:

没有答案