Search code examples
swiftxcodemapboxscenekitaugmented-reality

How to fix 'Extra argument 'zoom' in call' for MapBox sceneKit (AR scene)?


The error states that it doesn't require the 'zoom' argument but all online documentation suggests otherwise.

When I've removed the 'zoom' argument it errors once again and says it needs two arguments. Am I missing another argument which I need to add instead?

Also, I've tried using the 'multiplier' argument which someone suggested using that didn't work either.

func createTerrain() {
    terrainNode = TerrainNode(minLat: minLat, maxLat: maxLat,
                              minLon: minLon, maxLon: maxLon)
    
    if let terrainNode = terrainNode {
        terrainNode.scale = terrainNodeScale // Scale down map
        terrainNode.position = SCNVector3Make(0, -0.15, 0) // Place map slightly below clouds
        terrainNode.geometry?.materials = defaultMaterials() // Add default materials
        scene.rootNode.addChildNode(terrainNode)
        
        terrainNode.fetchTerrainHeights(minWallHeight: 100.0, enableDynamicShadows: true, progress: { progress, total in
        }, completion: {
            NSLog("Terrain load complete")
        })
        
        terrainNode.fetchTerrainTexture("mapbox/satellite-v9", zoom: 14, progress: { progress, total in
        }, completion: { image in
            NSLog("Texture load complete")
            terrainNode.geometry?.materials[4].diffuse.contents = image
        })
    }
}

This is the part of the code that at the terrain texture and satellite image to the terrain node. I assume that I need to know the 'zoom' level but it's wanting it removed.

Any help would be greatly appreciated as I'm currently ripping my hair out. Thank you very much to anyone who comes across this post and can offer any suggestions.

Screenshot of error


Solution

  • The fetchTextureTerrain method seems to have been changed from your:

    terrainNode.fetchTerrainTexture("mapbox/satellite-v9", zoom: 14, progress: { progress, total in
            }, completion: { image in
                NSLog("Texture load complete")
                terrainNode.geometry?.materials[4].diffuse.contents = image
            })
    

    To something like:

    terrainNode.fetchTerrainTexture("mapbox/satellite-v9", progress: { progress, total in
          // Some code here.
    
          }, completion: { image, fetchError in
                if let fetchError = fetchError {
                    NSLog("Texture load failed: \(fetchError.localizedDescription)")
                }
                if image != nil {
                    NSLog("Texture load complete")
                    terrainNode.geometry?.materials[4].diffuse.contents = image
                }
          })
    

    Notice the extra fetchError term in the completion block (and the removal of the zoom term that you noticed earlier). Unrelated but for a purely swift implementation you should use print statements and avoid the NSLogs.