Ejemplo n.º 1
0
        private void zoom2selBtn_Click(object sender, EventArgs e)
        {
            if (mouseCmd == null || csvDataGrid.SelectedRows.Count == 0)
            {
                return;
            }

            int maxCount = 30;
            int i        = 0;

            try
            {
                clearGraphics();

                IPointCollection points = new MultipointClass();

                foreach (DataGridViewRow row in csvDataGrid.SelectedRows)
                {
                    if (row.Cells["validAdres"].Value == null || row.Cells["validAdres"].Value.ToString() == "")
                    {
                        continue;
                    }

                    if (i > maxCount)
                    {
                        break;
                    }
                    i++;

                    string adres = row.Cells["validAdres"].Value.ToString();

                    string[] xy = adres.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);

                    double x; double y;
                    string adresType = "Manueel";
                    if (xy.Count() == 2)
                    {
                        bool xBool = Double.TryParse(xy[0], out x);
                        bool yBool = Double.TryParse(xy[1], out y);

                        if (!xBool || !yBool)
                        {
                            List <datacontract.locationResult> locs = loc.getAdresLocation(adres, 1);
                            if (locs.Count == 0)
                            {
                                continue;
                            }
                            x         = locs[0].Location.X_Lambert72;
                            y         = locs[0].Location.Y_Lambert72;
                            adresType = locs[0].LocationType;
                        }
                    }
                    else
                    {
                        List <datacontract.locationResult> locs = loc.getAdresLocation(adres, 1);
                        if (locs.Count == 0)
                        {
                            continue;
                        }
                        x         = locs[0].Location.X_Lambert72;
                        y         = locs[0].Location.Y_Lambert72;
                        adresType = locs[0].LocationType;
                    }

                    IPoint pt = new PointClass()
                    {
                        X = x, Y = y, SpatialReference = lam72
                    };
                    IPoint prjPt = geopuntHelper.Transform(pt, map.SpatialReference) as IPoint;
                    points.AddPoint(prjPt);

                    IRgbColor rgb = new RgbColorClass()
                    {
                        Red = 0, Blue = 255, Green = 255
                    };
                    IRgbColor black = new RgbColorClass()
                    {
                        Red = 0, Green = 0, Blue = 0
                    };
                    IElement grp = geopuntHelper.AddGraphicToMap(map, (IGeometry)prjPt, rgb, black, 5, true);
                    graphics.Add(grp);
                }

                if (points.PointCount == 0)
                {
                    return;
                }
                else if (points.PointCount == 1)
                {
                    IPoint xy = points.get_Point(0);
                    geopuntHelper.ZoomByRatioAndRecenter(view, 1, xy.X, xy.Y);
                    map.MapScale = 1000;
                    view.Refresh();
                }
                else
                {
                    IEnvelope extent = ((IGeometry)points).Envelope;
                    view.Extent = extent;
                    view.Refresh();
                }
            }
            catch (WebException wex)
            {
                if (wex.Status == WebExceptionStatus.Timeout)
                {
                    MessageBox.Show("De connectie werd afgebroken." +
                                    " Het duurde te lang voor de server een resultaat terug gaf.\n" +
                                    "U kunt via de instellingen de 'timout'-tijd optrekken.", wex.Message);
                }
                else if (wex.Response != null)
                {
                    string resp = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd();
                    MessageBox.Show(resp, wex.Message);
                }
                else
                {
                    MessageBox.Show(wex.Message, "Error");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " : " + ex.StackTrace);
            }
        }
Ejemplo n.º 2
0
        private bool zoomToQuery(string query, int count, Double zoom)
        {
            List <datacontract.locationResult> loc = adresLocation.getAdresLocation(query, count);

            if (loc.Count > 0)
            {
                IPoint leftXY = new ESRI.ArcGIS.Geometry.Point()
                {
                    X = loc[0].BoundingBox.LowerLeft.Lon_WGS84,
                    Y = loc[0].BoundingBox.LowerLeft.Lat_WGS84,
                    SpatialReference = wgs
                };
                IPoint toleftXY = geopuntHelper.Transform(leftXY as IGeometry, map.SpatialReference) as IPoint;
                IPoint rightXY  = new ESRI.ArcGIS.Geometry.Point()
                {
                    X = loc[0].BoundingBox.UpperRight.Lon_WGS84,
                    Y = loc[0].BoundingBox.UpperRight.Lat_WGS84,
                    SpatialReference = wgs
                };
                IPoint    torightXY = geopuntHelper.Transform(rightXY as IGeometry, map.SpatialReference) as IPoint;
                IEnvelope bbox      = geopuntHelper.makeExtend(toleftXY.X, toleftXY.Y, torightXY.X, torightXY.Y,
                                                               map.SpatialReference);

                IPoint XY = new ESRI.ArcGIS.Geometry.Point()
                {
                    X = loc[0].Location.Lon_WGS84,
                    Y = loc[0].Location.Lat_WGS84,
                    SpatialReference = wgs
                };
                IPoint toXY = geopuntHelper.Transform(XY as IGeometry, map.SpatialReference) as IPoint;

                //create a graphic
                IRgbColor rgb = new RgbColorClass()
                {
                    Red = 255, Blue = 255, Green = 0
                };
                if (graphic != null)
                {
                    IGraphicsContainer grpCont = (IGraphicsContainer)map;
                    grpCont.DeleteElement(graphic);
                    graphic = null;
                }
                graphic = geopuntHelper.AddGraphicToMap(map, toXY, rgb,
                                                        new RgbColorClass()
                {
                    Red = 0, Blue = 0, Green = 0
                }, 8, true);

                infoLabel.Text = geopuntHelper.adresTypeStringTranslate(loc[0].LocationType);

                map.MapScale = 1000;
                view.Extent  = bbox;
                geopuntHelper.ZoomByRatioAndRecenter(view, 1, toXY.X, toXY.Y);

                view.Refresh();
                return(true);
            }
            else
            {
                return(false);
            }
        }