0

I am trying this 'open mobile map' example using .mmpk, and uesed code under the 'Forms' tag of this web link: OpenMobileMap,Forms tab However the code behind does not compile. I got error: 'DataManager does not exist in the current context'. Any idea ?

I used the 'ArcGIS Runrtime App (Xamarin.Forms Shared) template in Visual Studio 2017 and put the code behind (C#) in the 'MapPage.exml.cs file.

1 Answers1

1

Sorry to hear that you're having trouble.

The sample viewer for .NET (available on GitHub) uses the Data Manager to download sample data from ArcGIS Online. Individual samples use that class to download the data they need.

DataManager is not a component of ArcGIS Runtime. You can find the implementation used in the sample viewer here, if you're interested in seeing how it works.

Alternatively, you could include the .mmpk in your deployed package or you could write your own code to download the .mmpk.

For example, the following code finds the appropriate directory for downloaded data:

public string GetDataFolder()
{
    #if NETFX_CORE
        return Windows.Storage.ApplicationData.Current.LocalFolder.Path;
    #else
        return System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);
    #endif
}

And the following code downloads an item from ArcGIS Online (the approach taken in the sample viewer):

// ItemId is the item's identifier on ArcGIS Online
private async Task GetData(string itemId)
{
    // Create the portal
    var portal = await ArcGISPortal.CreateAsync().ConfigureAwait(false);

    // Create the portal item
    var item = await PortalItem.CreateAsync(portal, itemId).ConfigureAwait(false);

    // Create the SampleData folder
    var tempFile = Path.Combine(GetDataFolder(), "Data");
    createDir(new DirectoryInfo(tempFile));

    // Get the full path to the specific file
    tempFile = Path.Combine(tempFile, item.Name);

    // Download the file
    using (var s = await item.GetDataAsync().ConfigureAwait(false))
    {
        using (var f = File.Create(tempFile))
        {
            await s.CopyToAsync(f).ConfigureAwait(false);
        }
    }
}

In the API reference documentation, the code referencing DataManager is replaced with code that assumes the data has already been downloaded (example). That hasn't been done for the code in the sample doc section. I've opened an issue to address this in a future release.

Edit: there was another question I responded to, but it looks like it was lost, so I want to add it here. The referenced 'Data Manager' code has a feature to unzip zip archives. That code requires a reference to System.IO.Compression.FileSystem. You can use Visual Studio to add a reference (right click 'references' in each individual platform project, select 'Add reference', then search). An example of the updated .csproj file is on GitHub.

Nathan Castle
  • 310
  • 4
  • 9