Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 是否可以将MGLShapes动态添加到MGLShapeSource_Ios_Mapbox - Fatal编程技术网

Ios 是否可以将MGLShapes动态添加到MGLShapeSource

Ios 是否可以将MGLShapes动态添加到MGLShapeSource,ios,mapbox,Ios,Mapbox,我希望以点云的形式在单个MGLStyleLayer上跟踪用户的位置。这样以后就可以显示和隐藏它。但我不知道如何修改MGLShapeSource。我看到的唯一方法是创建一个全新的MGLShape并将其分配给MGLShapeSource。但我 只需向现有形状添加一个点(每秒),点存储将快速增长 该层的创建如下所示: func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle { addLayer(to: style

我希望以点云的形式在单个MGLStyleLayer上跟踪用户的位置。这样以后就可以显示和隐藏它。但我不知道如何修改MGLShapeSource。我看到的唯一方法是创建一个全新的MGLShape并将其分配给MGLShapeSource。但我 只需向现有形状添加一个点(每秒),点存储将快速增长

该层的创建如下所示:

func mapView(_ mapView: MGLMapView, didFinishLoading style: MGLStyle {
    addLayer(to: style)
}

private func addLayer(to style: MGLStyle) {

    // Create initial data
    let geoJson = [
        "type" : "FeatureCollection",
        "features" :
            [
                [
                    "type" : "Feature",
                    "geometry" : [
                        "type": "Point",
                        "coordinates": [0.0, 0.0]
                    ],
                    "properties" : [
                        "name" : "somewhere in the ocean"
                    ]
                ]
            ]
        ] as [String : Any]

    // Create layer with source and add them to style
    do {
        let geoJsonData = try JSONSerialization.data(withJSONObject: geoJson)
        let shape = try MGLShape(data: geoJsonData, encoding: String.Encoding.utf8.rawValue)
        let source = MGLShapeSource(identifier: "heatMapSource", shape: shape, options: nil)
        let layer = MGLCircleStyleLayer(identifier: "heatMapLayer", source: source)
        layer.sourceLayerIdentifier = "heatMap"
        layer.isVisible = true
        style.addSource(source)
        style.addLayer(layer)
        self.heatMapSource = source
        self.heatMapLayer = layer
    } catch {
        print("\(#function): \(error)")
    }
}
Mapbox版本为:Mapbox iOS SDK 3.5.4

编辑:重新指定新形状当前的工作方式如下:

// Create a 'modified' dictionary
let geoJson = [
    "type" : "FeatureCollection",
    "features" :
        [
            [
                "type" : "Feature",
                "geometry" : [
                    "type": "Point",
                    "coordinates": [0.0, 0.0]
                ],
                "properties" : [
                    "name" : "somewhere in the ocean"
                ]
            ],
            [
                "type" : "Feature",
                "geometry" : [
                    "type": "Point",
                    "coordinates": [1.0, 0.0]
                ],
                "properties" : [
                    "name" : "somewhere else in the ocean"
                ]
            ]
        ]
    ] as [String : Any]

// Assign new shape
do {
    let geoJsonData = try JSONSerialization.data(withJSONObject: geoJson)
    let shape = try MGLShape(data: geoJsonData, encoding: String.Encoding.utf8.rawValue)
    heatMapSource?.shape = shape
} catch {
    print("\(#function): \(error)")
}

有没有找到答案?@局外人很抱歉,我们从未找到解决办法。这个问题是在一个maps sdk研究项目中提出的,所以对我们来说不是什么大问题。