예제 #1
0
        private void TrackOverlay_TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e)
        {
            if (mapModel.MapControl.TrackOverlay.TrackMode == TrackMode.Polygon)
            {
                PolygonShape polygonShape = e.TrackShape as PolygonShape;
                if (polygonShape != null)
                {
                    double area     = -1;
                    string areaUnit = "sq.m.";
                    switch (SelectedUnitSystem)
                    {
                    case UnitSystem.Metric:
                        areaUnit = "sq.m.";
                        area     = polygonShape.GetArea(GeographyUnit.Meter, AreaUnit.SquareMeters);
                        break;

                    case UnitSystem.Imperial:
                        areaUnit = "ac.";
                        area     = polygonShape.GetArea(GeographyUnit.Meter, AreaUnit.Acres);
                        break;
                    }
                    if (area > 0)
                    {
                        string content = string.Format(CultureInfo.InvariantCulture, "Area: {0} {1}", area.ToString("N1"), areaUnit);
                        ShowPopup(new PointShape(polygonShape.OuterRing.Vertices[polygonShape.OuterRing.Vertices.Count - 2]), content);
                    }
                    mapModel.MapControl.TrackOverlay.TrackShapeLayer.InternalFeatures.LastOrDefault().Tag = "Measure";
                }
            }

            if (mapModel.MapControl.TrackOverlay.TrackMode == TrackMode.Line)
            {
                string    unit      = string.Empty;
                LineShape lineShape = e.TrackShape as LineShape;
                if (lineShape != null)
                {
                    double lenth = 0;
                    if (SelectedUnitSystem == UnitSystem.Metric)
                    {
                        lenth = lineShape.GetLength(GeographyUnit.Meter, DistanceUnit.Meter);
                        unit  = "m";
                        if (lenth >= 1000)
                        {
                            unit  = "km";
                            lenth = Math.Round(lenth / 1000d, 1, MidpointRounding.AwayFromZero);
                        }
                    }
                    else if (SelectedUnitSystem == UnitSystem.Imperial)
                    {
                        lenth = lineShape.GetLength(GeographyUnit.Meter, DistanceUnit.Feet);
                        unit  = "ft";
                        if (lenth >= 5280)
                        {
                            unit  = "mi";
                            lenth = Math.Round(lenth / 5280d, 1, MidpointRounding.AwayFromZero);
                        }
                    }

                    string lengthString = lenth.ToString("N1");
                    string content      = string.Format(CultureInfo.InvariantCulture, "Total Length: {0} {1}", lengthString, unit);
                    ShowPopup(new PointShape(lineShape.Vertices[lineShape.Vertices.Count - 1]), content);
                    mapModel.MapControl.TrackOverlay.TrackShapeLayer.InternalFeatures.LastOrDefault().Tag = "Measure";
                }
            }
        }
        //private void SetupAnimationForOverlay(LayerOverlay overlay)
        //{
        //    overlay.Drawing -= overlay_Drawing;
        //    overlay.Drawing += overlay_Drawing;
        //    overlay.Drawn -= overlay_Drawn;
        //    overlay.Drawn += overlay_Drawn;
        //}

        private void WpfMap_MapClick(object sender, MapClickWpfMapEventArgs e)
        {
            if (isIdentify)
            {
                ThinkGeo.MapSuite.Shapes.PointShape point = e.WorldLocation;
                if (!map.Overlays.Contains(chartsOverlayName))
                {
                    return;
                }
                LayerOverlay overlay = map.Overlays[chartsOverlayName] as LayerOverlay;

                var features = new Collection <Feature>();
                NauticalChartsFeatureLayer hydrographyFeatureLayer = null;
                foreach (var item in overlay.Layers)
                {
                    NauticalChartsFeatureLayer itemLayer = item as NauticalChartsFeatureLayer;
                    itemLayer.Open();
                    features = itemLayer.QueryTools.GetFeaturesIntersecting(point.GetBoundingBox(), ReturningColumnsType.AllColumns);

                    if (features.Count > 0)
                    {
                        hydrographyFeatureLayer = itemLayer;
                        break;
                    }
                }

                if (features.Count > 0)
                {
                    List <FeatureInfo> selectedFeatures = new List <FeatureInfo>();

                    foreach (var item in features)
                    {
                        double       area      = double.MaxValue;
                        PolygonShape areaShape = item.GetShape() as PolygonShape;
                        if (areaShape != null)
                        {
                            area = areaShape.GetArea(map.MapUnit, AreaUnit.SquareMeters);
                        }
                        selectedFeatures.Add(new FeatureInfo(item, hydrographyFeatureLayer.Name, area));
                    }

                    if (map.Overlays.Contains(highlightOverlayName))
                    {
                        map.Overlays.Remove(highlightOverlayName);
                    }

                    IEnumerable <FeatureInfo> featureInfos = selectedFeatures.OrderBy(p => p.Area);
                    SelectedFeatureInfo = featureInfos.FirstOrDefault();
                    NauticalChartsFeatureSource featureSource = hydrographyFeatureLayer.FeatureSource as NauticalChartsFeatureSource;
                    if (featureSource != null)
                    {
                        ChartSelectedItem = new ChartSelectedItem(featureSource.NauticalChartsPathFilename, featureInfos);
                    }
                }
                else
                {
                    if (map.Overlays.Contains(highlightOverlayName))
                    {
                        map.Overlays.Remove(highlightOverlayName);
                    }
                    map.Refresh();
                }
            }
        }
예제 #3
0
 public float GetArea()
 {
     return((_polygonShape != null) ? _polygonShape.GetArea() : 0f);
 }