Пример #1
0
 public static MapCoord ToMapCoord(this Location mapPoint)
 {
     var mapCoord = new MapCoord {Latitude = mapPoint.Latitude,
                                  Longitude = mapPoint.Longitude,
                                  ProjectionWkid = CoordinateSystems.Wgs84ProjectionWkid};
     return mapCoord;
 }
        public static MapCoord ToWebMercator(this MapCoord mapCoord)
        {
            if (mapCoord.ProjectionWkid == CoordinateSystems.WebMercatorProjectionWkid)
            {
                return mapCoord;
            }

            var wgs84XLon = mapCoord.Longitude;
            var wgs84YLat = mapCoord.Latitude;

            if ((Math.Abs(wgs84XLon) > 180 || Math.Abs(wgs84YLat) > 90))
            {
                throw new IndexOutOfRangeException("WGS84 coordinates out of bounds");
            }

            var num = wgs84XLon * 0.017453292519943295;
            var x = 6378137.0 * num;
            var a = wgs84YLat * 0.017453292519943295;

            wgs84XLon = x;
            wgs84YLat = 3189068.5 * Math.Log((1.0 + Math.Sin(a)) / (1.0 - Math.Sin(a)));

            var reprojPoint = new MapCoord { Latitude = wgs84YLat,
                                            Longitude = wgs84XLon,
                                            ProjectionWkid = CoordinateSystems.WebMercatorProjectionWkid
                                            };
            return reprojPoint;
        }
        public static double KmDistanceFrom(this MapCoord wgs84Coords1, MapCoord wgs84Coords2)
        {
            var location1Reproj = wgs84Coords1.ToWebMercator();
            var location2Reproj = wgs84Coords2.ToWebMercator();

            var meterDistance = location1Reproj.ToPoint().DistanceFrom(location2Reproj.ToPoint());
            var kmDistance = meterDistance/1000;
            return kmDistance;
        }
Пример #4
0
        private void ShowFlag(MapCoord coord, Uri imageUri)
        {
            var mapPoint = coord.ToEsriWebMercatorMapPoint();
            if (_flagsGraphicsLayer == null || mapPoint == null)
            {
                throw new ArgumentNullException("coord", "Coordinates or Graphic layers is null");
            }

            var symbol = new PictureMarkerSymbol {Source = new BitmapImage(imageUri),
                                                  OffsetX=1,
                                                  OffsetY=30};

            // Ação quando o usuário responder o local
            var graphic = new Graphic
                              {
                                  Symbol = symbol,
                                  Geometry = mapPoint
                              };

            _flagsGraphicsLayer.Graphics.Add(graphic);
        }
        public static MapCoord ToGeographic(this MapCoord mapCoord)
        {
            if (mapCoord.ProjectionWkid == CoordinateSystems.Wgs84ProjectionWkid)
            {
                return mapCoord;
            }

            var mercatorXLon = mapCoord.Longitude;
            var mercatorYLat = mapCoord.Latitude;

            if (Math.Abs(mercatorXLon) < 180 && Math.Abs(mercatorYLat) < 90)
            {
                throw new IndexOutOfRangeException("It appears to be Geographic coordinates");
            }

            if ((Math.Abs(mercatorXLon) > 20037508.3427892) || (Math.Abs(mercatorYLat) > 20037508.3427892))
            {
                throw new IndexOutOfRangeException("WebMercator coordinates out of bounds");
            }

            var x = mercatorXLon;
            var y = mercatorYLat;
            var num3 = x / 6378137.0;
            var num4 = num3 * 57.295779513082323;
            var num5 = Math.Floor(((num4 + 180.0) / 360.0));
            var num6 = num4 - (num5 * 360.0);
            var num7 = 1.5707963267948966 - (2.0 * Math.Atan(Math.Exp((-1.0 * y) / 6378137.0)));
            mercatorXLon = num6;
            mercatorYLat = num7 * 57.295779513082323;

            var reprojPoint = new MapCoord
                                  {
                                      Latitude = mercatorYLat,
                                      Longitude = mercatorXLon,
                                      ProjectionWkid = CoordinateSystems.Wgs84ProjectionWkid
                                  };
            return reprojPoint;
        }
Пример #6
0
 public void ShowTargetFlag(MapCoord coord, Uri imageUri)
 {
     ShowFlag(coord, imageUri);
 }
Пример #7
0
 public void ShowClickedFlag(MapCoord coord, Uri imageUri)
 {
     ShowFlag(coord, imageUri);
 }
Пример #8
0
        private void ShowFlag(MapCoord coord, Uri imageUri, bool target)
        {
            if (_informationLayer == null)
            {
                throw new NullReferenceException("Map not already created!");
            }

            var hotSpot = new HotSpot();

            if (target)
            {
                hotSpot.X = 0.15;
                hotSpot.Y = 0.85;
            }
            else
            {
                hotSpot.X = 0.22;
                hotSpot.Y = 0.9;
            }

            var reprojCoord = coord.ToGeographic();
            var mapPinPoint = new MapPinPoint {ImageSource = new BitmapImage(imageUri)};
            MapLayer.SetHotSpot(mapPinPoint, hotSpot);
            MapLayer.SetLocation(mapPinPoint, new Location(reprojCoord.Latitude, reprojCoord.Longitude));
            _informationLayer.Items.Add(mapPinPoint);
        }
Пример #9
0
 private void MapClick(MapCoord coord)
 {
     ShowClickedFlag(coord);
 }
Пример #10
0
 private void ShowClickedFlag(MapCoord handCoordinate)
 {
     _mapHandler.ShowClickedFlag(handCoordinate, new Uri("/Resources/Images/flag_target.png", UriKind.Relative));
 }