Esempio n. 1
0
        public override void OnMapMouseMove(object sender, MouseEventArgs e)
        {
            if (!_start) return;
            PointLatLng currentPoint = this._gMapControl.FromLocalToLatLng(e.X, e.Y);

            if (flag)
            {
                _points.RemoveAt(_points.Count - 1);
            }
            if (!flag) flag = true;
            _points.Add(currentPoint);
            if (_route == null)
            {
                _route = new GMapRouteExtension("mearsureLine", _points, System.Drawing.Color.FromArgb(100, 255, 0, 0), 2.5F,
                    true);
            }
            else
            {
                ((GMapRouteExtension)_route).GPoints = _points;
            }

            if (_gMapOverlay.Routes.Count > 0)
            {
                _gMapOverlay.Routes[0] = _route;
            }
            else
            {
                _gMapOverlay.Routes.Add(_route);
            }
        }
Esempio n. 2
0
        public override void OnMapMouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (!_start) return;
            PointLatLng currentPoint = this._gMapControl.FromLocalToLatLng(e.X, e.Y);
            double mercatorX, mercatorY;
            Helper.LonLat2Mercator(currentPoint.Lng, currentPoint.Lat, out mercatorX, out mercatorY);
            Point2D point2D = new Point2D(mercatorX, mercatorY);
            _point2Ds.Add(point2D);
            Map map = new Map(_mapUrl);

            QueryParameterSet queryParameterSet = new QueryParameterSet();
            queryParameterSet.ReturnContent = true;
            queryParameterSet.QueryOption = QuerySetting.QueryOption;
            queryParameterSet.ExpectCount = QuerySetting.ExceptionCount;
            queryParameterSet.QueryParams = new QueryParameter[QuerySetting.LayerNames.Count];
            for (int i = 0; i < QuerySetting.LayerNames.Count; i++)
            {
                queryParameterSet.QueryParams[i] = new QueryParameter();
                queryParameterSet.QueryParams[i].Name = QuerySetting.LayerNames[i];
            }

            Geometry geo = new Geometry();
            geo.Parts = new int[1] { _point2Ds.Count };
            geo.Points = _point2Ds.ToArray();
            geo.Type = GeometryType.REGION;
            QueryResult queryResult = null;
            try
            {
                queryResult = map.QueryByGeometry(_mapName, geo, SpatialQueryMode.INTERSECT, queryParameterSet);
            }
            catch (ServiceException serviceException)
            {
                MessageBox.Show(serviceException.Message);
            }

            //高亮显示查询结果。
            if (queryResult != null && queryResult.Recordsets != null && queryResult.Recordsets.Length > 0)
            {
                for (int i = 0; i < queryResult.Recordsets.Length; i++)
                {
                    if (queryResult.Recordsets[i] != null && queryResult.Recordsets[i].Features != null &&
                        queryResult.Recordsets[i].Features.Length > 0)
                    {
                        for (int j = 0; j < queryResult.Recordsets[i].Features.Length; j++)
                        {
                            if (queryResult.Recordsets[i].Features[j].Geometry != null && (
                                queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.POINT
                            || queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.TEXT))
                            {
                                double lat, lng;
                                Helper.Mercator2LonLat(queryResult.Recordsets[i].Features[j].Geometry.Points[0].X, queryResult.Recordsets[i].Features[j].Geometry.Points[0].Y, out lng, out lat);
                                PointLatLng pointLatLng = new PointLatLng(lat, lng);
                                GMapMarkerGoogleRed marker = new GMapMarkerGoogleRed(pointLatLng);
                                _highLightOverlay.Markers.Add(marker);
                            }
                            else if (queryResult.Recordsets[i].Features[j].Geometry != null &&
                                (queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.REGION
                            || queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.RECTANGLE))
                            {
                                if (queryResult.Recordsets[i].Features[j].Geometry.Parts != null)
                                //queryResult.Recordsets[i].Features[j].Geometry.Parts.Length > 1)
                                {
                                    int startIndex = 0;
                                    for (int k = 0; k < queryResult.Recordsets[i].Features[j].Geometry.Parts.Length; k++)
                                    {
                                        List<PointLatLng> regionClient = new List<PointLatLng>();
                                        for (int n = startIndex; n < queryResult.Recordsets[i].Features[j].Geometry.Parts[k]; n++)
                                        {
                                            double lat, lng;
                                            Helper.Mercator2LonLat(queryResult.Recordsets[i].Features[j].Geometry.Points[n].X, queryResult.Recordsets[i].Features[j].Geometry.Points[n].Y, out lng, out lat);
                                            regionClient.Add(new PointLatLng(lat, lng));
                                        }
                                        GMapPolygonExtension hight = new GMapPolygonExtension("", regionClient, 2.0F,
               System.Drawing.Color.FromArgb(125, 255, 0, 0), System.Drawing.Color.FromArgb(50, 255, 0, 0));
                                        _highLightOverlay.Polygons.Add(hight);
                                        startIndex += queryResult.Recordsets[i].Features[j].Geometry.Parts[k];

                                    }
                                }
                            }
                            else if (queryResult.Recordsets[i].Features[j].Geometry != null &&
                                (queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.LINE))
                            {
                                int startIndex = 0;
                                for (int k = 0; k < queryResult.Recordsets[i].Features[j].Geometry.Parts.Length; k++)
                                {
                                    List<PointLatLng> regionClient = new List<PointLatLng>();
                                    for (int n = startIndex; n < startIndex + queryResult.Recordsets[i].Features[j].Geometry.Parts[k]; n++)
                                    {
                                        double lat, lng;
                                        Helper.Mercator2LonLat(queryResult.Recordsets[i].Features[j].Geometry.Points[n].X, queryResult.Recordsets[i].Features[j].Geometry.Points[n].Y, out lng, out lat);
                                        regionClient.Add(new PointLatLng(lat, lng));
                                    }
                                    GMapRouteExtension hight = new GMapRouteExtension("", regionClient,
               System.Drawing.Color.FromArgb(125, 255, 0, 0), 5.0F, false);
                                    _highLightOverlay.Routes.Add(hight);
                                    startIndex += queryResult.Recordsets[i].Features[j].Geometry.Parts[k];

                                }
                            }
                        }
                    }
                }
            }

            _gMapOverlay.Polygons.Clear();
            _points.Clear();
            _point2Ds.Clear();
            flag = false;
            _start = false;
            base.OnMapMouseDoubleClick(sender, e);
        }
Esempio n. 3
0
        public override void OnMapMouseUp(object sender, MouseEventArgs e)
        {
            if (!_start) return;
            this._gMapOverlay.Polygons.Clear();

            PointLatLng currentPoint = this._gMapControl.FromLocalToLatLng(e.X, e.Y);
            double mecatorStartX = 0, mecatorStartY = 0;
            double mecatorEndX = 0, mecatorEndY = 0;
            Helper.LonLat2Mercator(_startPoint.Lng, _startPoint.Lat, out mecatorStartX, out  mecatorStartY);
            Helper.LonLat2Mercator(currentPoint.Lng, currentPoint.Lat, out mecatorEndX, out  mecatorEndY);
            double left = mecatorStartX > mecatorEndX ? mecatorEndX : mecatorStartX;
            double bottom = mecatorStartY > mecatorEndY ? mecatorEndY : mecatorStartY;
            double right = mecatorStartX > mecatorEndX ? mecatorStartX : mecatorEndX;
            double top = mecatorStartY > mecatorEndY ? mecatorStartY : mecatorEndY;
            Rectangle2D rect = new Rectangle2D(left, bottom, right, top);
            Geometry geo = new Geometry(rect);
            geo.Type = GeometryType.REGION;

            //MessageBox.Show(string.Format("left:{0};bottom:{1};right:{2};top{3}", left, bottom, right, top));
            //List<PointLatLng> test = new List<PointLatLng>();
            //double lat1, lng1;
            //Helper.Mercator2LonLat(rect.LeftBottom.X, rect.LeftBottom.Y, out lng1, out lat1);
            //test.Add(new PointLatLng(lat1, lng1));
            //Helper.Mercator2LonLat(rect.LeftBottom.X, rect.RightTop.Y, out lng1, out lat1);
            //test.Add(new PointLatLng(lat1, lng1));
            //Helper.Mercator2LonLat(rect.RightTop.X, rect.RightTop.Y, out lng1, out lat1);
            //test.Add(new PointLatLng(lat1, lng1));
            //Helper.Mercator2LonLat(rect.RightTop.X, rect.LeftBottom.Y, out lng1, out lat1);
            //test.Add(new PointLatLng(lat1, lng1));
            //GMapPolygonExtension testgp = new GMapPolygonExtension("", test, 2.0F,
            //    System.Drawing.Color.FromArgb(100, 0, 0, 255), System.Drawing.Color.FromArgb(255, 255, 0, 0));
            //this._gMapOverlay.Polygons.Add(testgp);

            QueryParameterSet queryParameterSet = new QueryParameterSet();

            queryParameterSet.ReturnContent = true;
            queryParameterSet.QueryOption = QuerySetting.QueryOption;
            queryParameterSet.ExpectCount = QuerySetting.ExceptionCount;
            queryParameterSet.QueryParams = new QueryParameter[QuerySetting.LayerNames.Count];
            for (int i = 0; i < QuerySetting.LayerNames.Count; i++)
            {
                queryParameterSet.QueryParams[i] = new QueryParameter();

                queryParameterSet.QueryParams[i].Name = QuerySetting.LayerNames[i];
            }

            QueryResult queryResult = null;
            try
            {
                queryResult = _map.QueryByGeometry(_mapName, geo, SpatialQueryMode.INTERSECT, queryParameterSet);
            }
            catch (ServiceException serviceException)
            {
                MessageBox.Show(serviceException.Message);
            }

            if (queryResult != null && queryResult.Recordsets != null && queryResult.Recordsets.Length > 0)
            {
                for (int i = 0; i < queryResult.Recordsets.Length; i++)
                {
                    if (queryResult.Recordsets[i] != null && queryResult.Recordsets[i].Features != null &&
                        queryResult.Recordsets[i].Features.Length > 0)
                    {
                        for (int j = 0; j < queryResult.Recordsets[i].Features.Length; j++)
                        {
                            if (queryResult.Recordsets[i].Features[j].Geometry != null && (
                                queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.POINT
                            || queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.TEXT))
                            {
                                double lat, lng;
                                Helper.Mercator2LonLat(queryResult.Recordsets[i].Features[j].Geometry.Points[0].X, queryResult.Recordsets[i].Features[j].Geometry.Points[0].Y, out lng, out lat);
                                PointLatLng pointLatLng = new PointLatLng(lat, lng);
                                GMapMarkerGoogleRed marker = new GMapMarkerGoogleRed(pointLatLng);
                                _highLightOverlay.Markers.Add(marker);
                            }
                            else if (queryResult.Recordsets[i].Features[j].Geometry != null &&
                                (queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.REGION
                            || queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.RECTANGLE))
                            {
                                if (queryResult.Recordsets[i].Features[j].Geometry.Parts != null)
                                //queryResult.Recordsets[i].Features[j].Geometry.Parts.Length > 1)
                                {
                                    int startIndex = 0;
                                    for (int k = 0; k < queryResult.Recordsets[i].Features[j].Geometry.Parts.Length; k++)
                                    {
                                        List<PointLatLng> regionClient = new List<PointLatLng>();
                                        for (int n = startIndex; n < startIndex + queryResult.Recordsets[i].Features[j].Geometry.Parts[k]; n++)
                                        {
                                            double lat, lng;
                                            Helper.Mercator2LonLat(queryResult.Recordsets[i].Features[j].Geometry.Points[n].X, queryResult.Recordsets[i].Features[j].Geometry.Points[n].Y, out lng, out lat);
                                            regionClient.Add(new PointLatLng(lat, lng));
                                        }
                                        GMapPolygonExtension hight = new GMapPolygonExtension("", regionClient, 2.0F,
               System.Drawing.Color.FromArgb(125, 255, 0, 0), System.Drawing.Color.FromArgb(50, 255, 0, 0));
                                        _highLightOverlay.Polygons.Add(hight);
                                        startIndex += queryResult.Recordsets[i].Features[j].Geometry.Parts[k];

                                    }
                                }
                            }
                            else if (queryResult.Recordsets[i].Features[j].Geometry != null &&
                                (queryResult.Recordsets[i].Features[j].Geometry.Type == GeometryType.LINE))
                            {
                                int startIndex = 0;
                                for (int k = 0; k < queryResult.Recordsets[i].Features[j].Geometry.Parts.Length; k++)
                                {
                                    List<PointLatLng> regionClient = new List<PointLatLng>();
                                    for (int n = startIndex; n < queryResult.Recordsets[i].Features[j].Geometry.Parts[k]; n++)
                                    {
                                        double lat, lng;
                                        Helper.Mercator2LonLat(queryResult.Recordsets[i].Features[j].Geometry.Points[n].X, queryResult.Recordsets[i].Features[j].Geometry.Points[n].Y, out lng, out lat);
                                        regionClient.Add(new PointLatLng(lat, lng));
                                    }
                                    GMapRouteExtension hight = new GMapRouteExtension("", regionClient,
               System.Drawing.Color.FromArgb(125, 255, 0, 0), 5.0F, false);
                                    _highLightOverlay.Routes.Add(hight);
                                    startIndex += queryResult.Recordsets[i].Features[j].Geometry.Parts[k];

                                }
                            }
                        }
                    }
                }
            }

            _start = false;
            base.OnMapMouseUp(sender, e);
        }