【问题标题】:How to use turf.js with ionic?如何将 turf.js 与 ionic 一起使用?
【发布时间】:2017-01-07 15:33:54
【问题描述】:

我是 ionic 新手,并尝试在 ionic 应用程序中使用 turf。 首先我通过 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);

【问题讨论】:

    标签: angularjs node.js ionic-framework mapbox turfjs


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2021-12-12
      • 1970-01-01
      • 2018-12-06
      • 1970-01-01
      • 2016-12-31
      • 2017-03-09
      • 2015-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多