Exemplo n.º 1
0
        public double distance(Location latlong,Location latlong2)
        {
            double lat1 = latlong.Latitude;
              double lon1 = latlong.Longitude;
              double lat2 = latlong2.Latitude;
              double lon2 = latlong2.Longitude;
              double earthRadius = 6371; //appxoximate radius in miles

              double factor = Math.PI/180;
              double dLat = (lat2-lat1)*factor;
              double dLon = (lon2-lon1)*factor;
              double a = Math.Sin(dLat/2) * Math.Sin(dLat/2) + Math.Cos(lat1*factor) * Math.Cos(lat2*factor) * Math.Sin(dLon/2) * Math.Sin(dLon/2);
              double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1-a));
              double d = earthRadius * c;
              return d;
        }
Exemplo n.º 2
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            status.Text = string.Empty;

            this.Show();
            System.Windows.Forms.Application.DoEvents();

            string mapPointFile = string.Empty;

            openFileDialog1.Filter           = "Mappoint Files (*.ptm)|*.ptm";
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                mappointAreas = new AreaCollection();

                MapPoint.Application mApp = new MapPoint.Application();
                mApp.Visible     = false;
                mApp.UserControl = false;

                MapPoint.Map map = mApp.OpenMap(openFileDialog1.FileName, false);

                int i = 0;
                foreach (MapPoint.Shape shape in map.Shapes)
                {
                    //try
                    //{
                    if (shape.Type == GeoShapeType.geoFreeform)
                    {
                        i++;

                        status.Text = "Importing Shape " + i.ToString();
                        System.Windows.Forms.Application.DoEvents();

                        AreaCoordinateCollection coordinates = new AreaCoordinateCollection();

                        System.Object[] objects = (System.Object[])shape.Vertices;

                        foreach (System.Object obj in objects)
                        {
                            if (obj is MapPoint.Location)
                            {
                                MapPoint.Location location = (MapPoint.Location)obj;

                                AreaCoordinate coordinate = new AreaCoordinate();
                                coordinate.Latitude  = location.Latitude;
                                coordinate.Longitude = location.Longitude;
                                coordinates.Add(coordinate);

                                System.Windows.Forms.Application.DoEvents();
                            }
                        }

                        Area area = new Area(coordinates.MinLatitude(), coordinates.MinLongitude());
                        if (area == null || area.AreaID == -1)
                        {
                            area.AreaID         = int.MinValue;
                            area.OrganizationID = OrganizationId;
                            area.Name           = "Area: " + i.ToString();
                            area.MapHeight      = 400;
                            area.MapWidth       = 600;
                        }

                        area.Coordinates = coordinates;

                        for (int j = 0; j < area.Coordinates.Count; j++)
                        {
                            AreaCoordinate aCoordinate = area.Coordinates[j];
                            aCoordinate.AreaID = area.AreaID;
                            aCoordinate.Order  = j;
                        }

                        if (area.Blob != null)
                        {
                            area.Blob.DateModified = DateTime.Now;
                        }

                        mappointAreas.Add(area);
                    }
                    //}
                    //catch (System.Exception ex)
                    //{
                    //    MessageBox.Show("Area " + i.ToString() + ": " + ex.Message, "Error Reading Area");
                    //}
                }

                LoadExistingAreas();
                LoadMappointAreas(0);
            }
            else
            {
                btnLink.Enabled      = false;
                btnCreateNew.Enabled = false;
                btnRemove.Enabled    = false;
                btnImport.Enabled    = false;
            }

            status.Text    = string.Empty;
            Cursor.Current = Cursors.Default;
        }
 public MapViewRepresentations GetBestMapView(Location[] locations, string dataSourceName)
 {
     object[] results = this.Invoke("GetBestMapView", new object[] {
                 locations,
                 dataSourceName});
     return ((MapViewRepresentations)(results[0]));
 }
 /// <remarks/>
 public System.IAsyncResult BeginGetBestMapView(Location[] locations, string dataSourceName, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("GetBestMapView", new object[] {
                 locations,
                 dataSourceName}, callback, asyncState);
 }
Exemplo n.º 5
0
 public void drawCircle(Location origin,double radius, MapPoint.Map map)
 {
     map.Shapes.AddShape(GeoAutoShapeType.geoShapeOval,origin,radius,radius);
 }