コード例 #1
0
        public object Clone()
        {
            AreaInfo ainfo = new AreaInfo(base.Mission, base.ID, base.Name, _Property);

            ainfo._Points  = new Dictionary <int, PointLatLng>(_Points);
            ainfo._Polygon = _Polygon;
            return(ainfo);
        }
コード例 #2
0
 public int FindPolygon(GMapPolygon polygon)
 {
     foreach (int ID in Polygons.Keys)
     {
         AreaInfo ainfo = Polygons[ID];
         if (polygon == ainfo.Polygon)
         {
             return(ID);
         }
     }
     return(-1);
 }
コード例 #3
0
        public void AddPolygon(List <PointLatLng> Points, string Name, int Property)
        {
            AreaInfo ainfo;
            int      mission_id, polygon_id;

            if (DataSettings.UseDatabase)
            {
                mission_id = Mission.GetMissionId();
                MySqlConnection conn = DataSettings.GetConnection();
                using (MySqlCommand cmd = new MySqlCommand(null, conn))
                {
                    cmd.CommandText = "INSERT INTO polygon_info (area_name, area_property, mission_id) " +
                                      "VALUES (@name, @property, @mission_id); SELECT LAST_INSERT_ID();";
                    cmd.Parameters.Clear();
                    cmd.Parameters.AddWithValue("name", Name);
                    cmd.Parameters.AddWithValue("property", Property);
                    cmd.Parameters.AddWithValue("mission_id", mission_id);
                    polygon_id = Convert.ToInt32(cmd.ExecuteScalar());
                    Dictionary <int, PointLatLng> points = new Dictionary <int, PointLatLng>();
                    foreach (PointLatLng point in Points)
                    {
                        cmd.CommandText = "INSERT INTO polygon_point (point_lat, point_lng, area_id) " +
                                          "VALUES (@lat, @lng, @area_id); SELECT LAST_INSERT_ID();";
                        cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue("lat", point.Lat);
                        cmd.Parameters.AddWithValue("lng", point.Lng);
                        cmd.Parameters.AddWithValue("area_id", polygon_id);
                        int point_id = Convert.ToInt32(cmd.ExecuteScalar());
                        points.Add(point_id, point);
                    }
                    ainfo = new AreaInfo(mission_id, polygon_id, Name, Property);
                    ainfo.SetPoints(points);
                    ainfo.Polygon = CreatePolygon(Name, Points, Property);
                    Polygons.Add(polygon_id, ainfo);
                }
            }
            else
            {
                mission_id = 0;
                polygon_id = simID++;
                ainfo      = new AreaInfo(mission_id, polygon_id, Name, Property);
                Dictionary <int, PointLatLng> points = new Dictionary <int, PointLatLng>();
                for (int i = 0; i < Points.Count; i++)
                {
                    points.Add(i, Points[i]);
                }
                ainfo.SetPoints(points);
                ainfo.Polygon = CreatePolygon(Name, Points, Property);
                Polygons.Add(polygon_id, ainfo);
            }
        }
コード例 #4
0
 public void EditPolygonPoints(int ID, List <PointLatLng> Points)
 {
     if (Polygons.ContainsKey(ID))
     {
         List <PointLatLng> np = new List <PointLatLng>(Points);
         AdjustPoints(np);
         AreaInfo ainfo = Polygons[ID];
         if (DataSettings.UseDatabase)
         {
             MySqlConnection conn = DataSettings.GetConnection();
             using (MySqlCommand cmd = new MySqlCommand(null, conn))
             {
                 Dictionary <int, PointLatLng> points = new Dictionary <int, PointLatLng>();
                 Dictionary <int, PointLatLng> op     = ainfo.Points;
                 foreach (int point_id in op.Keys)
                 {
                     cmd.CommandText = "DELETE FROM polygon_point WHERE point_id = @id";
                     cmd.Parameters.Clear();
                     cmd.Parameters.AddWithValue("id", point_id);
                     cmd.ExecuteNonQuery();
                 }
                 foreach (PointLatLng point in Points)
                 {
                     cmd.CommandText = "INSERT INTO polygon_point (point_lat, point_lng, area_id) " +
                                       "VALUES (@lat, @lng, @area_id); SELECT LAST_INSERT_ID();";
                     cmd.Parameters.Clear();
                     cmd.Parameters.AddWithValue("lat", point.Lat);
                     cmd.Parameters.AddWithValue("lng", point.Lng);
                     cmd.Parameters.AddWithValue("area_id", ID);
                     int point_id = Convert.ToInt32(cmd.ExecuteScalar());
                     points.Add(point_id, point);
                 }
                 ainfo.SetPoints(points);
                 ainfo.Polygon = CreatePolygon(ainfo.Name, Points, ainfo.Property);
             }
         }
         else
         {
             Dictionary <int, PointLatLng> points = new Dictionary <int, PointLatLng>();
             for (int i = 0; i < Points.Count; i++)
             {
                 points.Add(i, Points[i]);
             }
             ainfo.SetPoints(points);
             ainfo.Polygon = CreatePolygon(ainfo.Name, Points, ainfo.Property);
         }
     }
 }
コード例 #5
0
        public void LoadJson(string json)
        {
            Clear();
            MPWrapper wrapper = JsonConvert.DeserializeObject <MPWrapper>(json);

            this.Markers  = new Dictionary <int, SymbolInfo>(wrapper.Markers);
            this.Polygons = new Dictionary <int, AreaInfo>(wrapper.Polygons);
            foreach (int id in Markers.Keys)
            {
                SymbolInfo sinfo = Markers[id];
                sinfo.Marker = MarkSymbol(sinfo.ImgID, sinfo.Name, sinfo.Point, sinfo.ID);
            }
            foreach (int id in Polygons.Keys)
            {
                AreaInfo ainfo = Polygons[id];
                ainfo.Polygon = CreatePolygon(ainfo.Name, ainfo.GetPoints(), ainfo.Property);
            }
        }
コード例 #6
0
        public void RemovePolygon(int ID)
        {
            if (Polygons.ContainsKey(ID))
            {
                AreaInfo    ainfo   = Polygons[ID];
                GMapOverlay overlay = Main.GetOverlay("polygons");
                overlay.Markers.Remove((GmapMarkerWithLabel)ainfo.Polygon.Tag);
                overlay.Polygons.Remove(ainfo.Polygon);

                Polygons.Remove(ID);
                if (DataSettings.UseDatabase)
                {
                    MySqlConnection conn = DataSettings.GetConnection();
                    using (MySqlCommand cmd = new MySqlCommand(null, conn))
                    {
                        cmd.CommandText = "DELETE FROM polygon_info WHERE area_id = @id";
                        cmd.Parameters.Clear();
                        cmd.Parameters.AddWithValue("id", ID);
                        cmd.ExecuteNonQuery();
                    }
                }
            }
        }