【问题标题】:Openlayers 3, applying features array to vector results in getId() is not a functionOpenlayers 3,将特征数组应用于getId()中的向量结果不是函数
【发布时间】:2015-08-21 09:03:25
【问题描述】:

我有一个数组,其中填充了 ol.Feature 类型的对象,我将其添加到 ol.source.Vector 类型的新对象中,使用以下命令代码:

for (var i in stages)
{
    console.log(stages[i].Longitude, stages[i].Latitude);

    var iconFeature = new ol.Feature({
        geometry: new ol.geom.Point(ol.proj.transform([stages[i].Longitude, stages[i].Latitude], 'EPSG:4326', 'EPSG:3857')),
        name: stages[i].Title
    });

    iconFeature.setStyle(iconStyle);

    iconFeatures.push(iconFeatures);
}

try
{
    var vectorSource = new ol.source.Vector({
        features: iconFeatures
    });
}
catch (e)
{
    console.log(e);
}

添加了 try/catch 块,因为我没有收到任何错误(Angular/Ionic)。

当我加载应用程序时,我收到以下错误:

TypeError: feature.getId 不是函数

var id = feature.getId();

这会将我重定向到 console.log 的行号,这意味着错误必须在矢量源的创建中。

我完全被困在这里,互联网上的例子都是这样做的,任何帮助都会得到帮助。

【问题讨论】:

  • 你在iconFeatures.push(iconFeatures);中有一个愚蠢的错字,你可能想要iconFeatures.push(iconFeature);

标签: javascript angularjs openlayers-3


【解决方案1】:

显然,您可以将数组推送到自身而不会出现任何错误。

完全是我自己的错

iconFeatures.push(iconFeatures);

应该是

iconFeatures.push(iconFeature);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-07
    相关资源
    最近更新 更多