public ActionResult GetPlaceInfo(long sourceElementId, int sourceElementType)
        {
            var db   = new PraxisContext();
            var area = db.Places.Include(e => e.Tags).FirstOrDefault(e => e.SourceItemID == sourceElementId && e.SourceItemType == sourceElementType);

            if (area == null)
            {
                return(View());
            }

            TagParser.ApplyTags(new System.Collections.Generic.List <DbTables.Place>()
            {
                area
            }, "mapTiles");
            ViewBag.areaname = TagParser.GetPlaceName(area.Tags);
            ViewBag.type     = area.GameElementName;

            var geoarea = Converters.GeometryToGeoArea(area.ElementGeometry.Envelope);

            geoarea = new Google.OpenLocationCode.GeoArea(geoarea.SouthLatitude - ConstantValues.resolutionCell10,
                                                          geoarea.WestLongitude - ConstantValues.resolutionCell10,
                                                          geoarea.NorthLatitude + ConstantValues.resolutionCell10,
                                                          geoarea.EastLongitude + ConstantValues.resolutionCell10); //add some padding to the edges.
            ImageStats istats = new ImageStats(geoarea, (int)(geoarea.LongitudeWidth / ConstantValues.resolutionCell11Lon), (int)(geoarea.LatitudeHeight / ConstantValues.resolutionCell11Lat));

            //sanity check: we don't want to draw stuff that won't fit in memory, so check for size and cap it if needed
            if (istats.imageSizeX * istats.imageSizeY > 8000000)
            {
                var ratio   = geoarea.LongitudeWidth / geoarea.LatitudeHeight; //W:H,
                var newSize = (istats.imageSizeY > 2000 ? 2000 : istats.imageSizeY);
                istats = new ImageStats(geoarea, (int)(newSize * ratio), newSize);
            }
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            //var tileSvg = MapTiles.DrawAreaAtSizeSVG(istats); ViewBag.UseSvg = true;
            var tile = MapTiles.DrawAreaAtSize(istats); ViewBag.UseSvg = false;

            sw.Stop();

            ViewBag.imageString = "data:image/png;base64," + Convert.ToBase64String(tile);
            //ViewBag.imageString = tileSvg.Substring(39); //skip the <xml> tag
            ViewBag.timeToDraw  = sw.Elapsed;
            ViewBag.placeCount  = 0;
            ViewBag.areasByType = "";
            var places = Place.GetPlaces(istats.area);

            ViewBag.placeCount = places.Count();
            var    grouped     = places.GroupBy(p => p.GameElementName);
            string areasByType = "";

            foreach (var g in grouped)
            {
                areasByType += g.Key + g.Count() + "<br />";
            }

            ViewBag.areasByType = areasByType;

            return(View());
        }
Esempio n. 2
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);
        }