private void BasemapCombobox_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { int index = BasemapCombobox.SelectedIndex; switch (index) { case 0: MyMapView.Map.Basemap = Basemap.CreateStreetsVector(); break; case 1: MyMapView.Map.Basemap = Basemap.CreateTopographicVector(); break; case 2: MyMapView.Map.Basemap = Basemap.CreateImageryWithLabelsVector(); break; case 3: MyMapView.Map.Basemap = Basemap.CreateStreetsNightVector(); break; default: MyMapView.Map.Basemap = Basemap.CreateOpenStreetMap(); break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
protected override Task DoInitialize() { this.BasemapOperations.ToggleDisplay.RegisterExecute( (args) => { foreach (Layer basemapLayer in args.Map.Map.Basemap.BaseLayers) { basemapLayer.IsVisible = args.ToggleOn; } return(Task.FromResult((object)null)); }, this); this.BasemapOperations.ToggleBasemap.RegisterExecute( (args) => { if (args.ToggleOn) { args.Map.Map.Basemap = Basemap.CreateNavigationVector(); } else { args.Map.Map.Basemap = Basemap.CreateStreetsNightVector(); } return(Task.FromResult((object)null)); }, this); return(Task.CompletedTask); }
public DensifyAndGeneralize() { InitializeComponent(); // Create the map with a default basemap. MyMapView.Map = new Map(Basemap.CreateStreetsNightVector()); // Create and add a graphics overlay. GraphicsOverlay overlay = new GraphicsOverlay(); MyMapView.GraphicsOverlays.Add(overlay); // Create the original geometry: some points along a river. PointCollection points = CreateShipPoints(); // Show the original geometry as red dots on the map. Multipoint originalMultipoint = new Multipoint(points); Graphic originalPointsGraphic = new Graphic(originalMultipoint, new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Colors.Red, 7)); overlay.Graphics.Add(originalPointsGraphic); // Show a dotted red line connecting the original points. _originalPolyline = new Polyline(points); Graphic originalPolylineGraphic = new Graphic(_originalPolyline, new SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Colors.Red, 3)); overlay.Graphics.Add(originalPolylineGraphic); // Show the result (densified or generalized) points as magenta dots on the map. _resultPointGraphic = new Graphic { Symbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Colors.Magenta, 7), ZIndex = 999 }; overlay.Graphics.Add(_resultPointGraphic); // Connect the result points with a magenta polyline. _resultPolylineGraphic = new Graphic { Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Colors.Magenta, 3), ZIndex = 1000 }; overlay.Graphics.Add(_resultPolylineGraphic); // Listen for changes in state. DeviationSlider.ValueChanged += (o, e) => UpdateGeometry("Generalize", SegmentLengthSlider.Value, DeviationSlider.Value); SegmentLengthSlider.ValueChanged += (o, e) => UpdateGeometry("Densify", SegmentLengthSlider.Value, DeviationSlider.Value); // Center the map. MyMapView.SetViewpointGeometryAsync(_originalPolyline.Extent, 100); }
private async void Initialize() { try { // Starting viewpoint for the map view. Viewpoint _startingViewpoint = new Viewpoint(new Envelope(-9812691.11079696, 5128687.20710657, -9812377.9447607, 5128865.36767282, SpatialReferences.WebMercator)); // Create the map. MyMapView.Map = new Map(Basemap.CreateStreetsNightVector()) { InitialViewpoint = _startingViewpoint }; // NOTE: This layer supports any ArcGIS Feature Table that define subtypes. SubtypeFeatureLayer subtypeFeatureLayer = new SubtypeFeatureLayer(new ServiceFeatureTable(new Uri("https://sampleserver7.arcgisonline.com/arcgis/rest/services/UtilityNetwork/NapervilleElectric/FeatureServer/100"))); MyMapView.Map.OperationalLayers.Add(subtypeFeatureLayer); // Select sublayer to control. await subtypeFeatureLayer.LoadAsync(); // Select the sublayer of street lights by name. _sublayer = subtypeFeatureLayer.GetSublayerBySubtypeName("Street Light"); // Set the label definitions using the JSON. _sublayer.LabelDefinitions.Add(LabelDefinition.FromJson(_labelJSON)); // Enable labels for the sub layer. _sublayer.LabelsEnabled = true; // Set the data context for data-binding in XAML. SublayerInfo.DataContext = _sublayer; // Get the default renderer for the sublayer. _defaultRenderer = _sublayer.Renderer.Clone(); // Create a custom renderer for the sublayer. _customRenderer = new SimpleRenderer() { Symbol = new SimpleMarkerSymbol() { Color = Color.Salmon, Style = SimpleMarkerSymbolStyle.Diamond, Size = 20, } }; // Set a default minimum scale. _sublayer.MinScale = 3000; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error); } }
private async void Initialize() { try { // Starting viewpoint for the map view. Viewpoint _startingViewpoint = new Viewpoint(new Envelope(-9812691.11079696, 5128687.20710657, -9812377.9447607, 5128865.36767282, SpatialReferences.WebMercator)); // Create the map. MyMapView.Map = new Map(Basemap.CreateStreetsNightVector()) { InitialViewpoint = _startingViewpoint }; // NOTE: This layer supports any ArcGIS Feature Table that define subtypes. SubtypeFeatureLayer subtypeFeatureLayer = new SubtypeFeatureLayer(new ServiceFeatureTable(new Uri("https://sampleserver7.arcgisonline.com/arcgis/rest/services/UtilityNetwork/NapervilleElectric/FeatureServer/100"))); MyMapView.Map.OperationalLayers.Add(subtypeFeatureLayer); // Select sublayer to control. await subtypeFeatureLayer.LoadAsync(); // Select the sublayer of street lights by name. _sublayer = subtypeFeatureLayer.GetSublayerBySubtypeName("Street Light"); // Set the label definitions using the JSON. _sublayer.LabelDefinitions.Add(LabelDefinition.FromJson(_labelJSON)); // Enable labels for the sub layer. _sublayer.LabelsEnabled = true; // Get the default renderer for the sublayer. _defaultRenderer = _sublayer.Renderer.Clone(); // Create a custom renderer for the sublayer. _customRenderer = new SimpleRenderer() { Symbol = new SimpleMarkerSymbol() { Color = System.Drawing.Color.Salmon, Style = SimpleMarkerSymbolStyle.Diamond, Size = 20, } }; // Update the UI for displaying the current map scale. MyMapView.PropertyChanged += MapViewPropertyChanged; MapScaleLabel.Text = $"Current map scale: 1:{(int)MyMapView.MapScale}"; } catch (Exception ex) { await Application.Current.MainPage.DisplayAlert(ex.GetType().Name, ex.Message, "OK"); } }
private async void Initialize() { StatusGrid.BackgroundColor = new Color(0, 0, 0, 0.5); try { BusyIndicator.IsVisible = true; Status.Text = "Loading Utility Network..."; // Setup Map with Feature Layer(s) that contain Utility Network. MyMapView.Map = new Map(Basemap.CreateStreetsNightVector()) { InitialViewpoint = _startingViewpoint }; // Add the layer with electric distribution lines. FeatureLayer lineLayer = new FeatureLayer(new Uri($"{FeatureServiceUrl}/115")); lineLayer.Renderer = new SimpleRenderer(new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.DarkCyan, 3)); MyMapView.Map.OperationalLayers.Add(lineLayer); // Add the layer with electric devices. FeatureLayer electricDevicelayer = new FeatureLayer(new Uri($"{FeatureServiceUrl}/100")); MyMapView.Map.OperationalLayers.Add(electricDevicelayer); // Create and load the utility network. _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServiceUrl), MyMapView.Map); Status.Text = "Click on the network lines or points to add a utility element."; // Create symbols for starting points and barriers. _startingPointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Cross, System.Drawing.Color.Green, 20d); _barrierPointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.X, System.Drawing.Color.Red, 20d); // Create a graphics overlay. GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); MyMapView.GraphicsOverlays.Add(graphicsOverlay); } catch (Exception ex) { Status.Text = "Loading Utility Network failed..."; await Application.Current.MainPage.DisplayAlert(ex.Message.GetType().Name, ex.Message, "OK"); } finally { BusyIndicator.IsVisible = false; } }
private void Initialize() { // Create the map with a default basemap. _myMapView.Map = new Map(Basemap.CreateStreetsNightVector()); // Create and add a graphics overlay. GraphicsOverlay overlay = new GraphicsOverlay(); _myMapView.GraphicsOverlays.Add(overlay); // Create the original geometry: some points along a river. PointCollection points = CreateShipPoints(); // Show the original geometry as red dots on the map. Multipoint originalMultipoint = new Multipoint(points); Graphic originalPointsGraphic = new Graphic(originalMultipoint, new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.Red, 7)); overlay.Graphics.Add(originalPointsGraphic); // Show a dotted red line connecting the original points. _originalPolyline = new Polyline(points); Graphic originalPolylineGraphic = new Graphic(_originalPolyline, new SimpleLineSymbol(SimpleLineSymbolStyle.Dot, Color.Red, 3)); overlay.Graphics.Add(originalPolylineGraphic); // Show the result (densified or generalized) points as magenta dots on the map. _resultPointGraphic = new Graphic { Symbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.Magenta, 7), ZIndex = 999 }; overlay.Graphics.Add(_resultPointGraphic); // Connect the result points with a magenta polyline. _resultPolylineGraphic = new Graphic { Symbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Magenta, 3), ZIndex = 1000 }; overlay.Graphics.Add(_resultPolylineGraphic); // Center the map. _myMapView.SetViewpointGeometryAsync(_originalPolyline.Extent, 100); }
private async void Initialize() { try { _progressBar.Visibility = Android.Views.ViewStates.Visible; _status.Text = "Loading Utility Network..."; // Setup Map with Feature Layer(s) that contain Utility Network. _myMapView.Map = new Map(Basemap.CreateStreetsNightVector()) { InitialViewpoint = _startingViewpoint }; // Add the layer with electric distribution lines. FeatureLayer lineLayer = new FeatureLayer(new Uri($"{FeatureServiceUrl}/115")); lineLayer.Renderer = new SimpleRenderer(new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.DarkCyan, 3)); _myMapView.Map.OperationalLayers.Add(lineLayer); // Add the layer with electric devices. FeatureLayer electricDevicelayer = new FeatureLayer(new Uri($"{FeatureServiceUrl}/100")); _myMapView.Map.OperationalLayers.Add(electricDevicelayer); // Create and load the utility network. _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServiceUrl), _myMapView.Map); _status.Text = "Click on the network lines or points to add a utility element."; // Create symbols for starting points and barriers. _startingPointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Cross, System.Drawing.Color.Green, 20d); _barrierPointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.X, System.Drawing.Color.Red, 20d); // Create a graphics overlay. GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); _myMapView.GraphicsOverlays.Add(graphicsOverlay); } catch (Exception ex) { _status.Text = "Loading Utility Network failed..."; CreateDialog(ex.Message); } finally { _progressBar.Visibility = Android.Views.ViewStates.Invisible; } }
/// <summary> /// This method loads the feature layer on the map /// </summary> private void LoadFeatureLayer() { try { MyMapView.Map = new Map(); MyMapView.Map.Basemap = Basemap.CreateStreetsNightVector(); Uri popUri = new Uri("https://services1.arcgis.com/4yjifSiIG17X0gW4/arcgis/rest/services/World_Population_Data_2015_from_UN/FeatureServer/0"); FeatureLayer flayer = new FeatureLayer(popUri); MyMapView.Map.OperationalLayers.Add(flayer); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static Basemap FromBasemapType(this BasemapType type) { switch (type) { case BasemapType.DarkGrayCanvasVector: return(Basemap.CreateDarkGrayCanvasVector()); case BasemapType.Imagery: return(Basemap.CreateImagery()); case BasemapType.ImageryWithLabels: return(Basemap.CreateImageryWithLabels()); case BasemapType.ImageryWithLabelsVector: return(Basemap.CreateImageryWithLabelsVector()); case BasemapType.LightGrayCanvas: return(Basemap.CreateLightGrayCanvas()); case BasemapType.LightGrayCanvasVector: return(Basemap.CreateLightGrayCanvasVector()); case BasemapType.NationalGeographic: return(Basemap.CreateNationalGeographic()); case BasemapType.NavigationVector: return(Basemap.CreateNavigationVector()); case BasemapType.Oceans: return(Basemap.CreateOceans()); case BasemapType.OpenStreetMap: return(Basemap.CreateOpenStreetMap()); case BasemapType.Streets: return(Basemap.CreateStreets()); case BasemapType.StreetsNightVector: return(Basemap.CreateStreetsNightVector()); case BasemapType.StreetsVector: return(Basemap.CreateStreetsVector()); case BasemapType.StreetsWithReliefVector: return(Basemap.CreateStreetsWithReliefVector()); case BasemapType.TerrainWithLabels: return(Basemap.CreateTerrainWithLabels()); case BasemapType.TerrainWithLabelsVector: return(Basemap.CreateTerrainWithLabelsVector()); case BasemapType.Topographic: return(Basemap.CreateTopographic()); case BasemapType.TopographicVector: return(Basemap.CreateTopographicVector()); default: throw new NotImplementedException(type.ToString()); } }
/// <summary> /// Loading feature layer /// </summary> private void LoadFeatureLayer() { try { MyMapView.Map = new Esri.ArcGISRuntime.Mapping.Map(); MyMapView.Map.Basemap = Basemap.CreateStreetsNightVector(); Esri.ArcGISRuntime.Mapping.Map MyMap = new Esri.ArcGISRuntime.Mapping.Map(Esri.ArcGISRuntime.Mapping.Basemap.CreateTerrainWithLabelsVector()); Uri coronaUri = new Uri("https://services1.arcgis.com/4yjifSiIG17X0gW4/arcgis/rest/services/World_Population_Data_2015_from_UN/FeatureServer/0"); FeatureLayer flayer = new FeatureLayer(coronaUri); MyMapView.Map.OperationalLayers.Add(flayer); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private async void Initialize() { try { // Disable the UI. FilterOptions.Visibility = Visibility.Collapsed; // Create and load the utility network. _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServiceUrl)); // Create a map with layers in this utility network. MyMapView.Map = new Map(Basemap.CreateStreetsNightVector()); MyMapView.Map.OperationalLayers.Add(new FeatureLayer(new Uri($"{FeatureServiceUrl}/{LineLayerId}"))); MyMapView.Map.OperationalLayers.Add(new FeatureLayer(new Uri($"{FeatureServiceUrl}/{DeviceLayerId}"))); // Get a trace configuration from a tier. UtilityDomainNetwork domainNetwork = _utilityNetwork.Definition.GetDomainNetwork(DomainNetworkName) ?? throw new ArgumentException(DomainNetworkName); UtilityTier tier = domainNetwork.GetTier(TierName) ?? throw new ArgumentException(TierName); _configuration = tier.TraceConfiguration; // Create a trace filter. _configuration.Filter = new UtilityTraceFilter(); // Get a default starting location. UtilityNetworkSource networkSource = _utilityNetwork.Definition.GetNetworkSource(NetworkSourceName) ?? throw new ArgumentException(NetworkSourceName); UtilityAssetGroup assetGroup = networkSource.GetAssetGroup(AssetGroupName) ?? throw new ArgumentException(AssetGroupName); UtilityAssetType assetType = assetGroup.GetAssetType(AssetTypeName) ?? throw new ArgumentException(AssetTypeName); Guid globalId = Guid.Parse(GlobalId); _startingLocation = _utilityNetwork.CreateElement(assetType, globalId); // Create a graphics overlay. GraphicsOverlay overlay = new GraphicsOverlay(); MyMapView.GraphicsOverlays.Add(overlay); // Display starting location. IEnumerable <ArcGISFeature> elementFeatures = await _utilityNetwork.GetFeaturesForElementsAsync(new List <UtilityElement> { _startingLocation }); MapPoint startingLocationGeometry = elementFeatures.FirstOrDefault().Geometry as MapPoint; Symbol symbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Cross, System.Drawing.Color.LimeGreen, 25d); Graphic graphic = new Graphic(startingLocationGeometry, symbol); overlay.Graphics.Add(graphic); // Set the starting viewpoint. await MyMapView.SetViewpointAsync(new Viewpoint(startingLocationGeometry, 3000)); // Build the choice list for categories populated with the `Name` property of each `UtilityCategory` in the `UtilityNetworkDefinition`. Categories.ItemsSource = _utilityNetwork.Definition.Categories; Categories.SelectedItem = _utilityNetwork.Definition.Categories.First(); // Enable the UI. FilterOptions.Visibility = Visibility.Visible; } catch (Exception ex) { await new MessageDialog(ex.Message, ex.GetType().Name).ShowAsync(); } finally { LoadingBar.Visibility = Visibility.Collapsed; } }
private async void Initialize() { try { _activityIndicator.StartAnimating(); _statusLabel.Text = "Loading Utility Network..."; // Create a map. _myMapView.Map = new Map(Basemap.CreateStreetsNightVector()) { InitialViewpoint = _startingViewpoint }; // Add the layer with electric distribution lines. FeatureLayer lineLayer = new FeatureLayer(new Uri($"{FeatureServiceUrl}/115")); UniqueValue mediumVoltageValue = new UniqueValue("N/A", "Medium Voltage", new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.DarkCyan, 3), 5); UniqueValue lowVoltageValue = new UniqueValue("N/A", "Low Voltage", new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, System.Drawing.Color.DarkCyan, 3), 3); lineLayer.Renderer = new UniqueValueRenderer(new List <string>() { "ASSETGROUP" }, new List <UniqueValue>() { mediumVoltageValue, lowVoltageValue }, "", new SimpleLineSymbol()); _myMapView.Map.OperationalLayers.Add(lineLayer); // Add the layer with electric devices. FeatureLayer electricDevicelayer = new FeatureLayer(new Uri($"{FeatureServiceUrl}/100")); _myMapView.Map.OperationalLayers.Add(electricDevicelayer); // Set the selection color for features in the map view. _myMapView.SelectionProperties = new SelectionProperties(System.Drawing.Color.Yellow); // Create and load the utility network. _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServiceUrl), _myMapView.Map); // Get the utility tier used for traces in this network. For this data set, the "Medium Voltage Radial" tier from the "ElectricDistribution" domain network is used. UtilityDomainNetwork domainNetwork = _utilityNetwork.Definition.GetDomainNetwork("ElectricDistribution"); _mediumVoltageTier = domainNetwork.GetTier("Medium Voltage Radial"); // More complex datasets may require using utility trace configurations from different tiers. The following LINQ expression gets all tiers present in the utility network. //IEnumerable<UtilityTier> tiers = _utilityNetwork.Definition.DomainNetworks.Select(domain => domain.Tiers).SelectMany(tier => tier); // Create symbols for starting locations and barriers. _startingPointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Cross, System.Drawing.Color.LightGreen, 25d); _barrierPointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.X, System.Drawing.Color.OrangeRed, 25d); // Create a graphics overlay. GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); _myMapView.GraphicsOverlays.Add(graphicsOverlay); // Set the instruction text. _statusLabel.Text = "Click on the network lines or points to add a utility element."; } catch (Exception ex) { _statusLabel.Text = "Loading Utility Network failed..."; new UIAlertView("Error", ex.Message, (IUIAlertViewDelegate)null, "OK", null).Show(); } finally { _activityIndicator.StopAnimating(); } }
private async void Initialize() { try { IsBusy.Visibility = Visibility.Visible; Status.Text = "Loading Utility Network..."; // Setup Map with Feature Layer(s) that contain Utility Network. MyMapView.Map = new Map(Basemap.CreateStreetsNightVector()) { InitialViewpoint = _startingViewpoint }; // Add the layer with electric distribution lines. FeatureLayer lineLayer = new FeatureLayer(new Uri($"{FeatureServiceUrl}/115")); UniqueValue mediumVoltageValue = new UniqueValue("N/A", "Medium Voltage", new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.DarkCyan, 3), 5); UniqueValue lowVoltageValue = new UniqueValue("N/A", "Low Voltage", new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, System.Drawing.Color.DarkCyan, 3), 3); lineLayer.Renderer = new UniqueValueRenderer(new List <string>() { "ASSETGROUP" }, new List <UniqueValue>() { mediumVoltageValue, lowVoltageValue }, "", new SimpleLineSymbol()); MyMapView.Map.OperationalLayers.Add(lineLayer); // Add the layer with electric devices. FeatureLayer electricDevicelayer = new FeatureLayer(new Uri($"{FeatureServiceUrl}/100")); MyMapView.Map.OperationalLayers.Add(electricDevicelayer); // Set the selection color for features in the map view. MyMapView.SelectionProperties = new SelectionProperties(System.Drawing.Color.Yellow); // Create and load the utility network. _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServiceUrl), MyMapView.Map); // Update the trace configuration UI. TraceTypes.ItemsSource = Enum.GetValues(typeof(UtilityTraceType)); TraceTypes.SelectedIndex = 0; // Get the utility tier used for traces in this network. For this data set, the "Medium Voltage Radial" tier from the "ElectricDistribution" domain network is used. UtilityDomainNetwork domainNetwork = _utilityNetwork.Definition.GetDomainNetwork("ElectricDistribution"); _mediumVoltageTier = domainNetwork.GetTier("Medium Voltage Radial"); // More complex datasets may require using utility trace configurations from different tiers. The following LINQ expression gets all tiers present in the utility network. //IEnumerable<UtilityTier> tiers = _utilityNetwork.Definition.DomainNetworks.Select(domain => domain.Tiers).SelectMany(tier => tier); // Create symbols for starting locations and barriers. _startingPointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Cross, System.Drawing.Color.LightGreen, 25d); _barrierPointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.X, System.Drawing.Color.OrangeRed, 25d); // Create a graphics overlay. GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); MyMapView.GraphicsOverlays.Add(graphicsOverlay); // Set the instruction text. Status.Text = "Click on the network lines or points to add a utility element."; } catch (Exception ex) { Status.Text = "Loading Utility Network failed..."; MessageBox.Show(ex.Message, ex.Message.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error); } finally { MainUI.IsEnabled = true; IsBusy.Visibility = Visibility.Hidden; } }
private async void Initialize() { // As of ArcGIS Enterprise 10.8.1, using utility network functionality requires a licensed user. The following login for the sample server is licensed to perform utility network operations. AuthenticationManager.Current.ChallengeHandler = new ChallengeHandler(async(info) => { try { // WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample. string sampleServer7User = "******"; string sampleServer7Pass = "******"; return(await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass)); } catch (Exception ex) { await new MessageDialog2(ex.Message, ex.Message.GetType().Name).ShowAsync(); return(null); } }); try { IsBusy.Visibility = Visibility.Visible; Status.Text = "Loading Utility Network..."; // Create a map. MyMapView.Map = new Map(Basemap.CreateStreetsNightVector()) { InitialViewpoint = _startingViewpoint }; // Add the layer with electric distribution lines. FeatureLayer lineLayer = new FeatureLayer(new Uri($"{FeatureServiceUrl}/3")); UniqueValue mediumVoltageValue = new UniqueValue("N/A", "Medium Voltage", new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.DarkCyan, 3), 5); UniqueValue lowVoltageValue = new UniqueValue("N/A", "Low Voltage", new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, System.Drawing.Color.DarkCyan, 3), 3); lineLayer.Renderer = new UniqueValueRenderer(new List <string>() { "ASSETGROUP" }, new List <UniqueValue>() { mediumVoltageValue, lowVoltageValue }, "", new SimpleLineSymbol()); MyMapView.Map.OperationalLayers.Add(lineLayer); // Add the layer with electric devices. FeatureLayer electricDevicelayer = new FeatureLayer(new Uri($"{FeatureServiceUrl}/0")); MyMapView.Map.OperationalLayers.Add(electricDevicelayer); // Set the selection color for features in the map view. MyMapView.SelectionProperties = new SelectionProperties(System.Drawing.Color.Yellow); // Create and load the utility network. _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServiceUrl), MyMapView.Map); // Update the trace configuration UI. TraceTypes.ItemsSource = new List <UtilityTraceType>() { UtilityTraceType.Connected, UtilityTraceType.Subnetwork, UtilityTraceType.Upstream, UtilityTraceType.Downstream }; TraceTypes.SelectedIndex = 0; // Get the utility tier used for traces in this network. For this data set, the "Medium Voltage Radial" tier from the "ElectricDistribution" domain network is used. UtilityDomainNetwork domainNetwork = _utilityNetwork.Definition.GetDomainNetwork("ElectricDistribution"); _mediumVoltageTier = domainNetwork.GetTier("Medium Voltage Radial"); // More complex datasets may require using utility trace configurations from different tiers. The following LINQ expression gets all tiers present in the utility network. //IEnumerable<UtilityTier> tiers = _utilityNetwork.Definition.DomainNetworks.Select(domain => domain.Tiers).SelectMany(tier => tier); // Create symbols for starting locations and barriers. _startingPointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Cross, System.Drawing.Color.LightGreen, 25d); _barrierPointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.X, System.Drawing.Color.OrangeRed, 25d); // Create a graphics overlay. GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); MyMapView.GraphicsOverlays.Add(graphicsOverlay); // Set the instruction text. Status.Text = "Click on the network lines or points to add a utility element."; } catch (Exception ex) { Status.Text = "Loading Utility Network failed..."; await new MessageDialog2(ex.Message, ex.GetType().Name).ShowAsync(); } finally { EnableControls(); IsBusy.Visibility = Visibility.Collapsed; } }
private async void Initialize() { // As of ArcGIS Enterprise 10.8.1, using utility network functionality requires a licensed user. The following login for the sample server is licensed to perform utility network operations. AuthenticationManager.Current.ChallengeHandler = new ChallengeHandler(async(info) => { try { // WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample. string sampleServer7User = "******"; string sampleServer7Pass = "******"; return(await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass)); } catch (Exception ex) { await new MessageDialog2(ex.Message, ex.Message.GetType().Name).ShowAsync(); return(null); } }); try { // Disable the UI. FilterOptions.Visibility = Visibility.Collapsed; // Create and load the utility network. _utilityNetwork = await UtilityNetwork.CreateAsync(new Uri(FeatureServiceUrl)); // Create a map with layers in this utility network. MyMapView.Map = new Map(Basemap.CreateStreetsNightVector()); MyMapView.Map.OperationalLayers.Add(new FeatureLayer(new Uri($"{FeatureServiceUrl}/{LineLayerId}"))); MyMapView.Map.OperationalLayers.Add(new FeatureLayer(new Uri($"{FeatureServiceUrl}/{DeviceLayerId}"))); // Get a trace configuration from a tier. UtilityDomainNetwork domainNetwork = _utilityNetwork.Definition.GetDomainNetwork(DomainNetworkName) ?? throw new ArgumentException(DomainNetworkName); UtilityTier tier = domainNetwork.GetTier(TierName) ?? throw new ArgumentException(TierName); _configuration = tier.TraceConfiguration; // Create a trace filter. _configuration.Filter = new UtilityTraceFilter(); // Get a default starting location. UtilityNetworkSource networkSource = _utilityNetwork.Definition.GetNetworkSource(NetworkSourceName) ?? throw new ArgumentException(NetworkSourceName); UtilityAssetGroup assetGroup = networkSource.GetAssetGroup(AssetGroupName) ?? throw new ArgumentException(AssetGroupName); UtilityAssetType assetType = assetGroup.GetAssetType(AssetTypeName) ?? throw new ArgumentException(AssetTypeName); Guid globalId = Guid.Parse(GlobalId); _startingLocation = _utilityNetwork.CreateElement(assetType, globalId); // Create a graphics overlay. GraphicsOverlay overlay = new GraphicsOverlay(); MyMapView.GraphicsOverlays.Add(overlay); // Display starting location. IEnumerable <ArcGISFeature> elementFeatures = await _utilityNetwork.GetFeaturesForElementsAsync(new List <UtilityElement> { _startingLocation }); MapPoint startingLocationGeometry = elementFeatures.FirstOrDefault().Geometry as MapPoint; Symbol symbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Cross, System.Drawing.Color.LimeGreen, 25d); Graphic graphic = new Graphic(startingLocationGeometry, symbol); overlay.Graphics.Add(graphic); // Set the starting viewpoint. await MyMapView.SetViewpointAsync(new Viewpoint(startingLocationGeometry, 3000)); // Build the choice list for categories populated with the `Name` property of each `UtilityCategory` in the `UtilityNetworkDefinition`. Categories.ItemsSource = _utilityNetwork.Definition.Categories; Categories.SelectedItem = _utilityNetwork.Definition.Categories.First(); // Enable the UI. FilterOptions.Visibility = Visibility.Visible; } catch (Exception ex) { await new MessageDialog2(ex.Message, ex.GetType().Name).ShowAsync(); } finally { LoadingBar.Visibility = Visibility.Collapsed; } }
public Basemap GetBaseMap(CusMapView cusMapView) { switch (cusMapView.Map.MapType) { case MapType.Imagery: return(Basemap.CreateImagery()); case MapType.Streets: return(Basemap.CreateStreets()); case MapType.ImageryWithLabels: return(Basemap.CreateImageryWithLabels()); case MapType.ImageryWithLabelsVector: return(Basemap.CreateImageryWithLabelsVector()); case MapType.LightGrayCanvas: return(Basemap.CreateLightGrayCanvas()); case MapType.LightGrayCanvasVector: return(Basemap.CreateLightGrayCanvasVector()); case MapType.DarkGrayCanvasVector: return(Basemap.CreateDarkGrayCanvasVector()); case MapType.NationalGeographic: return(Basemap.CreateNationalGeographic()); case MapType.Oceans: return(Basemap.CreateOceans()); case MapType.StreetsVector: return(Basemap.CreateStreetsVector()); case MapType.StreetsWithReliefVector: return(Basemap.CreateStreetsWithReliefVector()); case MapType.StreetsNightVector: return(Basemap.CreateStreetsNightVector()); case MapType.NavigationVector: return(Basemap.CreateNavigationVector()); case MapType.TerrainWithLabels: return(Basemap.CreateTerrainWithLabels()); case MapType.TerrainWithLabelsVector: return(Basemap.CreateTerrainWithLabelsVector()); case MapType.Topographic: return(Basemap.CreateTopographic()); case MapType.TopographicVector: return(Basemap.CreateTopographicVector()); case MapType.OpenStreetMap: return(Basemap.CreateOpenStreetMap()); case MapType.WebMap: if (!string.IsNullOrEmpty(cusMapView.Map.WebMapUrl)) { return(new Basemap(new Uri(cusMapView.Map.WebMapUrl))); } throw new ArgumentOutOfRangeException(nameof(cusMapView.Map.WebMapUrl), cusMapView.Map.WebMapUrl, null); default: throw new ArgumentOutOfRangeException(nameof(cusMapView.Map.MapType), cusMapView.Map.MapType, null); } }
private async void Initialize() { // As of ArcGIS Enterprise 10.8.1, using utility network functionality requires a licensed user. The following login for the sample server is licensed to perform utility network operations. AuthenticationManager.Current.ChallengeHandler = new ChallengeHandler(async(info) => { try { // WARNING: Never hardcode login information in a production application. This is done solely for the sake of the sample. string sampleServer7User = "******"; string sampleServer7Pass = "******"; return(await AuthenticationManager.Current.GenerateCredentialAsync(info.ServiceUri, sampleServer7User, sampleServer7Pass)); } catch (Exception ex) { await new MessageDialog2(ex.Message, ex.GetType().Name).ShowAsync(); return(null); } }); try { // Starting viewpoint for the map view. Viewpoint _startingViewpoint = new Viewpoint(new Envelope(-9812691.11079696, 5128687.20710657, -9812377.9447607, 5128865.36767282, SpatialReferences.WebMercator)); // Create the map. MyMapView.Map = new Map(Basemap.CreateStreetsNightVector()) { InitialViewpoint = _startingViewpoint }; // NOTE: This layer supports any ArcGIS Feature Table that define subtypes. SubtypeFeatureLayer subtypeFeatureLayer = new SubtypeFeatureLayer(new ServiceFeatureTable(new Uri("https://sampleserver7.arcgisonline.com/server/rest/services/UtilityNetwork/NapervilleElectric/FeatureServer/0"))); MyMapView.Map.OperationalLayers.Add(subtypeFeatureLayer); // Select sublayer to control. await subtypeFeatureLayer.LoadAsync(); // Select the sublayer of street lights by name. _sublayer = subtypeFeatureLayer.GetSublayerBySubtypeName("Street Light"); // Create a text symbol for styling the sublayer label definition. TextSymbol textSymbol = new TextSymbol { Size = 12, OutlineColor = Color.White, Color = Color.Blue, HaloColor = Color.White, HaloWidth = 3, }; // Create a label definition with a simple label expression. LabelExpression simpleLabelExpression = new SimpleLabelExpression("[nominalvoltage]"); LabelDefinition labelDefinition = new LabelDefinition(simpleLabelExpression, textSymbol) { Placement = Esri.ArcGISRuntime.ArcGISServices.LabelingPlacement.PointAboveRight, UseCodedValues = true, }; // Add the label definition to the sublayer. _sublayer.LabelDefinitions.Add(labelDefinition); // Enable labels for the sub layer. _sublayer.LabelsEnabled = true; // Set the data context for data-binding in XAML. SublayerInfo.DataContext = _sublayer; // Get the default renderer for the sublayer. _defaultRenderer = _sublayer.Renderer.Clone(); // Create a custom renderer for the sublayer. _customRenderer = new SimpleRenderer() { Symbol = new SimpleMarkerSymbol() { Color = Color.Salmon, Style = SimpleMarkerSymbolStyle.Diamond, Size = 20, } }; // Set a default minimum scale. _sublayer.MinScale = 3000; } catch (Exception ex) { await new MessageDialog2(ex.Message, ex.GetType().Name).ShowAsync(); } }