Ejemplo n.º 1
0
        public override void CreateTripMap(DataTable coords, int width, int height, MapMode mapmode, MapSpecial special, string filename)
        {
            if (String.IsNullOrEmpty(ApplicationSettings.Default.MapQuestKey))
            {
                return;
            }
            if (coords == null)
            {
                return;
            }
            // https://open.mapquestapi.com/staticmap/v5/map?key=ulMOOlevG9FunIVobQB2BG2GA0EdCjjH&boundingBox=38.915,-77.072,38.876,-77.001&size=200,150&type=dark
            Tuple <double, double, double, double> extent = DetermineExtent(coords);

            if (extent == null)
            {
                return;
            }

            StringBuilder sb = new StringBuilder();

            _ = sb.Append("http://open.mapquestapi.com/staticmap/v5/map?key=");
            _ = sb.Append(ApplicationSettings.Default.MapQuestKey);
            _ = sb.Append("&boundingBox=");
            _ = sb.Append(extent.Item1.ToString(Tools.ciEnUS)).Append(",");
            _ = sb.Append(extent.Item2.ToString(Tools.ciEnUS)).Append(",");
            _ = sb.Append(extent.Item3.ToString(Tools.ciEnUS)).Append(",");
            _ = sb.Append(extent.Item4.ToString(Tools.ciEnUS));
            _ = sb.Append($"&size={width},{height}&type=dark");
            _ = sb.Append("&locations=");
            _ = sb.Append(Convert.ToDouble(coords.Rows[0]["lat"], Tools.ciDeDE).ToString(Tools.ciEnUS)).Append(",").Append(Convert.ToDouble(coords.Rows[0]["lng"], Tools.ciDeDE).ToString(Tools.ciEnUS));
            _ = sb.Append("|marker-start||");
            _ = sb.Append(Convert.ToDouble(coords.Rows[coords.Rows.Count - 1]["lat"], Tools.ciDeDE).ToString(Tools.ciEnUS)).Append(",").Append(Convert.ToDouble(coords.Rows[coords.Rows.Count - 1]["lng"], Tools.ciDeDE).ToString(Tools.ciEnUS));
            _ = sb.Append("|marker-end");
            _ = sb.Append("&shape=");
            bool first    = true;
            int  posquery = 0;

            if (coords.Rows.Count < 4)
            {
                return;
            }

            int step = coords.Rows.Count / 200;

            if (step == 0)
            {
                step = 1;
            }

            for (int pos = 0; pos < coords.Rows.Count; pos++)
            {
                DataRow dr = coords.Rows[pos];

                if (!(pos % step == 0))
                {
                    continue;
                }


                if (first)
                {
                    first = false;
                }
                else
                {
                    sb.Append("|");
                }

                sb.Append(Convert.ToDouble(dr["lat"], Tools.ciDeDE).ToString(Tools.ciEnUS)).Append(",").Append(Convert.ToDouble(dr["lng"], Tools.ciDeDE).ToString(Tools.ciEnUS));
                posquery++;
            }
            string url = sb.ToString();

            System.Diagnostics.Debug.WriteLine(url);

            try
            {
                using (WebClient webClient = new WebClient())
                {
                    webClient.Headers.Add("User-Agent: TeslaLogger");
                    webClient.Headers.Add("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");

                    // Download the Web resource and save it into the current filesystem folder.
                    webClient.DownloadFile(url, filename);
                    Logfile.Log("Create File: " + filename);
                }

                System.Threading.Thread.Sleep(1000);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                Logfile.Log("Rows count: " + coords.Rows.Count + " posquery= " + posquery + "\r\n" + ex.ToString());
            }
        }
Ejemplo n.º 2
0
        public override void CreateParkingMap(double lat, double lng, int width, int height, MapMode mapmode, MapSpecial special, string filename)
        {
            if (String.IsNullOrEmpty(ApplicationSettings.Default.MapQuestKey))
            {
                return;
            }
            StringBuilder sb = new StringBuilder();

            sb.Append("http://open.mapquestapi.com/staticmap/v5/map?key=");
            sb.Append(ApplicationSettings.Default.MapQuestKey);
            sb.Append("&center=");
            sb.Append(lat.ToString(Tools.ciEnUS)).Append(",");
            sb.Append(lng.ToString(Tools.ciEnUS));
            sb.Append($"&size={width},{height}&type=dark");
            sb.Append("&locations=");
            sb.Append(lat.ToString(Tools.ciEnUS)).Append(",").Append(lng.ToString(Tools.ciEnUS));
            sb.Append("|marker-3E72B1|");

            string url = sb.ToString();

            System.Diagnostics.Debug.WriteLine(url);

            try
            {
                using (WebClient webClient = new WebClient())
                {
                    webClient.Headers.Add("User-Agent: TeslaLogger");
                    webClient.Headers.Add("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");

                    // Download the Web resource and save it into the current filesystem folder.
                    webClient.DownloadFile(url, filename);

                    Logfile.Log("Create File: " + filename);
                }

                System.Threading.Thread.Sleep(500);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                Logfile.Log(ex.ToString());
            }
        }
Ejemplo n.º 3
0
        public override void CreateTripMap(DataTable coords, int width, int height, MapMode mapmode, MapSpecial special, string filename)
        {
            if (coords == null)
            {
                return;
            }
            // workaround for linux mono libgdiplus memory leak
            Dictionary <string, object>            job    = new Dictionary <string, object>();
            Tuple <double, double, double, double> extent = DetermineExtent(coords);

            if (extent == null)
            {
                return;
            }
            // calculate center point of map
            double lat_center = (extent.Item1 + extent.Item3) / 2;
            double lng_center = (extent.Item2 + extent.Item4) / 2;
            int    zoom       = CalculateZoom(extent, width, height);

            job.Add("zoom", zoom);
            double x_center = LngToTileX(lng_center, zoom);

            job.Add("x_center", x_center);
            double y_center = LatToTileY(lat_center, zoom);

            job.Add("y_center", y_center);
            job.Add("filename", filename);
            job.Add("width", width);
            job.Add("height", height);
            job.Add("mapmode", mapmode);
            job.Add("tileSize", tileSize);
            job.Add("MapCachePath", FileManager.GetMapCachePath());
            List <double> latlng = new List <double>();

            for (int row = 0; row < coords.Rows.Count; row++)
            {
                latlng.Add(Convert.ToDouble(coords.Rows[row]["lat"], Tools.ciDeDE));
                latlng.Add(Convert.ToDouble(coords.Rows[row]["lng"], Tools.ciDeDE));
            }
            job.Add("latlng", latlng.ToArray());
            string tempfile = Path.GetTempFileName();

            File.WriteAllText(tempfile, new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(job), Encoding.UTF8);

            GetOSMMapGeneratorFilename(out string fileName, out string arguments);
            arguments += "-jobfile " + tempfile + (Program.VERBOSE ? " - debug" : "");

            using (Process process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = fileName,
                    Arguments = arguments,
                    UseShellExecute = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow = true
                }
            })
            {
                process.Start();
                while (!process.StandardOutput.EndOfStream)
                {
                    Logfile.Log(process.StandardOutput.ReadLine());
                }
                process.WaitForExit();
            }
            if (File.Exists(tempfile))
            {
                File.Delete(tempfile);
            }
        }
Ejemplo n.º 4
0
        public override void CreateParkingMap(double lat, double lng, int width, int height, MapMode mapmode, MapSpecial special, string filename)
        {
            int zoom = 16;

            // workaround for linux mono libgdiplus memory leak
            Dictionary <string, object> job = new Dictionary <string, object>();
            double x_center = LngToTileX(lng, zoom);
            double y_center = LatToTileY(lat, zoom);

            job.Add("zoom", zoom);
            job.Add("x_center", x_center);
            job.Add("y_center", y_center);
            job.Add("filename", filename);
            job.Add("width", width);
            job.Add("height", height);
            job.Add("mapmode", mapmode);
            job.Add("tileSize", tileSize);
            job.Add("MapCachePath", FileManager.GetMapCachePath());
            job.Add("poi", "park");
            job.Add("lat", lat);
            job.Add("lng", lng);

            string tempfile = Path.GetTempFileName();

            GetOSMMapGeneratorFilename(out string fileName, out string arguments);
            arguments += "-jobfile " + tempfile + (Program.VERBOSE ? " - debug" : "");

            File.WriteAllText(tempfile, new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(job), Encoding.UTF8);
            using (Process process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = fileName,
                    Arguments = arguments,
                    UseShellExecute = false,
                    RedirectStandardOutput = true,
                    CreateNoWindow = true
                }
            })
            {
                process.Start();
                while (!process.StandardOutput.EndOfStream)
                {
                    Logfile.Log(process.StandardOutput.ReadLine());
                }
                process.WaitForExit();
            }
            if (File.Exists(tempfile))
            {
                File.Delete(tempfile);
            }

            /*
             * using (Bitmap map = DrawMap(width, height, 19, x_center, y_center, mapmode))
             * {
             *  // map has background tiles, OSM attribution and dark mode, if enabled
             *  DrawIcon(map, lat, lng, MapIcon.Park, 19, x_center, y_center);
             *  SaveImage(map, filename);
             *  map.Dispose();
             * }
             */
        }
Ejemplo n.º 5
0
 public abstract void CreateTripMap(DataTable coords, int width, int height, MapMode mapmode, MapSpecial special, string filename);
Ejemplo n.º 6
0
 public abstract void CreateParkingMap(double lat, double lng, int width, int height, MapMode mapmode, MapSpecial special, string filename);