Как добавить слой от mapbox в приложение ios?

Суть задачи: В библиотеке react-native-yamap-shim в ios добавить функционал добавления слоя на карту по пропсам. 1 пропс передает maptype={“custom”} он активирует наш слой, а 2 пропс передает ключ от mapbox. При загрузке скрина подключается слой, если добавлены пропс с mapBox(с ключем), но не активирует его. Если мы передаем в mapType = {“custom”} то активируется слой, если нет то слой деактивируется

Необходимо проработать два пропса:

<YaMap
  mapType={'custom'} // - добавляется тип карты, он и будет активировать наш слой
  mapBox={'КЛЮЧ_ОТ_MA'} // - добавляется ключ от mapbox, чтобы наш слой активировался
/>

Для android уже сделано react-native-yamap-shim, нужно тот же самый функционал перенести в ios

Для понимания можете запустить пример яндекса mapkit-ios-demo.И добавить в CustomLayerViewController :

import UIKit
import YandexMapsMobile

/**
 * This example shows how to add a user-defined layer to the map.
 * We use the UrlProvider class to format requests to a remote server that renders
 * tiles. For simplicity, we ignore map coordinates and zoom here, and
 * just provide a URL for the static image.
 */
class CustomLayerViewController: BaseMapViewController {
    
    var layer: YMKLayer?

    internal class CustomTilesUrlProvider: NSObject, YMKTilesUrlProvider {
        func formatUrl(with tileId: YMKTileId, version: YMKVersion) -> String {
            return "https://api.mapbox.com/v4/mapbox.satellite/\(tileId.z)/\(tileId.x)/\(tileId.y)@2.jpg90?access_token=КЛЮЧ_ОТ_MAPBOX";
        }
    }


    // MapKit  doesn't need Url provider for raster maps.
    internal class DummyUrlProvider : NSObject, YMKResourceUrlProvider {
        override init() {}

        func formatUrl(withResourceId resourceId: String) -> String {
            return "";
        }

        override func isEqual(_ object: Any?) -> Bool {
            return true;
        }
    }

    // Client code must retain strong references to providers and projection
    let tilesUrlProvider = CustomTilesUrlProvider()
    let projection = YMKProjections.sphericalMercator()

    override func viewDidLoad() {
        super.viewDidLoad()
//        YMKMapTypeVectorMap;
        mapView.mapWindow.map.mapType = YMKMapType.vectorMap;

        let layerOptions = YMKLayerOptions(
            active: true,
            nightModeAvailable: true,
            cacheable: true,
            animateOnActivation: true,
            tileAppearingAnimationDuration: 0,
            overzoomMode: .enabled,
            transparent: false
        )

        layer = mapView.mapWindow.map.addLayer(
            withLayerId: "mapkit_logo",
            contentType: "image/jpeg",
            layerOptions: layerOptions,
            tileUrlProvider: tilesUrlProvider,
            imageUrlProvider: YMKImagesDefaultUrlProvider(),
            projection: projection)

        layer!.invalidate(withVersion: "0.0.0")
    
    }
}

Сам с свифтом не работал, направьте, пожалуйста, как это сделать. Спасибо

получилось сделаьт для андроида, а для ios не понимаю куда что подставить


Ответы (0 шт):