private async void MyMapView_Loaded(object sender, RoutedEventArgs e) { try { //Create a new webmap with basemap and operational layers var webmap = new WebMap() { Basemap = CreateBasemapLayer(), OperationalLayers = new List<WebMapLayer>() { CreateDynamicServiceLayer(), CreateStateLayerWithPopup(), await CreateFeatureCollectionLayer() } }; // Load the new webmap into the current UI MyMapView.Map = await LoadWebMapAsync(webmap); MyMapView.Map.InitialViewpoint = new Viewpoint( new Envelope(-14470183.421, 3560814.811, -11255400.943, 5399444.790, SpatialReferences.WebMercator)); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
public ArcGisPortalWebMapItem(ArcGISPortalItem arcGisPortalItem, WebMap webMap, bool isEditable, bool isSyncable) { _arcGisPortalItem = arcGisPortalItem; _webMap = webMap; _isEditable = isEditable; _isSyncable = isSyncable; }
private async Task SetupWebMap() { //Create a new webmap with basemap and operational layers var webmap = new WebMap() { BaseMap = CreateBasemapLayer(), OperationalLayers = new List<WebMapLayer>() { CreateDynamicServiceLayer(), CreateStateLayerWithPopup(), await CreateFeatureCollectionLayer() } }; // Load the new webmap into the current UI var mapView = new MapView(); mapView.Map = await LoadWebMapAsync(webmap); mapView.Map.InitialExtent = new Envelope(-20000000, 1100000, -3900000, 11000000); layoutGrid.Children.Add(mapView); }
void qt_ExecuteCompleted(object sender, QueryEventArgs e) { #region Since featureset does not include layerdefinition, we would have to populate it with appropriate drawinginfo Dictionary<string, object> layerdef = new Dictionary<string, object>(); Dictionary<string, object> defdictionary = new Dictionary<string, object>() { { "id", 0 }, { "name", "Earthquakes from last 7 days" } }; Dictionary<string, object> renderer = new Dictionary<string, object>(); renderer.Add("type", "simple"); renderer.Add("style", "esriSMSCircle"); int[] color = new int[] { 255, 0, 0, 255 }; renderer.Add("color", color); renderer.Add("size", 4); int[] outlinecolor = new int[] { 0, 0, 0, 255 }; defdictionary.Add("drawingInfo", renderer); layerdef.Add("layerDefinition", defdictionary); #endregion //Add a FeatureCollection to operational layers FeatureCollection featureCollection = null; if (e.FeatureSet.Features.Count > 0) { var sublayer = new WebMapSubLayer(); sublayer.FeatureSet = e.FeatureSet; sublayer.AddCustomProperty("layerDefinition", layerdef); featureCollection = new FeatureCollection { SubLayers = new List<WebMapSubLayer> { sublayer } }; } if (featureCollection != null) operationLayers.Add(new WebMapLayer { FeatureCollection = featureCollection }); //Create a new webmap object and add base map and operational layers webmap = new WebMap() { BaseMap = basemap, OperationalLayers = operationLayers }; Document webmapdoc = new Document(); webmapdoc.GetMapCompleted += (a, b) => { if (b.Error == null) { b.Map.Extent = new ESRI.ArcGIS.Client.Geometry.Envelope(-20000000, 1100000, -3900000, 11000000); LayoutRoot.Children.Add(b.Map); } }; webmapdoc.GetMapAsync(webmap); }
public void TriggerLoadWebMapEvent(WebMap webMap, ArcGISPortal arcGisPortal) { LoadWebMap(webMap, arcGisPortal); }
// Loads the given webmap private async Task<Map> LoadWebMapAsync(WebMap webmap) { var portal = await ArcGISPortal.CreateAsync(); var vm = await WebMapViewModel.LoadAsync(webmap, portal); return vm.Map; }
/// <summary> /// Get a web map from the selected portal item and display it in the app. /// </summary> private async void AddMapItem_Click(object sender, RoutedEventArgs e) { if (this.MapItemListBox.SelectedItem == null) { return; } // Clear status messages MessagesTextBlock.Text = string.Empty; var sb = new StringBuilder(); try { // Clear the current MapView control from the app MyMapGrid.Children.Clear(); // See if we're using the public or secured portal; get the appropriate object reference ArcGISPortal portal = null; if (_usingPublicPortal) { portal = _publicPortal; } else { portal = _pkiSecuredPortal; } // Throw an exception if the portal is null if (portal == null) { throw new Exception("Portal has not been instantiated."); } // Get the portal item ID from the selected listbox item (read it from the Tag property) var itemId = (this.MapItemListBox.SelectedItem as ListBoxItem).Tag.ToString(); // Use the item ID to create an ArcGISPortalItem from the appropriate portal var portalItem = await ArcGISPortalItem.CreateAsync(portal, itemId); // Create a WebMap from the portal item (all items in the list represent web maps) var webMap = await WebMap.FromPortalItemAsync(portalItem); if (webMap != null) { // Create a WebMapViewModel using the WebMap var myWebMapViewModel = await WebMapViewModel.LoadAsync(webMap, portal); // Create a new MapView control to display the WebMapViewModel's Map; add it to the app var mv = new MapView { Map = myWebMapViewModel.Map }; MyMapGrid.Children.Add(mv); } // Report success sb.AppendLine("Successfully loaded web map from item #" + itemId + " from " + portal.Uri.Host); } catch (Exception ex) { // Add an error message sb.AppendLine("Error accessing web map: " + ex.Message); } finally { // Show messages MessagesTextBlock.Text = sb.ToString(); } }
private void TryLoadWebMap(string itemId) { try { // Create a new WebMap Document ESRI.ArcGIS.Client.WebMap.Document document = new ESRI.ArcGIS.Client.WebMap.Document(); // Handle the GetMapCompleted event. document.GetMapCompleted += (s, getMapCompletedEventArgs) => { // Check the Error property of the GetMapCompletedEventArgs for a connection or login failure. if (getMapCompletedEventArgs.Error != null) { // Show an error message box string message = getMapCompletedEventArgs.Error.Message + "\nWould you like to retry?"; MessageBoxResult result = MessageBox.Show(message, "Error Loading WebMap", MessageBoxButton.YesNo, MessageBoxImage.Error); if (result == MessageBoxResult.Yes) TryLoadWebMap(itemId); else Application.Current.Shutdown(); return; } // Webmap loaded sucessfully, insert the loaded map into the window and continue MapGrid.Children.Insert(0, getMapCompletedEventArgs.Map); _map = getMapCompletedEventArgs.Map; _webMap = getMapCompletedEventArgs.WebMap; _username = MainSignInDialog.UserName; MapLoaded(getMapCompletedEventArgs); }; // Call the GetMayAsync method to retrieve the WebMap by ArcGIS.com item identifier. document.GetMapAsync(itemId, null); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
void qt_ExecuteCompleted(object sender, QueryEventArgs e) { #region Since featureset does not include layerdefinition, we would have to populate it with appropriate drawinginfo Dictionary <string, object> layerdef = new Dictionary <string, object>(); Dictionary <string, object> defdictionary = new Dictionary <string, object>() { { "id", 0 }, { "name", "Earthquakes from last 7 days" } }; Dictionary <string, object> renderer = new Dictionary <string, object>(); renderer.Add("type", "simple"); renderer.Add("style", "esriSMSCircle"); int[] color = new int[] { 255, 0, 0, 255 }; renderer.Add("color", color); renderer.Add("size", 4); int[] outlinecolor = new int[] { 0, 0, 0, 255 }; defdictionary.Add("drawingInfo", renderer); layerdef.Add("layerDefinition", defdictionary); #endregion //Add a FeatureCollection to operational layers FeatureCollection featureCollection = null; if (e.FeatureSet.Features.Count > 0) { var sublayer = new WebMapSubLayer(); sublayer.FeatureSet = e.FeatureSet; sublayer.AddCustomProperty("layerDefinition", layerdef); featureCollection = new FeatureCollection { SubLayers = new List <WebMapSubLayer> { sublayer } }; } if (featureCollection != null) { operationLayers.Add(new WebMapLayer { FeatureCollection = featureCollection }); } //Create a new webmap object and add base map and operational layers webmap = new WebMap() { BaseMap = basemap, OperationalLayers = operationLayers }; Document webmapdoc = new Document(); webmapdoc.GetMapCompleted += (a, b) => { if (b.Error == null) { b.Map.Extent = new ESRI.ArcGIS.Client.Geometry.Envelope(-20000000, 1100000, -3900000, 11000000); LayoutRoot.Children.Add(b.Map); } }; webmapdoc.GetMapAsync(webmap); }
private async Task <WebMap> UpdateWebMap() { try { WebMap = await WebMap.FromPortalItemAsync(PortalItem); if (WebMap == null) { return(null); } WebMapVM = await WebMapViewModel.LoadAsync(WebMap, this.PortalItem.ArcGISPortal); var errors = WebMapVM.LoadErrors.ToArray(); if (errors != null && errors.Any()) { string title = null; string message = null; if (errors.Count() == 1) { WebMapLayer webMapLayer = errors.First().Key; var layerName = webMapLayer.Title ?? webMapLayer.Id ?? webMapLayer.Type; title = string.Format("Unable to add the layer '{0}' in the map.", layerName); message = errors.First().Value.Message; } else { title = string.Format("Unable to add {0} layers in the map.", errors.Count()); foreach (KeyValuePair <WebMapLayer, Exception> error in errors) { WebMapLayer webMapLayer = error.Key; var layerName = webMapLayer.Title ?? webMapLayer.Id ?? webMapLayer.Type; message += layerName + ": " + error.Value.Message + Environment.NewLine; } } var ex = new Exception(message); var _ = App.ShowExceptionDialog(ex, title); } // <start workaround> // This is work around for WebMapViewModel because OutFields is not being set // on the GeodatabaseFeatureServiceTable in the API this will be fixed after Beta. foreach (var featureLayer in OperationalLayers.OfType <FeatureLayer>()) { var webMapLayer = WebMap.OperationalLayers.FirstOrDefault(wml => wml.Id == featureLayer.ID); if (webMapLayer != null && webMapLayer.PopupInfo != null && webMapLayer.PopupInfo.FieldInfos != null && webMapLayer.PopupInfo.FieldInfos.Any()) { var geodatabaseFeatureServiceTable = featureLayer.FeatureTable as GeodatabaseFeatureServiceTable; if (geodatabaseFeatureServiceTable != null && geodatabaseFeatureServiceTable.OutFields == null) { geodatabaseFeatureServiceTable.OutFields = new OutFields(webMapLayer.PopupInfo.FieldInfos.Where(f => f != null).Select(f => f.FieldName)); geodatabaseFeatureServiceTable.RefreshFeatures(false); } } } // <end workaround> } catch (Exception ex) { var _ = App.ShowExceptionDialog(ex, "An exception was caught while trying to open the map."); } return(WebMap); }
// Loads the given webmap private async Task<Map> LoadWebMapAsync(WebMap webmap) { try { var portal = await ArcGISPortal.CreateAsync(); var vm = await WebMapViewModel.LoadAsync(webmap, portal); return vm.Map; } catch (Exception ex) { MessageBox.Show(ex.Message, "Sample Error"); return null; } }
public static string GetMappingToken(this WebMap webMap) { return(webMap.Section.GetMappingToken(webMap.Url)); }
private async Task LoadWebMap(WebMap webMap, ArcGISPortal arcGisPortal) { var vm = await WebMapViewModel.LoadAsync(webMap, arcGisPortal); var mapView = new MapView {Map = vm.Map}; CurrentEsriMapView = mapView; CurrentEsriMapView.MapViewTapped += CurrentEsriMapViewTapped; }