Select to view content in your preferred language

How to clone a KmlLayer including loaded KmlDataSet?

07-10-2023 07:01 AM
Labels (3)
Occasional Contributor


I've implemented myself a global/static KmlLayer cache () as loading its data from the web can take a long time.

When I add the instance from the cache to a MapView

MapView1.Map!.OperationalLayers(_staticCache.First(k => k.Dataset?.Source == uri);

all is fine.

But if I do this to a second time:

MapView2.Map!.OperationalLayers(_staticCache.First(k => k.Dataset?.Source == uri);

I get an "Object already owned" exception.

So far so good...I thought...then I just clone the already loaded instance of the cache before I add it to the MapViews...

MapView1.Map!.OperationalLayers((_staticCache.First(k => k.Dataset?.Source == uri).Clone());
MapView2.Map!.OperationalLayers((_staticCache.First(k => k.Dataset?.Source == uri).Clone());


But the clones status (of the Dataset) is `NotLoaded` and the data is downloaded again from the web!

Why is the loaded data not cloned? I haven't found any way to clone/copy or use KmlData once loaded from the web multiple times. How do I do that?




0 Kudos
1 Reply
Occasional Contributor

Can nobody give me a hint here? Its really a bad thing to download the same data multiple times just to show them in different maps!

0 Kudos