Esempio n. 1
0
        public ActionResult DrawTile(string code, string styleSet = "mapTiles")
        {
            try
            {
                PerformanceTracker pt = new PerformanceTracker("DrawTile");
                MapTileSupport.GetPlusCodeImagePixelSize(code, out var imgX, out var imgY);
                var info = new ImageStats(OpenLocationCode.DecodeValid(code), imgX, imgY);

                if (!DataCheck.IsInBounds(cache.Get <IPreparedGeometry>("serverBounds"), info.area))
                {
                    pt.Stop("OOB");
                    return(StatusCode(500));
                }

                byte[] tileData = getExistingSlippyTile(code, styleSet);
                if (tileData != null)
                {
                    pt.Stop(code + "|" + styleSet);
                    return(File(tileData, "image/png"));
                }

                //Make tile
                var places   = GetPlacesForTile(info, null, styleSet, false);
                var paintOps = MapTileSupport.GetPaintOpsForStoredElements(places, styleSet, info);
                tileData = FinishMapTile(info, paintOps, code, styleSet);

                pt.Stop(code + "|" + styleSet + "|" + Configuration.GetValue <string>("MapTilesEngine"));
                return(File(tileData, "image/png"));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex);
                return(StatusCode(500));
            }
        }
Esempio n. 2
0
        [Route("/[controller]/Slippy/{styleSet}/{zoom}/{x}/{y}.png")]         //slippy map conventions.
        public ActionResult DrawSlippyTile(int zoom, int x, int y, string styleSet)
        {
            try
            {
                PerformanceTracker pt      = new PerformanceTracker("DrawSlippyTile");
                string             tileKey = x.ToString() + "|" + y.ToString() + "|" + zoom.ToString();
                var info = new ImageStats(zoom, x, y, IMapTiles.SlippyTileSizeSquare);

                if (!DataCheck.IsInBounds(cache.Get <IPreparedGeometry>("serverBounds"), info.area))
                {
                    pt.Stop("OOB");
                    return(StatusCode(500));
                }

                byte[] tileData = getExistingSlippyTile(tileKey, styleSet);
                if (tileData != null)
                {
                    pt.Stop(tileKey + "|" + styleSet);
                    return(File(tileData, "image/png"));
                }

                //Make tile
                var places   = GetPlacesForTile(info, null, styleSet, false);
                var paintOps = MapTileSupport.GetPaintOpsForStoredElements(places, styleSet, info);
                tileData = FinishSlippyMapTile(info, paintOps, tileKey, styleSet);

                pt.Stop(tileKey + "|" + styleSet + "|" + Configuration.GetValue <string>("MapTilesEngine"));
                return(File(tileData, "image/png"));
            }
            catch (Exception ex)
            {
                ErrorLogger.LogError(ex);
                return(StatusCode(500));
            }
        }
Esempio n. 3
0
        private static void DrawOneImage(string code)
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            TagParser.ApplyTags(memorySource, "mapTiles");
            ImageStats istats   = new ImageStats(OpenLocationCode.DecodeValid(code), 1024, 1024);
            var        paintOps = MapTileSupport.GetPaintOpsForStoredElements(memorySource, "mapTiles", istats);

            File.WriteAllBytes(config["OutputDataFolder"] + code + ".png", MapTileSupport.DrawPlusCode(code, paintOps, "mapTiles"));
            sw.Stop();
            Log.WriteLog("image drawn from memory in " + sw.Elapsed);
        }
Esempio n. 4
0
        private static void DrawPosterOfServer()
        {
            var db     = new PraxisContext();
            var bounds = db.ServerSettings.First();

            var geoArea = new GeoArea(bounds.SouthBound, bounds.WestBound, bounds.NorthBound, bounds.EastBound);
            //do the math to scale image.
            //the smaller side is set to 24", the larger size scales up proportionally up to a max of 36"
            //if the longer side is > 36", scale both down by the difference?

            //36x24 is target poster size, at 300 dpi, our image size will allow for a half-inch of margin on both axes.
            var dpi      = 300;
            var maxXSide = 35 * dpi;
            var maxYSide = 23 * dpi;
            var xSize    = 0;
            var ySize    = 0;

            var heightScale = geoArea.LatitudeHeight / geoArea.LongitudeWidth; //Y pixels per X pixel

            if (heightScale > 1)                                               // Y axis is longer than X axis
            {
                heightScale = geoArea.LongitudeWidth / geoArea.LatitudeHeight;
                maxXSide    = 23 * dpi;
                maxYSide    = 35 * dpi;
                ySize       = maxYSide;
                xSize       = (int)(maxXSide * heightScale);
            }
            else
            {
                xSize = maxXSide;
                ySize = (int)(maxYSide * heightScale);
            }

            Log.WriteLog("Loading all places from DB");
            var places = GetPlaces(geoArea);
            var iStats = new ImageStats(geoArea, xSize, ySize);

            Log.WriteLog("Generating paint operations");
            var paintOps = MapTileSupport.GetPaintOpsForStoredElements(places, "mapTiles", iStats);

            Log.WriteLog("Drawing image");
            var image = MapTiles.DrawAreaAtSize(iStats, paintOps);

            File.WriteAllBytes("ServerPoster.png", image);
            Log.WriteLog("Image saved to disk");
        }