How To Create Map View without XAML in ArcGIS Runtime for .NET?

1902
5
05-19-2017 12:37 AM
Data_Integra_DinamikaDID
New Contributor

Hallo, everybody, I am new in ArcGIS. I need your help. I have a problem when I try to create MapView without XAML. I use ArcGIS Runtime for.NET 10.2.7. All of the tutorials always create it within XAML. But in my condition, I have to create the MapView in my Library, not within XAML. Is there anybody can help me, please?

I have tried to create a map view without XAML. But when I use the ScreenToLocation method based on it, the result always NULL. Is it mean the map view doesn't create, right?

0 Kudos
5 Replies
dotMorten_esri
Esri Notable Contributor

You cannot use ScreenToLocation until the MapView control is Loaded and presented on the UI tree. Just instantiating a MapView doesn't "activate" it. It must be added to the visual view in your app.

Why do you not want to use XAML? You can still use XAML in libraries by exposing Controls and UserControls to be included in the app. If a library does not expose things as controls or user controls, they really shouldn't be creating visual elements. It's really the responsibility of the app and not the library to create visual elements (but of course you can have a class library expose custom controls that the app will instantiate and render)

0 Kudos
Data_Integra_DinamikaDID
New Contributor

Thank you for your answer Mr.Morten Nielsen,


Actually, I have three projects here. There are Client, Server, and UserControl which contains with ArcGIS. Let me call the UserControl as UserControl map. I use the UserControl in the client. To synchronize between client and server, I created libraries which contain functions calculating map, such as the function of GetMapPosition, GetMapDepth, etc. In the GetMapPosition, I need to use the function of ScreenToLocation. For access it, I must create the map view in my libraries class. That's why I must create the map view without XAML. Are you have a solution for this?

0 Kudos
dotMorten_esri
Esri Notable Contributor

> For access it, I must create the map view in my libraries class. That's why I must create the map view without XAML.

I don't really understand what you're getting at. You can create view in XAML using class libraries. In fact the MapView control is a custom control created using XAML in a class library. You then take that view and instantiate it in your app. The control _will not_ work until you actually add it to your app UI tree. It cannot run without being on screen.

I'm also not clear on your server-component here. Note that the ArcGIS Runtime is a client app library and doesn't support running in a server environment (and license also prohibits it as well).

0 Kudos
Data_Integra_DinamikaDID
New Contributor

Hi Morten Nielsen, thank for response.

Mostly MapView and Map is declared under xaml file like picture below. That (in my opinion) will make MapView and Map only stored inside App Windows instead top level class in my Software, whereas we have 2 project (Server and Client) that need same MapView and Map object.

MapView declaration in xaml file

I plan to create MapView and Map object in App Manager then in ClientApp constructor i passing it to UserControl.

system scheme

This is what I do to implement my plan.

1. Create MapView and Map in AppManager.SimMap
Create MapView and Map in AppManager

2. Passing Map inside SimMap to UserControl in AppClient.

With this I hope MapView that I create in SimMap able to work like MapView inside UserControl (xaml). But when I test it, I always get Null MapPoint.

Is there any minimum requirement for MapView parameter (maybe) like Size, Position to able work like usual?

0 Kudos
dotMorten_esri
Esri Notable Contributor

You could do that. You just need to insert the map view.

LayoutRootGrid.Children.Add(AppManager.Instance().SimilationMap());‍‍

However I would recommend against that. You really should declare MapView in your app, and not your library. It's considered bad practice to create UI in code, rather than XAML Markup.

Instead your library returns the Map, not the MapView. Your app should be creating the views, your libraries model/viewmodel data, and potentially declare custom controls you can add (through markup) to your app xaml. That also gives you binding support. Ie

<esri:MapView Map="{Binding AppManagerViewModel.Map}" />‍‍

As a getting started reference, I'd encourage you to research the "MVVM" pattern. There's plenty of online presentations that can walk you through and give you a good basis on how to architect XAML-based apps.

Lastly your Map and MapView are not sharable. A map can only be rendered in a single MapView at a given time (you can however move it to a different MapView), and you also can't render a visual element like the MapView in multiple places. And as stated earlier, none of this is supported in a server-context, so this would only be supported on a client-side. You could from the server end pass down the Map JSON representation, and then instantiate a map from that json.

0 Kudos