示例#1
0
        /// <summary>
        /// End of a draw operation - is tool depended
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void DrawComplete(object sender, DrawEventArgs args)
        {
            try
            {
                if (currentCommand.Equals("Info") || currentCommand.Equals("AddressInfo"))
                {
                    // Use ESRI API for Info
                    Point screenPoint =
                    gisOperations.GetMap().MapToScreen(args.Geometry as MapPoint);
                    GeneralTransform generalTransform =
                    gisOperations.GetMap().TransformToVisual(Application.Current.RootVisual);
                    Point transformScreenPnt = generalTransform.Transform(screenPoint);
                    IEnumerable<Graphic> selected = null;
                    Graphic result = null;
                    FeatureLayer featureLayer = null;
                    if (currentCommand.Equals("Info"))
                    {
                        var selectedLayers = from l in gisOperations.GetLayersData()
                                                                 where l.Selection
                                                                 select l;
                        foreach (var item in selectedLayers)
                        {
                            var layer = (from f in gisOperations.GetMap().Layers
                                                     where f.ID.Equals(item.LayerName)
                                                     select f).FirstOrDefault();
                            if (layer.GetType() == typeof(FeatureLayer))
                            {
                                featureLayer = layer as FeatureLayer;
                                selected = featureLayer.FindGraphicsInHostCoordinates(transformScreenPnt);
                                if (selected != null && selected.Count() > 0)
                                {
                                    // return only one item, the first
                                    result = selected.FirstOrDefault(g => g.Attributes.Count > 0);
                                    if (result != null && result.Attributes != null)
                                    {
                                        break;
                                    }
                                    else
                                        result = null;
                                }
                            }
                        }
                        gisOperations.SetDrawMode(DrawMode.None);
                        gisOperations.ResetCompleteDrawEvent(DrawComplete);
                    }
                    else
                    {
                        // Address info, stop handling of points
                        gisOperations.SetDrawMode(DrawMode.None);
                        gisOperations.ResetCompleteDrawEvent(DrawComplete);
                    }
                    ResultInfoEventArgs resultEventArgs =
                        new ResultInfoEventArgs(screenPoint, args.Geometry as MapPoint, result == null)
                    {
                        LayerId = string.Empty
                    };
                    if (result != null)
                    {
                        resultEventArgs.Attributes = result.Attributes;
                        if (featureLayer != null)
                            resultEventArgs.LayerId = featureLayer.ID;
                    }
                    OnFinishedInfo(resultEventArgs);
                }
                else
                {
                    gisOperations.MapZoom(currentCommand, args.Geometry);
                    gisOperations.SetDrawMode(DrawMode.Rectangle);
                }

            }
            catch (Exception ex)
            {
                messageBoxCustom.Show(String.Format("DrawComplete /{0}", ex.Message),
                    GisTexts.SevereError,
                    MessageBoxCustomEnum.MessageBoxButtonCustom.Ok);
            }
        }
示例#2
0
 protected virtual void OnFinishedInfo(ResultInfoEventArgs e)
 {
     if (finishedInfo != null)
     {
         finishedInfo(this, e);
     }
 }
示例#3
0
 /// <summary>
 /// Event handling for the info query
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void HandleResultQuery(object sender, ResultInfoEventArgs e)
 {
     if (e != null && !e.Error)
     {
         DisplayInfoResults(e);
     }
 }
示例#4
0
 private void HandleGeolocatorResults(object sender, ResultsGeoLocatorEventArgs geoLocatorResults)
 {
     //
     if (geoLocatorResults.result != null && geoLocatorResults.result.Count > 0)
     {
         ResultInfoEventArgs e = new ResultInfoEventArgs(currentPosition, geoLocatorResults.result[0].Location, false)
         {
             Attributes = geoLocatorResults.result[0].Attributes,
             LayerId = string.Empty
         };
         if (locationInputViewModel == null || locationInputViewModel.LocationsSelected.Count == 0)
             DisplayInfoResults(e);
         else
         {
             // Transfer the contents of the result to the stops list
             locationInputViewModel.StopsVisibility = Visibility.Visible;
             locationInputViewModel.RouteDirectionsVisibility = Visibility.Collapsed;
             locationInputViewModel.SelectionVisibility = Visibility.Collapsed;
             locationInputViewModel.LocationsSelected.Add(new GeoLocatorDetail()
             {
                 Attributes = geoLocatorResults.result[0].Attributes,
                 Location = geoLocatorResults.result[0].Location,
                 Match = geoLocatorResults.result[0].Match,
                 Title = geoLocatorResults.result[0].Title
             });
             gisOperations.GetSelectLayer().Graphics.Add(new Graphic()
             {
                 Geometry = geoLocatorResults.result[0].Location,
                 Symbol = geoLocator.GetLocationMarker(),
                 Selected = true
             });
             locationInputViewModel.RefreshStops();
             locationInputViewModel.Zoom2Stops();
         }
     }
 }
示例#5
0
 private void HandleAddressPoint(object sender, ResultInfoEventArgs e)
 {
     // Geocoding request
     geoLocator.SetResultsGeoLocatorHandler(HandleGeolocatorResults);
     currentPosition = e.ScreenPoint;
     geoLocator.FindAddressByLocation(e.InfoPoint);
 }
示例#6
0
 private void DisplayInfoResults(ResultInfoEventArgs e)
 {
     // Create InfoWindow to be used
     if (e.Attributes == null)
         return;
     this.Attributes.AttributeValueList.Clear();
     string objectId = gisOperations.GetFeatureLayerInfo(e.LayerId).ObjectId;
     foreach (var item in e.Attributes)
     {
         if (e.LayerId.Length == 0 || Utilities.IsValidField(item.Key, objectId))
         {
             AttributeFeature attributeFeature = new AttributeFeature() { FieldName = item.Key };
             if (item.Value != null)
                 attributeFeature.Value = Utilities.FormatField(item.Value);
             else
                 attributeFeature.Value = "";
             this.Attributes.AttributeValueList.Add(attributeFeature);
         }
     }
     DataTemplate dataTemplate = this.menuToolbar.LayoutRoot.Resources["AttributesTemplate"] as DataTemplate;
     DataGrid dataGrid = dataTemplate.LoadContent() as DataGrid;
     dataGrid.ItemsSource = this.Attributes.AttributeValueList;
     this.RaisePropertyChanged(() => this.Attributes);
     Grid layoutRoot = gisOperations.GetMap().Parent as Grid;
     window.Anchor = e.InfoPoint;
     window.Map = gisOperations.GetMap();
     window.IsOpen = true;
     window.Content = dataGrid;
     window.Name = "InfoWindow";
     layoutRoot.Children.Add(window);
 }