mousebird-consulting-inc / WhirlyGlobe

WhirlyGlobe Development
Other
827 stars 253 forks source link

Not all screen is covered by tiles while using MaplyQuadPagingLoader #1600

Closed serhii-londar closed 6 months ago

serhii-londar commented 6 months ago

I have issue with showing data on map using tiles. So I want to fetch and add object per tile and I want to do that on high zoom levels, for example after zoom level 9. But I'm facing issues, because some of the tiles are not loading. For example zoom level 9:

Zoom level 10:

Here is example of the code I use:

class DebugLoaderInterpreter: NSObject, MaplyLoaderInterpreter {
    var loader: MaplyQuadLoaderBase?

    func setLoader(_ loader: MaplyQuadLoaderBase) {
        self.loader = loader
    }

    func data(forTile loadReturn: MaplyLoaderReturn, loader: MaplyQuadLoaderBase) {
        guard let objectReturn = loadReturn as? MaplyObjectLoaderReturn else { return }

        let bb = loader.bounds(for: loadReturn.tileID)

        var locations = [MaplyCoordinate]()
        locations.append(MaplyCoordinate(x: Float(bb.ll.x), y: Float(bb.ll.y)))
        locations.append(MaplyCoordinate(x: Float(bb.ll.x), y: Float(bb.ur.y)))
        locations.append(MaplyCoordinate(x: Float(bb.ur.x), y: Float(bb.ur.y)))
        locations.append(MaplyCoordinate(x: Float(bb.ur.x), y: Float(bb.ll.y)))
        locations.append(MaplyCoordinate(x: Float(bb.ll.x), y: Float(bb.ll.y)))

        let vector = MaplyVectorObject(lineString: &locations, numCoords: Int32(locations.count))
        if let obj = loader.viewC?.addVectors([vector],
                                              desc: [
                                                kMaplyVecWidth: 4.0,
                                                kMaplyWideVecImpl: kMaplyWideVecImplPerf,
                                                kMaplyColor: UIColor.blue
                                              ],
                                              mode: .current) {
            objectReturn.addCompObj(obj)
        }

        let label = MaplyScreenLabel()
        label.loc = MaplyCoordinate(x: Float(bb.ll.x), y: Float(bb.ll.y))
        label.text = "\(loadReturn.tileID.level)"
        label.color = .red

        if let comObj = loader.viewC?.addScreenLabels([label],
                                                      desc: [
                                                        kMaplyTextColor: UIColor.red,
                                                        kMaplyFont: UIFont.boldSystemFont(ofSize: 10.0),
                                                        kMaplyTextOutlineColor: UIColor.white,
                                                        kMaplyTextOutlineSize: 2.0,
                                                        kMaplyEnable: true,
                                                        kMaplyDrawPriority: kMaplyLabelDrawPriorityDefault + 100,
                                                      ],
                                                      mode: .current) {
            objectReturn.addCompObj(comObj)
        }
    }

    func tileUnloaded(_ tileID: MaplyTileID) { }
}

func showDebug() {
        let params = MaplySamplingParams()
        params.minZoom = 1
        params.maxZoom = 20
        params.coordSys = MaplySphericalMercator(webStandard: ())

        debugLoader = MaplyQuadPagingLoader(params: params, tileInfo: nil, loadInterp: DebugLoaderInterpreter(), viewC: globeViewController)
    }

So basically I'm adding MaplyQuadPagingLoader with custom MaplyLoaderInterpreter where I want to fetch and add my objects per tile, in this case I just draw tile edges and add label of tile's zoom level.
I'm using pre built SDK v 3.5 downloaded from releases page.

Please help to resolve my issue.

Thanks in advance.

sjg-wdw commented 6 months ago

If this is on the globe, see if it does it with the map and vice versa. We use this exact configuration to display image tiles, so I don't immediately see what's going wrong.

serhii-londar commented 6 months ago

I found the problem. I was using let bb = loader.bounds(for: loadReturn.tileID) instead of let bb = loader.geoBounds(for: loadReturn.tileID)