コード例 #1
0
        private byte[] FinishSlippyMapTile(ImageStats info, List <CompletePaintOp> paintOps, string tileKey, string styleSet)
        {
            byte[] results = null;
            results = MapTiles.DrawAreaAtSize(info, paintOps);

            if (!SaveMapTiles())
            {
                var db = new PraxisContext();
                var existingResults = db.SlippyMapTiles.FirstOrDefault(mt => mt.Values == tileKey && mt.StyleSet == styleSet);
                if (existingResults == null)
                {
                    existingResults = new SlippyMapTile()
                    {
                        Values = tileKey, StyleSet = styleSet, AreaCovered = Converters.GeoAreaToPolygon(GeometrySupport.MakeBufferedGeoArea(info.area))
                    };
                    db.SlippyMapTiles.Add(existingResults);
                }

                existingResults.ExpireOn = DateTime.Now.AddYears(10);
                existingResults.TileData = results;
                existingResults.GenerationID++;
                db.SaveChanges();
            }

            return(results);
        }
コード例 #2
0
        /// <summary>
        /// Get the image for a PlusCode. Can optionally draw in a specific style set.
        /// </summary>
        /// <param name="area">the PlusCode string to draw. Can be 6-11 digits long</param>
        /// <param name="styleSet">the TagParser style set to use when drawing</param>
        /// <param name="doubleRes">treat each Cell11 contained as 2x2 pixels when true, 1x1 when not.</param>
        /// <returns></returns>
        public static byte[] DrawPlusCode(string area, string styleSet = "mapTiles")
        {
            //This might be a cleaner version of my V4 function, for working with CellX sized tiles..
            //This will draw at a Cell11 resolution automatically.
            //Split it into a few functions.
            //then get all the area

            GetPlusCodeImagePixelSize(area, out var imgX, out var imgY);
            ImageStats info = new ImageStats(OpenLocationCode.DecodeValid(area), imgX, imgY);

            info.drawPoints = true;
            var places   = GetPlacesForTile(info);
            var paintOps = GetPaintOpsForStoredElements(places, styleSet, info);

            return(MapTiles.DrawAreaAtSize(info, paintOps));
        }
コード例 #3
0
        public ActionResult GetMapTileInfo(int x, int y, int zoom)
        {
            //Draw the map tile, with extra info to send over.
            ImageStats istats = new ImageStats(zoom, x, y, IMapTiles.SlippyTileSizeSquare);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            var tile = MapTiles.DrawAreaAtSize(istats);

            sw.Stop();

            ViewBag.placeCount  = Place.GetPlaces(istats.area).Count();
            ViewBag.timeToDraw  = sw.Elapsed.ToString();
            ViewBag.imageString = "data:image/png;base64," + Convert.ToBase64String(tile);

            return(View());
        }
コード例 #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");
        }