public void TestCacheModifySymbol()
        {
            using (ShimsContext.Create())
              {
            client.Geometry.MapPoint p = new client.Geometry.MapPoint(0.0, 0.0);
            clientfake.ShimGraphic g = new clientfake.ShimGraphic();
            client.FeatureService.Symbols.PictureMarkerSymbol pms = new client.FeatureService.Symbols.PictureMarkerSymbol();
            Uri myUri = new Uri("../../resources/zoom_in_tool_1.bmp", UriKind.RelativeOrAbsolute);

            BitmapDecoder decoder = new BmpBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
            BitmapSource bitmapSource = decoder.Frames[0];
            pms.Source = bitmapSource;
            clientfake.ShimUniqueValueRenderer r = new clientfake.ShimUniqueValueRenderer();
            Dictionary<String, Object> attributes = new Dictionary<String, Object>();
            attributes["uniquedesignation"] = "Wolfpack 1 C";
            attributes["owningunit"] = "2nd Stryker Brigade";
            attributes["type"] = "M1128";
            g.AttributesGet = () => { return attributes; };
            g.GeometryGet = () => { return p; };
            Dictionary<String, String> fields = new Dictionary<String, String>();
            fields["UID"] = "uniquedesignation";
            fields["HF"] = "owningunit";
            fields["LABELS"] = "uniquedesignation";
            fields["DESCFLDS"] = "type";
            fields["DESCFIELD"] = "type";
            int count = cache.RetrieveFeatureCache("EQUIPMENT").Count;
            cache.AddFeature("EQUIPMENT", g, "Type: {type}", "{uniquedesignation}", fields, r);
            fields["LABELS"] = "uniquedesignation,owningunit";
            g.SymbolGet = () => { return pms; };
            cache.UpdateFeature("EQUIPMENT", "Wolfpack 1 C", "Type: {type}", "{uniquedesignation} owned by {owningunit}", g, fields);
            Dictionary<String, Dictionary<String, Object>> fcache = cache.RetrieveFeatureCache("EQUIPMENT");
            Dictionary<String, Object> f = fcache["Wolfpack 1 C"];
            ImageSource imsrc = f["ICON"] as ImageSource;
            Assert.AreEqual(pms.Source, imsrc);
              }
        }
        public MarkerProperties(ESRI.ArcGIS.Client.Map myMap, ESRI.ArcGIS.Client.Geometry.MapPoint point)
        {
            InitializeComponent();

            this.myMap = myMap;
            this.point = point;

            provider = new MarkerProvider(myMap, point);
            cbxSize.SelectionChanged += new SelectionChangedEventHandler(config_SelectionChanged);
            cbxStyle.SelectionChanged += new SelectionChangedEventHandler(config_SelectionChanged);
            rctColor.MouseUp += new MouseButtonEventHandler(rctColor_MouseUp);
            btnOK.Click += new RoutedEventHandler(btnOK_Click);

            FillComboBoxes();
        }
        public TextProperties(ESRI.ArcGIS.Client.Map myMap, ESRI.ArcGIS.Client.Geometry.MapPoint point)
        {
            InitializeComponent();
            isReadOnlyMode = false;

            this.myMap = myMap;
            this.point = point;

            provider = new TextProvider(myMap, point);
            txtFont.TextChanged += new TextChangedEventHandler(config_TextChanged);
            txtText.TextChanged += new TextChangedEventHandler(config_TextChanged);
            rctColor.MouseUp += new MouseButtonEventHandler(rctColor_MouseUp);
            btnFont.Click += new RoutedEventHandler(btnFont_Click);
            btnOK.Click += new RoutedEventHandler(btnOK_Click);
        }
Example #4
0
 private void AddLineSegmentToCache(ESRI.ArcGIS.Client.Geometry.PointCollection pointCollection, double x, double y, double searchDistance, ref Int32 id)
 {
     double distance;
       ESRI.ArcGIS.Client.Geometry.MapPoint lastPoint = null;
       ESRI.ArcGIS.Client.Geometry.MapPoint originPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(x, y);
       foreach (ESRI.ArcGIS.Client.Geometry.MapPoint featurePoint in pointCollection)
       {
     if (lastPoint != null)
     {
       ESRI.ArcGIS.Client.Geometry.Polyline snapLine = GeometryUtil.Line(lastPoint, featurePoint);
       if (GeometryUtil.FindPerpendicularDistance(snapLine, originPoint, out distance))
     if (distance < searchDistance)
       _snapObjects[id++] = snapLine;
     }
     lastPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(featurePoint.X, featurePoint.Y);
       }
 }
Example #5
0
 public static ESRI.ArcGIS.Client.Geometry.Polyline CreateGeoForZoom(ESRI.ArcGIS.Client.Geometry.Geometry mp)
 {
     ESRI.ArcGIS.Client.Geometry.MapPoint mp1 = new ESRI.ArcGIS.Client.Geometry.MapPoint()
     {
         X = (mp as ESRI.ArcGIS.Client.Geometry.MapPoint).X + 10000,
         Y = (mp as ESRI.ArcGIS.Client.Geometry.MapPoint).Y + 10000
     };
     ESRI.ArcGIS.Client.Geometry.MapPoint mp2 = new ESRI.ArcGIS.Client.Geometry.MapPoint()
     {
         X = (mp as ESRI.ArcGIS.Client.Geometry.MapPoint).X - 10000,
         Y = (mp as ESRI.ArcGIS.Client.Geometry.MapPoint).Y - 10000
     };
     System.Collections.ObjectModel.ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection> path = new System.Collections.ObjectModel.ObservableCollection<ESRI.ArcGIS.Client.Geometry.PointCollection>();
     ESRI.ArcGIS.Client.Geometry.PointCollection plist = new ESRI.ArcGIS.Client.Geometry.PointCollection();
     plist.Add(mp2 as ESRI.ArcGIS.Client.Geometry.MapPoint);
     plist.Add(mp1);
     path.Add(plist);
     ESRI.ArcGIS.Client.Geometry.Polyline pl = new ESRI.ArcGIS.Client.Geometry.Polyline
     {
         Paths = path
     };
     return pl;
 }
Example #6
0
        public static bool ConstructPointLineLineIntersection(ESRI.ArcGIS.Client.Geometry.Polyline line1, ESRI.ArcGIS.Client.Geometry.Polyline line2, out ESRI.ArcGIS.Client.Geometry.MapPoint intersectionPoint)
        {
            intersectionPoint = null;
              if ((line1 == null) || (line2 == null))
            return false;

              // Check if line is 2 point.
              if ((line1.Paths.Count == 0) || (line2.Paths.Count == 0))
            return false;

              // For now we are only going to look at the first segment.
              ESRI.ArcGIS.Client.Geometry.PointCollection pathPoints1 = line1.Paths.First();
              ESRI.ArcGIS.Client.Geometry.PointCollection pathPoints2 = line2.Paths.First();
              Int32 pathPoint1Count = pathPoints1.Count;
              Int32 pathPoint2Count = pathPoints2.Count;
              if ((pathPoint1Count < 1) || (pathPoint2Count < 1))
            return false;

              // Used the following http://en.wikipedia.org/wiki/Line-line_intersection

              ESRI.ArcGIS.Client.Geometry.MapPoint point1f = pathPoints1[0];
              ESRI.ArcGIS.Client.Geometry.MapPoint point1t = pathPoints1[pathPoint1Count - 1];
              ESRI.ArcGIS.Client.Geometry.MapPoint point2f = pathPoints2[0];
              ESRI.ArcGIS.Client.Geometry.MapPoint point2t = pathPoints2[pathPoint2Count - 1];

              double x1 = point1f.X; double y1 = point1f.Y;
              double x2 = point1t.X; double y2 = point1t.Y;
              double x3 = point2f.X; double y3 = point2f.Y;
              double x4 = point2t.X; double y4 = point2t.Y;

              double divider = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
              double intersectX = ((x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4)) / divider;
              double intersectY = ((x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4)) / divider;

              // Now that we have intersection line, lay the source line horizontal (either would do)
              // and rotation intersection point on that. From this we can test if the line is within.

              // Shift coordinates to 0,0
              double x2shift = x2 - x1;
              double y2shift = y2 - y1;
              double intersectXshift = intersectX - x1;
              double intersectYshift = intersectY - y1;

              double lineAngle = Math.Atan2(y2shift, x2shift);

              // Rotate the to point and the test point (clockwise)
              // x' =  x.cos(angle) + y.sin(angle)
              // y' =  y.cos(angle) - x.sin(angle)

              double cosAngle = Math.Cos(lineAngle);
              double sinAngle = Math.Sin(lineAngle);

              double rotX2 = x2shift * cosAngle + y2shift * sinAngle;

              // No need to compute the to point rotated y position. It will just be zero.
              // double rotY2 = y2shift * cosAngle - x2shift * sinAngle;

              double rotXIntersection = intersectXshift * cosAngle + intersectYshift * sinAngle;
              double rotYIntersection = intersectYshift * cosAngle - intersectXshift * sinAngle;

              double selfIntersectTolerance = 0.01;  // don't allow an intersection result to select start/end points
              if ((rotXIntersection < selfIntersectTolerance) || (rotXIntersection > rotX2 - selfIntersectTolerance))
            return false;

              intersectionPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(intersectX, intersectY);

              return true;
        }
        /// <summary>
        /// Create map point for candidate
        /// </summary>
        /// <param name="candidate">Candidate to get geometry</param>
        /// <returns>Map point of candidate position</returns>
        private ESRI.ArcGIS.Client.Geometry.MapPoint _CreatePoint(AddressCandidate candidate)
        {
            ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = null;

            ESRI.ArcLogistics.Geometry.Point geoLocation = candidate.GeoLocation;

            // Project point from WGS84 to Web Mercator if spatial reference of map is Web Mercator
            if (ParentLayer != null && ParentLayer.SpatialReferenceID != null)
            {
                geoLocation = WebMercatorUtil.ProjectPointToWebMercator(geoLocation, ParentLayer.SpatialReferenceID.Value);
            }

            mapPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(geoLocation.X, geoLocation.Y);

            return mapPoint;
        }
        /// <summary>
        /// Create position for editing marker.
        /// </summary>
        /// <param name="obj">Edited object.</param>
        /// <returns>Position for editing marker.</returns>
        private ESRI.ArcGIS.Client.Geometry.MapPoint _CreatePoint(object obj)
        {
            ESRI.ArcLogistics.Geometry.Point? point = null;

            if (_editingMarker.EditingObject is Location)
            {
                Location location = (Location)obj;
                if (location.GeoLocation.HasValue)
                    point = new ESRI.ArcLogistics.Geometry.Point(location.GeoLocation.Value.X, location.GeoLocation.Value.Y);
                else
                    point = null;
            }
            else if (_editingMarker.EditingObject is Order)
            {
                Order order = (Order)_editingMarker.EditingObject;
                if (order.GeoLocation.HasValue)
                    point = new ESRI.ArcLogistics.Geometry.Point(order.GeoLocation.Value.X, order.GeoLocation.Value.Y);
                else
                    point = null;
            }
            else if ((_editingMarker.EditingObject is Zone) || (_editingMarker.EditingObject is Barrier))
            {
                point = _CreatePointForMultiPointObject(obj);
            }

            ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = null;

            if (point.HasValue)
            {
                // Project point from WGS84 to Web Mercator if spatial reference of map is Web Mercator
                if (ParentLayer != null && ParentLayer.SpatialReferenceID != null)
                {
                    point = WebMercatorUtil.ProjectPointToWebMercator(point.Value, ParentLayer.SpatialReferenceID.Value);
                }

                mapPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(point.Value.X, point.Value.Y);
            }

            return mapPoint;
        }
Example #9
0
        public static bool ConstructPointLineCurveIntersection(ESRI.ArcGIS.Client.Geometry.Polyline srcLine, ESRI.ArcGIS.Client.Geometry.MapPoint centerPoint, double bearing, double radius, out ESRI.ArcGIS.Client.Geometry.MapPoint intersectPoint)
        {
            // Given a straight line geometry and a point, find the intersection point.

              // If the line was purely in the x direction, this would be a trivial task:
              //   i) If the x ordinate of the point is with the x range of the line a perpendicular can be drawn
              //  ii) If i) is true, the distance is just the difference in the y values of the line and the point.
              // iii) Using a triangle (perpendicular distance, radius and angle) we can calculate point along line

              // For any general line orientation and point location, we can make it look like the simple case
              // above by:
              //   i) Translating the point and line such that the 'from' end of the line is at the origin
              //  ii) Rotating the point and line about the origin so that the line is indeed purely in the
              //      x direction.
              // iii) Check the x ordinate of the point against the line's xMin and xMax.
              //  iv) The magnitude of the point's y value is the distance.

              intersectPoint = null;
              if ((srcLine == null) || (centerPoint == null))
            return false;

              // Check if line is 2 point.
              if (srcLine.Paths.Count == 0)
            return false;

              // For now we are only going to look at the first segment.
              ESRI.ArcGIS.Client.Geometry.PointCollection pathPoints = srcLine.Paths.First();
              Int32 pointCount = pathPoints.Count;
              if (pointCount < 1)
            return false;

              double srcAngle = Math.PI / 2 - bearing;
              ESRI.ArcGIS.Client.Geometry.MapPoint endPoint = ConstructPoint(centerPoint, bearing, radius);

              double endPointX = endPoint.X;
              double endPointY = endPoint.Y;

              double centerPointX = centerPoint.X;
              double centerPointY = centerPoint.Y;

              ESRI.ArcGIS.Client.Geometry.MapPoint fromPoint = pathPoints[0];
              ESRI.ArcGIS.Client.Geometry.MapPoint toPoint = pathPoints[pointCount - 1];
              if ((fromPoint == null) || (toPoint == null))
            return false;

              double fromX = fromPoint.X;
              double fromY = fromPoint.Y;
              double toX = toPoint.X;
              double toY = toPoint.Y;

              // Translate the coordinates to place the from point at the origin.
              endPointX -= fromX;
              endPointY -= fromY;
              centerPointX -= fromX;
              centerPointY -= fromY;
              toX -= fromX;
              toY -= fromY;

              if ((toX == 0.0) && (toY == 0.0))
            return false;

              double lineAngle = Math.Atan2(toY, toX);

              // Rotate the to point and the test point (clockwise)
              // (not require, since we have rotated the line flat)
              // x' =  x.cos(angle) + y.sin(angle)
              // y' =  y.cos(angle) - x.sin(angle)

              double cosAngle = Math.Cos(lineAngle);
              double sinAngle = Math.Sin(lineAngle);

              double rotToX = toX * cosAngle + toY * sinAngle;

              // No need to compute the to point rotated y position. It will just be zero.
              // double rotToY = toY * cosAngle - toX * sinAngle;

              double rotEndPointX = endPointX * cosAngle + endPointY * sinAngle;
              // Check whether the point is with the bounds of the line
              if ((rotEndPointX <= 0.0) || (rotEndPointX >= rotToX))
            return false;
              double rotEndPointY = endPointY * cosAngle - endPointX * sinAngle;
              double endPointPerpendicularDistance = Math.Abs(rotEndPointY);

              double rotCenterPointX = centerPointX * cosAngle + centerPointY * sinAngle;
              // Check whether the point is with the bounds of the line
              double rotCenterPointY = centerPointY * cosAngle - centerPointX * sinAngle;
              double centerPointPerpendicularDistance = Math.Abs(rotCenterPointY);

              //                                                                   _____
              // Get distance b/t rotCenterPointY and arc intersection point: k = √r²-d²
              double k = Math.Sqrt(Math.Pow(radius, 2) - Math.Pow(centerPointPerpendicularDistance, 2));

              // For the first quadrant we have a good solution. The others we need to decide which
              // way to go on the line, and which origin point to use. The simplest solution is to
              // calculate both solutions and choose the closest.
              //
              // Use the following matrix to rotate solution point back counterclockwise.
              // x' =  x.cos(angle) + y.sin(angle)
              // y' = -y.cos(angle) + x.sin(angle)
              //
              // y=0 since the line is horizontal.
              // rotBackIntersectionPointX = intersectionDistance * cosAngle + 0 * sinAngle;
              // rotBackIntersectionPointY = -0 * cosAngle + intersectionDistance * sinAngle;
              //
              // To complete the solution, add the original offset (fromX, fromY)

              // Intersection point (solution 1)
              double intersectionDistance = rotCenterPointX + k;
              ESRI.ArcGIS.Client.Geometry.MapPoint intersectPoint1 = null;
              if ((intersectionDistance >= 0) || (intersectionDistance <= rotToX))
              {
            double rotBackIntersectionPointX = intersectionDistance * cosAngle + fromX;
            double rotBackIntersectionPointY = intersectionDistance * sinAngle + fromY;
            intersectPoint1 = new ESRI.ArcGIS.Client.Geometry.MapPoint(rotBackIntersectionPointX, rotBackIntersectionPointY);
              }

              // Intersection point (solution 2)
              intersectionDistance = rotCenterPointX - k;
              ESRI.ArcGIS.Client.Geometry.MapPoint intersectPoint2 = null;
              if ((intersectionDistance >= 0) || (intersectionDistance <= rotToX))
              {
            double rotBackIntersectionPointX = intersectionDistance * cosAngle + fromX;
            double rotBackIntersectionPointY = intersectionDistance * sinAngle + fromY;
            intersectPoint2 = new ESRI.ArcGIS.Client.Geometry.MapPoint(rotBackIntersectionPointX, rotBackIntersectionPointY);
              }

              // Choose the solution that's closest to our source point.
              if ((intersectPoint1 != null) && (intersectPoint2 == null))
              {
            intersectPoint = intersectPoint1;
              }
              else if ((intersectPoint1 == null) && (intersectPoint2 != null))
              {
            intersectPoint = intersectPoint2;
              }
              else if ((intersectPoint1 != null) && (intersectPoint2 != null))
              {
            double distance1 = LineLength(intersectPoint1, endPoint);
            double distance2 = LineLength(intersectPoint2, endPoint);
            if (distance1 <= distance2)
              intersectPoint = intersectPoint1;  // if equal, this will also be the solution (quadrant 1)
            else
              intersectPoint = intersectPoint2;
              }
              else
            return false;

              return true;
        }
        /// <summary>
        /// Create location point geometry.
        /// </summary>
        /// <param name="location">Location.</param>
        /// <returns>Location geometry.</returns>
        private ESRI.ArcGIS.Client.Geometry.MapPoint _CreatePoint(Location location)
        {
            ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = null;

            // If location geocoded - create point.
            if (location.GeoLocation.HasValue)
            {
                ESRI.ArcLogistics.Geometry.Point geoLocation = location.GeoLocation.Value;

                // Project point from WGS84 to Web Mercator if spatial reference of map is Web Mercator.
                if (ParentLayer != null && ParentLayer.SpatialReferenceID != null)
                {
                    geoLocation = WebMercatorUtil.ProjectPointToWebMercator(geoLocation, ParentLayer.SpatialReferenceID.Value);
                }

                mapPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(geoLocation.X, geoLocation.Y);
            }
            else
            {
                mapPoint = null;
            }

            return mapPoint;
        }
Example #11
0
 ///////////////////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>
 /// Initializes a new instance of the <c>AsyncReverseGeocodedEventArgs</c> class.
 /// </summary>
 /// <param name="address">Found address.</param>
 /// <param name="location">Address location.</param>
 public AsyncReverseGeocodedEventArgs(Address address, 
     ESRI.ArcGIS.Client.Geometry.MapPoint location, object userState)
     : base(null, false, userState)
 {
     _address = (Address)address.Clone();
     _location = new ESRI.ArcGIS.Client.Geometry.MapPoint(location.X, location.Y);
 }
 public void TestCacheAddFeature()
 {
     using (ShimsContext.Create())
       {
     client.Geometry.MapPoint p = new client.Geometry.MapPoint(0.0, 0.0);
     clientfake.ShimGraphic g = new clientfake.ShimGraphic();
     clientfake.ShimUniqueValueRenderer r = new clientfake.ShimUniqueValueRenderer();
     Dictionary<String, Object> attributes = new Dictionary<String, Object>();
     attributes["uniquedesignation"] = "1-1";
     attributes["higherformation"] = "1";
     g.AttributesGet = () => { return attributes; };
     g.GeometryGet = () => { return p; };
     Dictionary<String, String> fields = new Dictionary<String, String>();
     fields["UID"] = "uniquedesignation";
     fields["HF"] = "higherformation";
     fields["LABELS"] = "uniquedesignation";
     fields["DESCFLDS"] = null;
     fields["DESCFIELD"] = null;
     int count = cache.RetrieveFeatureCache("UNITS").Count;
     cache.AddFeature("UNITS", g, "", "{uniquedesignation}", fields, r);
     Assert.IsTrue(cache.RetrieveFeatureCache("UNITS").Count > count);
       }
 }
Example #13
0
        /// <summary>
        /// Is line intersects with extent.
        /// Implementation of Cohen-Sutherland algorithm.
        /// </summary>
        /// <param name="extent">Extent.</param>
        /// <param name="startPoint">Line start.</param>
        /// <param name="endPoint">Line end.</param>
        /// <returns>Is line intersects with extent.</returns>
        public static bool _IsLineIntersectsWithRect(Envelope extent, Point startPoint, Point endPoint)
        {
            ESRI.ArcGIS.Client.Geometry.MapPoint start = new ESRI.ArcGIS.Client.Geometry.MapPoint(startPoint.X, startPoint.Y);
            ESRI.ArcGIS.Client.Geometry.MapPoint end = new ESRI.ArcGIS.Client.Geometry.MapPoint(endPoint.X, endPoint.Y);

            ESRI.ArcGIS.Client.Geometry.Envelope rect = new ESRI.ArcGIS.Client.Geometry.Envelope(
                extent.left, extent.top, extent.right, extent.bottom);

            int code_a, code_b, code;
            ESRI.ArcGIS.Client.Geometry.MapPoint temp;

            code_a = _GetPointCode(rect, start);
            code_b = _GetPointCode(rect, end);

            while (code_a > 0 || code_b > 0)
            {
                // If both points on one side, than line does not intersects extent.
                if ((code_a & code_b) > 0)
                    return false;

                if (code_a > 0)
                {
                    code = code_a;
                    temp = start;
                }
                else
                {
                    code = code_b;
                    temp = end;
                }

                if ((code & LEFT_CODE) > 0)
                {
                    temp.Y = temp.Y + (start.Y - end.Y) * (rect.XMin - temp.X) / (start.X - end.X);
                    temp.X = rect.XMin;
                }
                else if ((code & RIGHT_CODE) > 0)
                {
                    temp.Y += (start.Y - end.Y) * (rect.XMax - temp.X) / (start.X - end.X);
                    temp.X = rect.XMax;
                }

                if ((code & BOTTOM_CODE) > 0)
                {
                    temp.X += (start.X - end.X) * (rect.YMin - temp.Y) / (start.Y - end.Y);
                    temp.Y = rect.YMin;
                }
                else if ((code & TOP_CODE) > 0)
                {
                    temp.X += (start.X - end.X) * (rect.YMax - temp.Y) / (start.Y - end.Y);
                    temp.Y = rect.YMax;
                }

                if (code == code_a)
                    code_a = _GetPointCode(rect, start);
                else
                    code_b = _GetPointCode(rect, end);
            }

            return true;
        }
Example #14
0
 private void buttonSearchAddress_Click(object sender, RoutedEventArgs e)
 {
     string[] coords = this.textBoxCoord.Text.Trim().Replace(',', ',').Split(',');
     if (coords==null||coords.Length<2)
     {
         MessageBox.Show("Wrong Coords Format,Check it out");
         return;
     }
     double lon = double.Parse(coords[0]);
     double lat = double.Parse(coords[1]);
     if (lat>90.0||lat<-90.0||lon>180.0||lon<-180.0)
     {
         MessageBox.Show("Wrong Coords Format,Check it out");
         return;
     }
     string result= GetLocationAddress(this.textBoxCoord.Text);
     if (this.map1.Layers.Contains(this.map1.Layers["SearchLyr"]))
     {
         this.map1.Layers.Remove(this.map1.Layers["SearchLyr"]);
     }
     ESRI.ArcGIS.Client.Geometry.MapPoint mp = new ESRI.ArcGIS.Client.Geometry.MapPoint()
     {
         X=lon,
         Y=lat,
         SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(4326)
     };
     ESRI.ArcGIS.Client.Projection.WebMercator wm = new ESRI.ArcGIS.Client.Projection.WebMercator();
     mp= wm.FromGeographic(mp) as ESRI.ArcGIS.Client.Geometry.MapPoint;
     ESRI.ArcGIS.Client.Geometry.Polyline pl = CreateGeoForZoom(mp);
     ESRI.ArcGIS.Client.GraphicsLayer gl = CreateSearchLyr(mp);
     this.textBoxResult.Text = this.textBoxCoord.Text + ":" +result;
     this.map1.ZoomTo(pl as ESRI.ArcGIS.Client.Geometry.Geometry);
     this.map1.Layers.Add(gl as ESRI.ArcGIS.Client.Layer);
 }
Example #15
0
        private void CancelScaleRotate()
        {
            bool redraw = _srPoint != null;

              ParcelData parcelData = ParcelGridContainer.DataContext as ParcelData;

              _srPoint = null;     // Stop mouse move from working;
              _oldRotation = parcelData.ScaleValue;
              _srSnapPointId = -1;

              if (redraw)
            CalculateAndAddLineGraphics();  // Redraw so we don't have snap graphic shown
        }
Example #16
0
        public static ESRI.ArcGIS.Client.Geometry.Geometry GetLocationCoord(string address)
        {
            ESRI.ArcGIS.Client.Geometry.MapPoint _mp = null;
            string url=string.Format("http://maps.google.com/maps/api/geocode/json?address={0}ka&sensor=false",address);
            HttpWebRequest hwr = WebRequest.Create(url) as HttpWebRequest;
            hwr.Method = "GET";
            HttpWebResponse httpResponse;
            StringBuilder stringBuffer = new StringBuilder();
            try
            {
                httpResponse = hwr.GetResponse() as HttpWebResponse;
                if (httpResponse.GetResponseStream().CanRead)
                {
                    StreamReader sr = new StreamReader(httpResponse.GetResponseStream(), Encoding.UTF8);
                    string s = sr.ReadToEnd();
                    JObject jObject = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(s);
                    string lon= ((((jObject["results"] as JArray)[0] as JObject)["geometry"] as JObject)["location"] as JObject)["lng"].ToString();
                    string lat = ((((jObject["results"] as JArray)[0] as JObject)["geometry"] as JObject)["location"] as JObject)["lat"].ToString();

                    ESRI.ArcGIS.Client.Geometry.MapPoint mp = new ESRI.ArcGIS.Client.Geometry.MapPoint()
                    {
                        X=double.Parse(lon),
                        Y=double.Parse(lat),
                        SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(4326)
                    };
                    ESRI.ArcGIS.Client.Projection.WebMercator w = new ESRI.ArcGIS.Client.Projection.WebMercator();
                    _mp = w.FromGeographic(mp) as ESRI.ArcGIS.Client.Geometry.MapPoint;
                }
            }
            catch (Exception e)
            {
            }
            return _mp;
        }
Example #17
0
        /// <summary>
        /// Convert from ArcLogistics polyline to ArcGIS polyline.
        /// </summary>
        /// <param name="sourcePolyline">ArcLogistics polyline</param>
        /// <param name="spatialReferenceID">Map spatial reference.</param>
        /// <returns>ArcGIS polyline.</returns>
        internal static ESRI.ArcGIS.Client.Geometry.Geometry ConvertToArcGISPolyline(Polyline sourcePolyline,
            int? spatialReferenceID)
        {
            ESRI.ArcGIS.Client.Geometry.Polyline resultPolyline = new ESRI.ArcGIS.Client.Geometry.Polyline();

            // Project polyline from WGS84 to Web Mercator if spatial reference of map is Web Mercator.
            if (spatialReferenceID != null) // REV: comapre with specific Web Mercator WKID, instead of null.
            {
                sourcePolyline = WebMercatorUtil.ProjectPolylineToWebMercator(sourcePolyline, spatialReferenceID.Value);
            }

            int[] groups = sourcePolyline.Groups;
            for (int groupIndex = 0; groupIndex < groups.Length; ++groupIndex)
            {
                ESRI.ArcLogistics.Geometry.Point[] points = sourcePolyline.GetGroupPoints(groupIndex);

                ESRI.ArcGIS.Client.Geometry.PointCollection pointsCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection();
                for (int index = 0; index < points.Length; index++)
                {
                    ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(
                        points[index].X, points[index].Y);
                    pointsCollection.Add(mapPoint);
                }

                resultPolyline.Paths.Add(pointsCollection);
            }

            return resultPolyline;
        }
Example #18
0
        /// <summary>
        /// Convert from ArcLogistics polygon to ArcGIS polygon.
        /// </summary>
        /// <param name="sourcePolygon">ArcLogistics polygon</param>
        /// <param name="spatialReferenceID">Map spatial reference.</param>
        /// <returns>ArcGIS polygon.</returns>
        internal static ESRI.ArcGIS.Client.Geometry.Polygon ConvertToArcGISPolygon(Polygon sourcePolygon,
            int? spatialReferenceID)
        {
            ESRI.ArcGIS.Client.Geometry.Polygon resultPolygon = new ESRI.ArcGIS.Client.Geometry.Polygon();

            // Project polygon from WGS84 to Web Mercator if spatial reference of map is Web Mercator.
            if (spatialReferenceID != null)
            {
                sourcePolygon = WebMercatorUtil.ProjectPolygonToWebMercator(sourcePolygon, spatialReferenceID.Value);
            }

            int[] groups = sourcePolygon.Groups;
            for (int groupIndex = 0; groupIndex < groups.Length; ++groupIndex)
            {
                ESRI.ArcLogistics.Geometry.Point[] points = sourcePolygon.GetGroupPoints(groupIndex);

                ESRI.ArcGIS.Client.Geometry.PointCollection pointsCollection = new ESRI.ArcGIS.Client.Geometry.PointCollection();
                for (int index = 0; index < points.Length; index++)
                {
                    ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(points[index].X, points[index].Y);
                    pointsCollection.Add(mapPoint);
                }

                resultPolygon.Rings.Add(pointsCollection);
            }

            return resultPolygon;
        }
        /// <summary>
        /// Create barrier geometry.
        /// </summary>
        /// <param name="barrier">Barrier.</param>
        /// <returns>Barrier geometry.</returns>
        private ESRI.ArcGIS.Client.Geometry.Geometry _CreateGeometry(Barrier barrier)
        {
            ESRI.ArcGIS.Client.Geometry.Geometry geometry = null;

            if (barrier.Geometry != null)
            {
                int? spatialReference = null;
                if (ParentLayer != null)
                {
                    spatialReference = ParentLayer.SpatialReferenceID;
                }

                if (barrier.Geometry is ESRI.ArcLogistics.Geometry.Point)
                {
                    ESRI.ArcLogistics.Geometry.Point point = (ESRI.ArcLogistics.Geometry.Point)barrier.Geometry;

                    // Project point from WGS84 to Web Mercator if spatial reference of map is Web Mercator
                    if (ParentLayer != null && ParentLayer.SpatialReferenceID != null)
                    {
                        point = WebMercatorUtil.ProjectPointToWebMercator(point, spatialReference.Value);
                    }

                    geometry = new ESRI.ArcGIS.Client.Geometry.MapPoint(point.X, point.Y);
                }
                else if (barrier.Geometry is ESRI.ArcLogistics.Geometry.Polygon)
                {
                    geometry = MapHelpers.ConvertToArcGISPolygon(
                        barrier.Geometry as ESRI.ArcLogistics.Geometry.Polygon, spatialReference);
                }
                else if (barrier.Geometry is ESRI.ArcLogistics.Geometry.Polyline)
                {
                    geometry = MapHelpers.ConvertToArcGISPolyline(
                        barrier.Geometry as ESRI.ArcLogistics.Geometry.Polyline, spatialReference);
                }
                else
                {
                    System.Diagnostics.Debug.Assert(false);
                }

                _SetSymbol();
            }
            else
            {
                geometry = null;
            }

            return geometry;
        }
        private static ESRI.ArcGIS.Client.Geometry.PointCollection GetPoints(List<ImsPoints> points)
        {
            ESRI.ArcGIS.Client.Geometry.PointCollection pointcollection = new ESRI.ArcGIS.Client.Geometry.PointCollection();
            foreach (var po in points)
            {
                ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = new
                    ESRI.ArcGIS.Client.Geometry.MapPoint(Convert.ToDouble(po.X, System.Globalization.CultureInfo.CurrentCulture),
                    Convert.ToDouble(po.Y, System.Globalization.CultureInfo.CurrentCulture));

                pointcollection.Add(mapPoint);
            }

            return pointcollection;
        }
Example #21
0
        /// <summary>
        /// React on reverse geocode completed.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Reverse geocode completed event args.</param>
        private void _ReverseGeocodeCompleted(object sender, ReverseGeocodeCompletedEventArgs e)
        {
            if (!e.Cancelled && e.Error == null)
            {
                // Geocoded successfully.
                PropertySet set = e.Result;

                // WORKAROUND!!! TODO DT
                // Remove, when geocode service will return good response in case if it
                // hasn't found candidates by reverse geocoding.
                // Right now it can return different responses.
                try
                {
                    // In ArcGIS Server 10 exception is not throws on failed reverse geocoding.
                    // Server returns empty result.
                    if (set.PropertyArray != null)
                    {
                        Address address = _GetAddress(set);

                        // WORKAROUND!!!
                        // When service return point without address - do not show anything.
                        if (string.IsNullOrEmpty(address.AddressLine))
                            return;

                        PointN point = (PointN)e.Result.PropertyArray[0].Value;

                        ESRI.ArcGIS.Client.Geometry.MapPoint location = new ESRI.ArcGIS.Client.Geometry.MapPoint(
                            point.X, point.Y);

                        if (AsyncReverseGeocodeCompleted != null)
                            AsyncReverseGeocodeCompleted(this, new AsyncReverseGeocodedEventArgs(address, location, e.UserState));
                    }
                }
                catch (Exception ex)
                {

                }

            }
        }
Example #22
0
        private void ScaleRotate(Point srcPoint)
        {
            if (!PDE_Tools.IsExpanded)
            return;

              ParcelData parcelData = ParcelGridContainer.DataContext as ParcelData;

              _moveScale = _oldScale = parcelData.ScaleValue;
              _moveRotation = _oldRotation = parcelData.RotationValue;
              _srPoint = ParcelMap.ScreenToMap(srcPoint);
              _srSnapPoint = null;

              double spX = _srPoint.X;
              double spY = _srPoint.Y;

              // Find _startPoint in list of points. If "close" snap to that point.
              // Otherwise user can free form scale or rotate parcel lines.

              double shortestDistance = double.MaxValue;
              Int32 shortestId = -1;
              ESRI.ArcGIS.Client.Geometry.MapPoint foundPoint = null;
              foreach (KeyValuePair<Int32, ESRI.ArcGIS.Client.Geometry.MapPoint> kvp in _calculatedPoints)
              {
            double x = kvp.Value.X;
            double y = kvp.Value.Y;
            double distance = GeometryUtil.LineLength(spX, spY, x, y);
            if ((distance < shortestDistance) && (distance < _xmlConfiguation.SnapTolerance))
            {
              shortestDistance = distance;
              shortestId = kvp.Key;
              foundPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(x, y);
            }
              }

              if (BearingDistanceToPoint(shortestId, out _srBearingToPoint, out _srDistanceToPoint, out _srSnapPoint))
              {
            // BearingDistanceToPoint will fail if shortestId == -1

            _srSnapPointId = shortestId;
            if (RotationButton.IsChecked == true)
            {
              double radialSearch = _srDistanceToPoint * parcelData.ScaleValue;

              // We seem to be getting some numerical precision error when rotating... this does not
              // really matter here; we only need to re-buffer if the changes are > 0.1.

              // if the user re-rotate with the same rotate point, try to avoid re-caching.
              if ((_originPoint == null) || (_lastGeometryCP == null) ||
              (Math.Abs(_lastSearchDistance - radialSearch) > 0.1) || !_lastBufferBasedOnCurve ||
              (_lastGeometryCP.X != _originPoint.X) || (_lastGeometryCP.Y != _originPoint.Y))
              {
            ESRI.ArcGIS.Client.Geometry.MapPoint offsetOriginPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(_originPoint.X - radialSearch, _originPoint.Y);

            // Create a geometry circle from the anchor/rotating point to the snap point.
            // We will create create a cache of all these points within the buffer distance
            // of this circle.

            ESRI.ArcGIS.Client.Geometry.MapPoint endPoint;
            ESRI.ArcGIS.Client.Geometry.Polyline circle = GeometryUtil.ConstructArcSegment(offsetOriginPoint, 0.0, 0.001, radialSearch, false, SweepDirection.Counterclockwise, out endPoint);

            _lastGeometryCP = _originPoint;
            _lastSearchDistance = radialSearch;
            _lastBufferBasedOnCurve = true;

            CacheSnapObjects(circle, radialSearch);
              }
            }
            else if (ScaleButton.IsChecked == true)
            {
              double mapDistanceBuffer = _srDistanceToPoint * 1.5 * parcelData.ScaleValue;

              // if the user re-scales with the same scale point, try to avoid re-caching.
              if ((_originPoint == null) || (_lastGeometryCP == null) ||
              (_lastSearchDistance < mapDistanceBuffer) || _lastBufferBasedOnCurve ||
              (_lastGeometryCP.X != _originPoint.X) || (_lastGeometryCP.Y != _originPoint.Y))
              {
            // Create a line from the anchor/rotating point to the snap point * 1.5 of the distance.
            // We will create create a cache of all these points within the buffer distance
            // of this line.

            ESRI.ArcGIS.Client.Geometry.MapPoint endPoint;
            ESRI.ArcGIS.Client.Geometry.Polyline snapLine = GeometryUtil.Line(_originPoint,
                                                                 _srBearingToPoint - parcelData.RotationValue,
                                                                 mapDistanceBuffer,
                                                                 out endPoint);
            if (snapLine != null)
            {
              _lastGeometryCP = _originPoint;
              _lastSearchDistance = mapDistanceBuffer;
              _lastBufferBasedOnCurve = false;

              CacheSnapObjects(snapLine, mapDistanceBuffer);
            }
              }
            }
            // else no snapping.

            CalculateAndAddLineGraphics();      // Redraw so we have snap graphic shown
              }
              else                      // BearingDistanceToPoint returns false if id = -1
            _srSnapPointId = -1;
        }
 public void TestCacheUpdateFeatureWithDesc()
 {
     using (ShimsContext.Create())
       {
     client.Geometry.MapPoint p = new client.Geometry.MapPoint(0.0, 0.0);
     clientfake.ShimGraphic g = new clientfake.ShimGraphic();
     clientfake.ShimUniqueValueRenderer r = new clientfake.ShimUniqueValueRenderer();
     Dictionary<String, Object> attributes = new Dictionary<String, Object>();
     attributes["uniquedesignation"] = "Wolfpack 1 C";
     attributes["owningunit"] = "2nd Stryker Brigade";
     attributes["type"] = "M1128";
     g.AttributesGet = () => { return attributes; };
     g.GeometryGet = () => { return p; };
     Dictionary<String, String> fields = new Dictionary<String, String>();
     fields["UID"] = "uniquedesignation";
     fields["HF"] = "owningunit";
     fields["LABELS"] = "uniquedesignation";
     fields["DESCFLDS"] = "type";
     fields["DESCFIELD"] = "type";
     int count = cache.RetrieveFeatureCache("EQUIPMENT").Count;
     cache.AddFeature("EQUIPMENT", g, "Type: {type}", "{uniquedesignation} owned by {owningunit}", fields, r);
     cache.UpdateFeature("EQUIPMENT", "Wolfpack 1 C", "{type}", "{uniquedesignation}", g, fields);
     Dictionary<String, Dictionary<String, Object>> fcache = cache.RetrieveFeatureCache("EQUIPMENT");
     Dictionary<String, Object> f = fcache["Wolfpack 1 C"];
     String desc = f["DESCRIPTION"].ToString();
     Assert.AreEqual(desc, "M1128");
       }
 }
Example #24
0
 public QueryItem(Map ParcelMap, ref Configuration config, ESRI.ArcGIS.Client.Geometry.MapPoint clickPoint, int index)
 {
     // TODO: Complete member initialization
     _parcelMap = ParcelMap;
     _config = config;
     _clickPoint = clickPoint;
     _index = index;
 }
        /// <summary>
        /// Create zone geometry.
        /// </summary>
        /// <param name="zone">Zone for creating geometry.</param>
        /// <returns>Created geometry.</returns>
        private ESRI.ArcGIS.Client.Geometry.Geometry _CreateGeometry(Zone zone)
        {
            ESRI.ArcGIS.Client.Geometry.Geometry geometry = null;

            if (zone.Geometry != null)
            {
                if (zone.Geometry is ESRI.ArcLogistics.Geometry.Point?)
                {
                    ESRI.ArcLogistics.Geometry.Point? point = zone.Geometry as ESRI.ArcLogistics.Geometry.Point?;
                    geometry = new ESRI.ArcGIS.Client.Geometry.MapPoint(point.Value.X, point.Value.Y);
                }
                else
                {
                    int? spatialReference = null;
                    if (ParentLayer != null)
                    {
                        spatialReference = ParentLayer.SpatialReferenceID;
                    }

                    geometry = MapHelpers.ConvertToArcGISPolygon(
                        zone.Geometry as ESRI.ArcLogistics.Geometry.Polygon, spatialReference);
                }
            }
            else
            {
                geometry = null;
            }

            return geometry;
        }
        void Map_MouseClick(object sender, client.Map.MouseEventArgs e)
        {
            if (sizeComboBox.Text=="Select Size")
                MessageBox.Show("Please select a size of animal before adding to the map.");
            if (btnAddSighting.IsEnabled == false && sizeComboBox.Text!="Select Size")
            {
                ESRI.ArcGIS.Client.Graphic graphicFeature = new client.Graphic();
                ESRI.ArcGIS.Client.FeatureLayer featureLayer = new client.FeatureLayer();
                featureLayer = this.globalFeatureLayer;
                ESRI.ArcGIS.Client.Geometry.MapPoint point = new client.Geometry.MapPoint();
                point = e.MapPoint;
                graphicFeature.Geometry=point;
                graphicFeature.Attributes.Add("size", sizeComboBox.Text.ToString());
                featureLayer.Graphics.Add(graphicFeature);
                featureLayer.SaveEdits();
                MessageBox.Show("Successfully added sighting!");
                ///Thread.Sleep(10000);
                //MessageBox.Show("finished");
                //featureLayer.Update();
                //featureLayer.Refresh();
                //globalMapWidget.Map.UpdateLayout();

            }
        }