Mapbox-如何获取矢量切片源的特征?

时间:2018-11-15 05:32:43

标签: ios swift xcode mapbox

在地图视图完成加载后,我试图设置矢量图块源:

func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle) {
    let urlTemplate = "http://a.tiles.mapbox.com/v4/mapbox.mapbox-streets-v7/{z}/{x}/{y}.mvt?access_token=my_access_token"
    let source = MGLVectorTileSource(identifier: "source",
                                 tileURLTemplates: [urlTemplate],
                                 options: nil)
    mapView.style?.addSource(source)

    let layer = MGLFillStyleLayer(identifier: "layer", source: source)
    layer.sourceLayerIdentifier = "source"
    mapView.style?.addLayer(layer) 
}

这里是我用来查找功能的地方:

func mapView(_ mapView: MGLMapView, regionDidChangeAnimated animated: Bool) {
    if let source = mapView.style?.source(withIdentifier: "source") as? MGLVectorTileSource {
        let sourceFeatures = source.features(sourceLayerIdentifiers: Set(["source"]), predicate: nil)
        print("sourceFeatures count = \(sourceFeatures.count)") // Always 0
    }
}

我什至尝试从地图视图中使用visibleFeatures,但是它没有用。我也尝试不添加该层,但是没有用。

0 个答案:

没有答案