0

I am facing such problem: while some package is downloading with Carto PackageManager, I can’t see neither other downloaded offline maps nor online maps of any other place.

In other words, if there is some package that is pending or downloading, I can't use any map, I can see only gray background from offline or online vector sources in any location, but as soon as map packages are fully downloaded the map appears in a regular way.

In debugger in both cases no differences, I easily pass over lines (this is full code of mapView initialization) :

        MapView = new MapView();
        ConstraintUtils.StretchView(MapContainerView, MapView);

        var baseLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleDefault);
        baseLayer.Language = MapElementsConstants.LocalizationLanguage;
        MapView.Layers.Add(baseLayer);
        _source = new LocalVectorDataSource(MapView.Options.BaseProjection);
        _layer = new VectorLayer(_source);

        MapView.Layers.Add(_layer);
        MapView.SetZoom(zoom: MapElementsConstants.MapControlHighZoomingCoeff, durationSeconds: 0);
        MapView.UserInteractionEnabled = false;

Is this feature of CartoSDK or it may be a bug in my application?

All iOS versions (11.2 in particular), Carto NUGET Package version : 4.0.2

1

Could you please provide your entire code? This doesn't seem to be intended behaviour. Once you have downloaded one map package and added CartoOfflineVectorTileLayer, you should see the entire map on zoom 0.

Download progress and other events should be available once you attach a PackageManagerListener.

If you haven't downloaded any single package, then CartoOfflineVectorTileLayer should display a gray background, yes, but CartoOnlineVectorTileLayer should still display a map (if you're online)

EDIT:

I created a sample application on Xamarin.iOS with SDK v4.0.2 and everything is working as intended, maps are properly shown. cf application below:

AppDelegate:

[Register("AppDelegate")]
public class AppDelegate : UIApplicationDelegate
{
    const string LicenseKey = "<YOUR-LICENSE-KEY>";

    public override UIWindow Window { get; set; }

    public UINavigationController Controller { get; set; }

    public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
        MapView.RegisterLicense(LicenseKey);

        var initial = new MyViewController();
        Controller = new UINavigationController(initial);

        Window = new UIWindow(UIScreen.MainScreen.Bounds);

        Window.RootViewController = Controller;

        Window.MakeKeyAndVisible();

        return true;
    }

}

Controller:

public class MyViewController : UIViewController
{
    public MapView ContentView { get; set; }

    public PackageListener Listener { get; set; }

    public CartoPackageManager Manager { get; set; }

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        ContentView = new MapView();
        View = ContentView;

        var baseLayer = new CartoOnlineVectorTileLayer(CartoBaseMapStyle.CartoBasemapStyleDefault);
        ContentView.Layers.Add(baseLayer);

        var source = "nutiteq.osm";
        var path = GetDocumentDirectory("com.carto.mappackages.test");
        Manager = new CartoPackageManager(source, path);

        Manager.Start();
        Manager.StartPackageListDownload();

        var offlineLayer = new CartoOfflineVectorTileLayer(Manager, CartoBaseMapStyle.CartoBasemapStyleGray);
        ContentView.Layers.Add(offlineLayer);

        Listener = new PackageListener();
        Manager.PackageManagerListener = Listener;

        Listener.OnPackageListUpdate += Listener_OnPackageListUpdate;
        Listener.OnPackageUpdate += Listener_OnPackageUpdate;
        Listener.OnPackageStatusChange += Listener_OnPackageStatusChange;
    }

    public override void ViewWillAppear(bool animated)
    {
        base.ViewWillAppear(animated);
    }

    public override void ViewWillDisappear(bool animated)
    {
        base.ViewWillDisappear(animated);
    }

    void Listener_OnPackageListUpdate(object sender, EventArgs e)
    {
        Console.WriteLine("updated package list");
        // Initially downloaded this package
        //Manager.StartPackageDownload("EE");
        // After EE was downloaded, tested with a second download:
        Manager.StartPackageDownload("LV");
    }

    void Listener_OnPackageUpdate(object sender, PackageEventArgs e)
    {
        Console.WriteLine("updated package");
    }

    void Listener_OnPackageStatusChange(object sender, PackageStatusEventArgs e)
    {
        Console.WriteLine("status change: " + e.Status.Progress + "%");
    }

    public static string GetDocumentDirectory(string withFolder)
    {
        string documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

        string path = Path.Combine(documents, withFolder + "/");

        Directory.CreateDirectory(path);
        return path;
    }
}

Listener convenience class to implement EventHandlers:

public class PackageListener : PackageManagerListener
{
    public EventHandler<EventArgs> OnPackageListUpdate;
    public EventHandler<EventArgs> OnPackageListFail;

    public EventHandler<PackageEventArgs> OnPackageCancel;
    public EventHandler<PackageEventArgs> OnPackageUpdate;
    public EventHandler<PackageStatusEventArgs> OnPackageStatusChange;
    public EventHandler<PackageFailedEventArgs> OnPackageFail;

    public PackageListener()
    {

    }

    public override void OnPackageListUpdated ()
    {
        // Called when package list is downloaded.
        // Now you can start downloading packages
        if (OnPackageListUpdate != null) {
            OnPackageListUpdate(this, EventArgs.Empty); 
        }
    }

    public override void OnPackageListFailed ()
    {
        Console.WriteLine("PackageListener: OnPackageListFailed");
        if (OnPackageListFail != null)
        {
            OnPackageListFail(this, EventArgs.Empty);
        }
    }

    public override void OnPackageStatusChanged (string id, int version, PackageStatus status)
    {
        Console.WriteLine("PackageListener: OnPackageStatusChanged");
        // A portion of package is downloaded. Update your progress bar here.
        // Notice that the view and SDK are in different threads, so data copy id needed
        if (OnPackageStatusChange != null)
        {
            OnPackageStatusChange(this, new PackageStatusEventArgs { Id = id, Version = version, Status = status });
        }
    }

    public override void OnPackageCancelled (string id, int version)
    {
        Console.WriteLine("PackageListener: OnPackageCancelled");
        // Called when you called cancel package download
        if (OnPackageCancel != null)
        {
            OnPackageCancel(this, new PackageEventArgs { Id = id, Version = version });
        }
    }

    public override void OnPackageUpdated (string id, int version)
    {
        Console.WriteLine("PackageListener: OnPackageUpdated");
        // Called when package is updated
        if (OnPackageUpdate != null)
        {
            OnPackageUpdate(this, new PackageEventArgs { Id = id, Version = version });
        }
    }

    public override void OnPackageFailed (string id, int version, PackageErrorType errorType)
    {
        Console.WriteLine("PackageListener: OnPackageFailed");

        if (OnPackageFail != null)
        {
            OnPackageFail(this, new PackageFailedEventArgs { Id = id, Version = version, ErrorType = errorType });
        }
    }
}

public class PackageEventArgs
{
    public string Id { get; set; }

    public int Version { get; set; }
}

public class PackageStatusEventArgs : PackageEventArgs
{
    public PackageStatus Status { get; set; }
}

public class PackageFailedEventArgs : PackageEventArgs
{
    public PackageErrorType ErrorType { get; set; }
}
  • I have added details and code. Also I claim that code with OfflineVectorSource is not executed in described situation. – Oleg Kosuakiv Jan 3 '18 at 8:42
  • @OlegKosuakiv see edited answer – Nikitah Jan 3 '18 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.