示例#1
0
        public static AVL.Controls.Map.BoundsObject BoundsStringtoPoints(string bounds)
        {
            string _sw = bounds.Split(new string[] { "), " }, StringSplitOptions.RemoveEmptyEntries)[0];
            string _ne = bounds.Split(new string[] { "), " }, StringSplitOptions.RemoveEmptyEntries)[1];
            float  lat, lng;

            lat = float.Parse(_sw.Split(new string[] { "((", ",", "\"" }, StringSplitOptions.RemoveEmptyEntries)[0].Trim(), new System.Globalization.CultureInfo("en-US"));
            lng = float.Parse(_sw.Split(new string[] { "((", ",", "\"" }, StringSplitOptions.RemoveEmptyEntries)[1].Trim(), new System.Globalization.CultureInfo("en-US"));
            AVL.Controls.Map.Point SW = new AVL.Controls.Map.Point()
            {
                Latitude  = lat,
                Longitude = lng
            };
            lat = float.Parse(_ne.Split(new string[] { "(", ",", "\"" }, StringSplitOptions.RemoveEmptyEntries)[0].Trim(), new System.Globalization.CultureInfo("en-US"));
            lng = float.Parse(_ne.Split(new string[] { "))", ",", "\"" }, StringSplitOptions.RemoveEmptyEntries)[1].Trim(), new System.Globalization.CultureInfo("en-US"));
            AVL.Controls.Map.Point NE = new AVL.Controls.Map.Point()
            {
                Latitude  = lat,
                Longitude = lng
            };
            AVL.Controls.Map.BoundsObject boundsObj = new BoundsObject();
            boundsObj.NorthEast = NE;
            boundsObj.SouthWest = SW;
            return(boundsObj);
        }
示例#2
0
文件: JGeofence.cs 项目: CoolWirya/BS
 /// <summary>
 /// SQuare
 /// </summary>
 /// <param name="ObjectCoordinate"></param>
 /// <param name="SouthWest"></param>
 /// <param name="NorthEast"></param>
 /// <returns></returns>
 public static bool IsInTheArea(AVL.Controls.Map.Point ObjectCoordinate, AVL.Controls.Map.Point SouthWest, AVL.Controls.Map.Point NorthEast)
 {
     if (ObjectCoordinate.Latitude >= SouthWest.Latitude && ObjectCoordinate.Latitude <= NorthEast.Latitude &&
         ObjectCoordinate.Longitude >= SouthWest.Longitude && ObjectCoordinate.Longitude <= NorthEast.Longitude)
     {
         return(true);
     }
     return(false);
 }
示例#3
0
        public static string[] GetObjects(string bounds)
        {
            List <string> bb = new List <string>();
            List <AVL.Controls.Map.GCommunicateObject> __datas = new List <AVL.Controls.Map.GCommunicateObject>();

            //Get all the objects of the current user.
            System.Data.DataTable dt = AVL.ObjectList.JObjectLists.GetDataTableToday(WebClassLibrary.SessionManager.Current.MainFrame.CurrentUserCode);
            //Create an array to store data that will be send back to the google map control.
            AVL.Controls.Map.GCommunicateObject[] objects = new AVL.Controls.Map.GCommunicateObject[dt.Rows.Count];
            //Extract south west and north east from bounds string
            AVL.Controls.Map.BoundsObject NESW = AVL.Controls.Map.GCommunicateObject.BoundsStringtoPoints(bounds);
            //First item of returned array from BoundsStringtoPoints method is alwas South West, and second one is always North East
            AVL.Controls.Map.Point SW = NESW.SouthWest;
            AVL.Controls.Map.Point NE = NESW.NorthEast;
            //Loop through objects returned from AVLObjectList table.
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                //Create a point object with latitude and longitude of current row.
                AVL.Controls.Map.PointD p = new AVL.Controls.Map.PointD(
                    Convert.ToDouble(dt.Rows[i]["LastLng"].ToString()),
                    Convert.ToDouble(dt.Rows[i]["LastLat"].ToString()));
                //Geofence using a circle. Specify whether point is in the area or not.
                //There is some other types of geofence methods in AVL.Geofence.JGeofence
                //Note that distance between 2 coordinate in map is so small.
                if (AVL.Geofence.JGeofence.IsInTheCircle(
                        new AVL.Controls.Map.Point()
                {
                    Latitude = SW.Latitude + (NE.Latitude - SW.Latitude) / 2, Longitude = SW.Longitude + (NE.Longitude - SW.Longitude) / 2
                },
                        ((NE.Latitude - SW.Latitude) / 2) > ((NE.Longitude - SW.Longitude) / 2) ? ((NE.Latitude - SW.Latitude) / 2) : ((NE.Longitude - SW.Longitude) / 2),
                        new AVL.Controls.Map.Point()
                {
                    Latitude = p.Y, Longitude = p.X
                }))
                {
                    //If point is in the area, it is allowed to pass through google map,
                    __datas.Add(new AVL.Controls.Map.GCommunicateObject()
                    {
                        ID       = "Bus_" + dt.Rows[i]["Code"].ToString(),
                        Location = p
                    });
                }
            }
            //We need to pass just IDs of objects as an array of strings.
            //Here we do joining of objects that are so close to each other.
            //If third argumant increase,then objects should be closer to be joined.otherwise method will join the objects with longer distance.
            bb.Clear();
            foreach (AVL.Controls.Map.GCommunicateObject g in
                     AVL.Controls.Map.Marker.JoinMarkers(NE.Longitude - SW.Longitude, __datas.ToArray(), 50))// o) //
            {
                bb.Add(g.ID.ToString());
            }
            return(bb.ToArray());
        }
示例#4
0
文件: JGeofence.cs 项目: CoolWirya/BS
        public static double distance(AVL.Controls.Map.Point CenterPoint, AVL.Controls.Map.Point Point)
        {
            AVL.Controls.Map.Point p = new AVL.Controls.Map.Point()
            {
                Latitude  = Point.Latitude - CenterPoint.Latitude,
                Longitude = Point.Longitude - CenterPoint.Longitude
            };
            double distance = Math.Sqrt(Math.Pow(p.Latitude, 2d) + Math.Pow(p.Longitude, 2d));

            return(distance);
        }
示例#5
0
文件: JGeofence.cs 项目: CoolWirya/BS
        /// <summary>
        /// Circle
        /// </summary>
        /// <param name="CenterPoint"></param>
        /// <param name="radius"></param>
        /// <param name="Point"></param>
        /// <returns></returns>
        public static bool IsInTheCircle(AVL.Controls.Map.Point CenterPoint, double radius, AVL.Controls.Map.Point Point)
        {
            AVL.Controls.Map.Point p = new AVL.Controls.Map.Point()
            {
                Latitude  = Point.Latitude - CenterPoint.Latitude,
                Longitude = Point.Longitude - CenterPoint.Longitude
            };
            double distance = Math.Sqrt(Math.Pow(p.Latitude, 2d) + Math.Pow(p.Longitude, 2d));

            if (distance <= radius)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#6
0
文件: JGeofence.cs 项目: CoolWirya/BS
        /// <summary>
        /// Line
        /// </summary>
        /// <param name="ObjectCoordinate"></param>
        /// <param name="Points"></param>
        /// <returns></returns>
        public static bool IsInTheLine(AVL.Controls.Map.Point ObjectCoordinate, List <AVL.Controls.Map.Point> Points)
        {
            AVL.Controls.Map.Point p1 = null, p2 = null;
            double Y;
            bool   IsIn = false;

            for (int i = 0; i < Points.Count - 1; i++)
            {
                p1 = Points[i];
                p2 = Points[i + 1];

                Y = ((p2.Latitude - p1.Latitude) / (p2.Longitude - p1.Longitude) * (ObjectCoordinate.Longitude - p1.Longitude)) - p1.Latitude;

                if ((Y - ObjectCoordinate.Latitude) <= 0.00004 && (Y - ObjectCoordinate.Latitude) >= -0.00004)
                {
                    IsIn = true;
                    break;
                }
            }
            return(IsIn);
        }
示例#7
0
        public static System.Data.DataTable GetDataTableInArea(AVL.Controls.Map.Point SouthWest, AVL.Controls.Map.Point NorthEast)
        {
            if (!ClassLibrary.JPermission.CheckPermission("AVL.Coordinate.Traditional.JTransactionCars.GetDataTableInArea"))
            {
                return(null);
            }
            ClassLibrary.JDataBase DB = new ClassLibrary.JDataBase();
            try
            {
                string query = @"SELECT CarID
      ,[LastLatitude]
      , LastLongitude
	  , LastDate
  FROM [avlsite_com_1].[dbo].[Cars] WHERE  LastLatitude IS NOT NULL AND LastLongitude IS NOT NULL AND 
  LastDate BETWEEN DATEADD(dd, DATEDIFF(dd,0,GETDATE()), 0) 
AND DATEADD(dd, DATEDIFF(dd,0,GETDATE()), 1)
  AND  " +
                               string.Format("LastLatitude BETWEEN {0} AND {1} AND LastLongitude BETWEEN {2} AND {3} ",
                                             SouthWest.Latitude,
                                             NorthEast.Latitude,
                                             SouthWest.Longitude,
                                             NorthEast.Longitude);

                //    query += " AND "+ ClassLibrary.JPermission.getObjectSql("AVL.Coordinate.Traditional.JTransactionCars.GetDataTableInArea", "TransactionCars.CarID");


                DB.setQuery(query);
                return(DB.Query_DataTable());
            }
            catch (Exception ex)
            {
                ClassLibrary.JSystem.Except.AddException(ex);
                return(null);
            }
            finally
            {
                DB.Dispose();
            }
        }
示例#8
0
        /// <summary>
        /// returned an area that coordinate is inside it.
        /// </summary>
        /// <param name="coordinate"></param>
        /// <returns>If coordinate is not inside any area, it returns null.</returns>
        public static AVL.Area.JArea CheckGeofence(AVL.Coordinate.JCoordinate coordinate)
        {
            System.Data.DataTable AreaTable = AVL.Area.JAreas.GetAreas(false);
            AVL.Area.JArea        area;
            AVL.Geofence.GeoData.JGeofenceData geof;
            List <AVL.Controls.Map.Point>      points;

            AVL.Controls.Map.Point currentPoint = new AVL.Controls.Map.Point()
            {
                Latitude  = coordinate.lat,
                Longitude = coordinate.lng
            };
            foreach (System.Data.DataRow dr in AreaTable.Rows)
            {
                area = new AVL.Area.JArea()
                {
                    ObjectsCodes = dr["ObjectsCodes"].ToString(),
                    IsGeofence   = bool.Parse(dr["IsGeofence"].ToString()),
                    Points       = dr["Points"].ToString()
                };
                points = AVL.Area.JArea.ExtractPoints(area.Points);
                if (!AVL.Geofence.JGeofence.IsInThePolygon(currentPoint, points) ||
                    !AVL.Geofence.JGeofence.IsInTheLine(currentPoint, points))
                {
                    geof = new AVL.Geofence.GeoData.JGeofenceData()
                    {
                        entered    = false,
                        GeoCode    = area.code,
                        IsGeofence = area.IsGeofence,
                        LastDate   = coordinate.DeviceSendDateTime,
                        ObjectCode = coordinate.ObjectCode
                    };
                    geof.Insert(false, false);
                    return(area);
                }
            }
            return(null);
        }
示例#9
0
文件: JGeofence.cs 项目: CoolWirya/BS
        /// <summary>
        /// Polygon
        /// </summary>
        /// <param name="point"></param>
        /// <param name="Points"></param>
        /// <returns></returns>
        public static bool IsInThePolygon(AVL.Controls.Map.Point point, List <AVL.Controls.Map.Point> Points)
        {
            double X           = point.Longitude;
            double Y           = point.Latitude;
            int    sides       = Points.Count() - 1;
            int    j           = sides - 1;
            bool   pointStatus = false;

            for (int i = 0; i < sides; i++)
            {
                if (Points[i].Latitude < Y && Points[j].Latitude >= Y ||
                    Points[j].Latitude < Y && Points[i].Latitude >= Y)
                {
                    if (Points[i].Longitude + (Y - Points[i].Latitude) /
                        (Points[j].Latitude - Points[i].Latitude) * (Points[j].Longitude - Points[i].Longitude) < X)
                    {
                        pointStatus = !pointStatus;
                    }
                }
                j = i;
            }
            return(pointStatus);
        }
示例#10
0
        public static List <AVL.Controls.Map.GCommunicateObject> GetCommunicationObjects(string bounds, string id, Dictionary <string, string[]> objects, int currentUserCode)
        {
            bool isinarea = true;

            System.Data.DataTable dt;
            string ids = " AND ol.Code IN(";

            if (id == "1")
            {
                if (objects[currentUserCode.ToString()].Length > 0)
                {
                    foreach (string aa in objects[currentUserCode.ToString()])
                    {
                        ids += aa + ",";
                    }
                    ids  = ids.Remove(ids.Length - 1);
                    ids += ")";
                }
                else
                {
                    return(null);
                }
            }
            else if (id.Contains(','))
            {
                foreach (string aa in id.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    ids += aa + ",";
                }
                ids  = ids.Remove(ids.Length - 1);
                ids += ")";
            }
            //Get fresh data from database.
            dt = WebClassLibrary.JWebDataBase.GetDataTable("select ol.* from AVLObjectList ol inner join " +
                                                           " AVLCash c ON c.userCode=ol.personCode  where ol.personCode=" +
                                                           WebClassLibrary.SessionManager.Current.MainFrame.CurrentUserCode + " AND  ol.lastSendDate > DATEADD(hour,-24,getdate())   AND (c.paid > 0) " + ids);
            List <AVL.Controls.Map.GCommunicateObject> s = new List <AVL.Controls.Map.GCommunicateObject>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                //Extract north east and south west from bounds string.
                AVL.Controls.Map.BoundsObject SwNe = AVL.Controls.Map.GCommunicateObject.BoundsStringtoPoints(bounds);
                AVL.Controls.Map.Point        SW   = SwNe.SouthWest;
                AVL.Controls.Map.Point        NE   = SwNe.NorthEast;
                //Create a point with latitude and longitude of current row.
                AVL.Controls.Map.PointD p = new AVL.Controls.Map.PointD(
                    Convert.ToDouble(dt.Rows[i]["LastLng"].ToString()),
                    Convert.ToDouble(dt.Rows[i]["LastLat"].ToString()));
                //Is in area or not?
                if (!id.Contains(','))
                {
                    if (AVL.Geofence.JGeofence.IsInTheCircle(
                            new AVL.Controls.Map.Point()
                    {
                        Latitude = SW.Latitude + (NE.Latitude - SW.Latitude) / 2, Longitude = SW.Longitude + (NE.Longitude - SW.Longitude) / 2
                    },
                            ((NE.Latitude - SW.Latitude) / 2) > ((NE.Longitude - SW.Longitude) / 2) ? ((NE.Latitude - SW.Latitude) / 2) : ((NE.Longitude - SW.Longitude) / 2),
                            new AVL.Controls.Map.Point()
                    {
                        Latitude = p.Y, Longitude = p.X
                    }))
                    {
                        isinarea = true;
                    }
                    else
                    {
                        isinarea = false;
                    }
                }
                if (isinarea)
                {
                    AVL.Controls.Map.GCommunicateObject gObject = new AVL.Controls.Map.GCommunicateObject();
                    gObject.ID    = "Bus_" + dt.Rows[i]["Code"].ToString();
                    gObject.Title = dt.Rows[i]["Label"].ToString();
                    WebClassLibrary.JActionsInfo action = new WebClassLibrary.JActionsInfo();
                    //     action.Name = dt.Rows[i]["ClassName"].ToString();
                    action.Method         = dt.Rows[i]["ClassName"].ToString() + ".GetIcon";
                    action.ParameterValue = new List <object>();
                    action.ParameterValue.Add(dt.Rows[i]["ObjectCode"].ToString());
                    gObject.Icon = action.runAction().ToString();
                    // مختصات جدید مارکر
                    gObject.Location = new AVL.Controls.Map.PointD()
                    {
                        // NEW Longitude
                        X = Convert.ToDouble(dt.Rows[i]["LastLng"].ToString()),
                        //NEW Latitude
                        Y = Convert.ToDouble(dt.Rows[i]["LastLat"].ToString())
                    };
                    s.Add(gObject);
                }
            }
            return(s);
        }
示例#11
0
        public static AVL.Controls.Map.GCommunicateObject[] JoinMarkers(List <AVL.Controls.Map.GCommunicateObject> objects, int zoom)
        {
            List <AVL.Controls.Map.GCommunicateObject> Clustered = new List <AVL.Controls.Map.GCommunicateObject>();
            double Meter = AVL.Controls.Map.NewMapControl.NewGoogleMap.GetMeterByZoom(zoom);
            double distance;

            AVL.Controls.Map.Point from;
            AVL.Controls.Map.Point end;
            List <AVL.Controls.Map.GCommunicateObject> temp = objects;

            if (Clustered.Count == 0)
            {
                Clustered.Add(temp[0]);
            }
            int index = 0;

            AVL.Controls.Map.GCommunicateObject c;
            while (temp.Count > 0)
            {
                c = Clustered[index];
                if (temp.Count == 1)
                {
                    Clustered[index].GroupIDs = c.ID.ToString();
                    break;
                }
                foreach (AVL.Controls.Map.GCommunicateObject g in temp)
                {
                    from = new AVL.Controls.Map.Point()
                    {
                        Latitude = c.Location.X, Longitude = c.Location.Y
                    };
                    end = new AVL.Controls.Map.Point()
                    {
                        Latitude = g.Location.X, Longitude = g.Location.Y
                    };
                    distance = AVL.Controls.Map.NewMapControl.NewGoogleMap.GetDistance(from, end);// *.5 / Meter;
                    if (distance <= (Meter / 10))
                    {
                        if (c.GroupIDs.Length > 0)
                        {
                            c.GroupIDs += ",";
                        }
                        c.GroupIDs += g.ID;
                    }
                }
                temp.RemoveAll(x => c.GroupIDs.Contains(x.ID.ToString()));
                if (temp.Count == 0)
                {
                    break;
                }
                try
                {
                    Clustered.Add(temp[0]);
                }
                catch
                {
                }
                index++;
            }
            return(Clustered.ToArray());
        }
示例#12
0
文件: Line.cs 项目: CoolWirya/BS
 public bool IsInTheCircle(AVL.Controls.Map.Point CenterPoint, double radius, AVL.Controls.Map.Point Point)
 {
     return(AVL.Geofence.JGeofence.IsInTheCircle(CenterPoint, radius, Point));
 }
示例#13
0
文件: Line.cs 项目: CoolWirya/BS
 /// <summary>
 ///
 /// </summary>
 /// <param name="ObjectCoordinate"></param>
 /// <param name="SouthWest"></param>
 /// <param name="NorthEast"></param>
 /// <returns></returns>
 public bool IsInTheArea(Point ObjectCoordinate, AVL.Controls.Map.Point SouthWest, AVL.Controls.Map.Point NorthEast)
 {
     return(AVL.Geofence.JGeofence.IsInTheArea(ObjectCoordinate, SouthWest, NorthEast));
 }