0

我是 ionic 新手,并试图在 ionic 应用程序中使用草皮。首先我通过 npm 使用

npm install turf

这在节点模块中添加了 turf 文件夹。我将它复制到 lib 文件夹中。然后我在索引页面中添加了指向 turf.min.js 的链接。

它给出了这个错误

turf.featurecollection is not a function

使用的代码 -

  var features = [
            turf.point([-97.502754, 35.463455], {
                "marker-color": "#6BC65F",
                "title": "Too Far",
                "marker-size": "small"
            }),
            turf.point([-97.508269, 35.463245], {
                "marker-color": "#6BC65F",
                "title": "Too Far",
                "marker-size": "small"
            }),
            turf.point([-97.516809, 35.465779], {
                "marker-color": "#6BC65F",
                "title": "Too Far",
                "marker-size": "small"
            }),
            turf.point([-97.515372, 35.467072], {
                "marker-color": "#6BC65F",
                "title": "Too Far",
                "marker-size": "small"
            }),
            turf.point([-97.509363, 35.463053], {
                "marker-color": "#6BC65F",
                "title": "Too Far",
                "marker-size": "small"
            }),
            turf.point([-97.511123, 35.466601], {
                "marker-color": "#6BC65F",
                "title": "Too Far",
                "marker-size": "small"
            }),
            turf.point([-97.518547, 35.469327], {
                "marker-color": "#6BC65F",
                "title": "Too Far",
                "marker-size": "small"
            }),
            turf.point([-97.519706, 35.469659], {
                "marker-color": "#6BC65F",
                "title": "Too Far",
                "marker-size": "small"
            }),
            turf.point([-97.517839, 35.466998], {
                "marker-color": "#6BC65F",
                "title": "Too Far",
                "marker-size": "small"
            }),
            turf.point([-97.508678, 35.464942], {
                "marker-color": "#6BC65F",
                "title": "Too Far",
                "marker-size": "small"
            }),
            turf.point([-97.514914, 35.463453], {
                "marker-color": "#6BC65F",
                "title": "Too Far",
                "marker-size": "small"
            })
        ];

        var fc = turf.featurecollection(features);

        var nearest = turf.nearest(point, fc);

        nearest.properties["marker-color"] = "#25561F";
        nearest.properties["title"] = "Nearest Point";
        nearest.properties["marker-size"] = "large";
        nearest.properties["marker-symbol"] = "star-stroked";

        var nearest_fc = turf.featurecollection([point, nearest]);

        var map = L.mapbox.map('map', 'charuoshan.0n1b363n')
            .setView([35.463453, -97.508014], 14);

        L.mapbox.featureLayer().setGeoJSON(fc).addTo(map);
        L.mapbox.featureLayer().setGeoJSON(nearest_fc).addTo(map);
4

1 回答 1

2

看起来像一个简单的错字。应该是featureCollection

于 2016-08-31T07:15:06.870 回答