示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddMvc();
            //services.AddCoreComponentServiceCollection(); //injects the DbContext and other services into this collection. (Eventually, still working on that)
            services.AddMemoryCache(); //AddMvc calls this quietly, but I'm calling it explicitly here anyways.
            services.AddResponseCompression();

            IMapTiles mapTiles = null;

            if (mapTilesEngine == "SkiaSharp")
            {
                Assembly asm;
                if (System.Diagnostics.Debugger.IsAttached) //Folders vary, when debugging in IIS run path and local folder aren't the same so we check here.
                {
                    asm = Assembly.LoadFrom(@".\bin\Debug\net6.0\PraxisMapTilesSkiaSharp.dll");
                }
                else
                {
                    asm = Assembly.LoadFrom(@"PraxisMapTilesSkiaSharp.dll");
                }
                mapTiles = (IMapTiles)Activator.CreateInstance(asm.GetType("PraxisCore.MapTiles"));
                services.AddSingleton(typeof(IMapTiles), mapTiles);
            }
            else if (mapTilesEngine == "ImageSharp")
            {
                Assembly asm;
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    asm = Assembly.LoadFrom(@".\bin\Debug\net6.0\PraxisMapTilesImageSharp.dll");
                }
                else
                {
                    asm = Assembly.LoadFrom(@"PraxisMapTilesImageSharp.dll");
                }
                mapTiles = (IMapTiles)Activator.CreateInstance(asm.GetType("PraxisCore.MapTiles"));
                services.AddSingleton(typeof(IMapTiles), mapTiles);
            }

            TagParser.Initialize(Configuration.GetValue <bool>("ForceStyleDefaults"), mapTiles);
            MapTileSupport.MapTiles = mapTiles;
        }
示例#2
0
        //Removed for now because I do not currently use it for any of my game modes, but I may still want to use this or something based on this in the future.
        //private static void populateEmptyAreas(string cell6)
        //{
        //    var db = new PraxisContext();
        //    CodeArea box6 = OpenLocationCode.DecodeValid(cell6);
        //    var location6 = Converters.GeoAreaToPolygon(box6);
        //    var places = db.StoredOsmElements.Where(md => md.elementGeometry.Intersects(location6)).ToList(); //TODO: filter this down to only areas with IsGameElement == true
        //    var fakeplaces = places.Where(p => p.IsGenerated).ToList();

        //    for (int x = 0; x < 20; x++)
        //    {
        //        for (int y = 0; y < 20; y++)
        //        {
        //            string cell8 = cell6 + OpenLocationCode.CodeAlphabet[x] + OpenLocationCode.CodeAlphabet[y];
        //            CodeArea box = OpenLocationCode.DecodeValid(cell8);
        //            var location = Converters.GeoAreaToPolygon(box);
        //            if (!places.Any(md => md.elementGeometry.Intersects(location)) && !fakeplaces.Any(md => md.elementGeometry.Intersects(location)))
        //                CreateInterestingPlaces(cell8);
        //        }
        //    }
        //}

        private static void ApplyConfigValues()
        {
            PraxisContext.connectionString = config["DbConnectionString"];
            PraxisContext.serverMode       = config["DbMode"];

            if (config["MapTilesEngine"] == "SkiaSharp")
            {
                var asm = Assembly.LoadFrom(@"PraxisMapTilesSkiaSharp.dll");
                MapTiles = (IMapTiles)Activator.CreateInstance(asm.GetType("PraxisCore.MapTiles"));
            }
            else if (config["MapTilesEngine"] == "ImageSharp")
            {
                var asm2 = Assembly.LoadFrom(@"PraxisMapTilesImageSharp.dll");
                MapTiles = (IMapTiles)Activator.CreateInstance(asm2.GetType("PraxisCore.MapTiles"));
            }
            IMapTiles.GameTileScale        = config["mapTileScaleFactor"].ToInt();
            IMapTiles.SlippyTileSizeSquare = config["slippyTileSize"].ToInt();
            IMapTiles.BufferSize           = config["AreaBuffer"].ToDouble();

            if (config["UseHighAccuracy"] != "True")
            {
                factory       = NtsGeometryServices.Instance.CreateGeometryFactory(new PrecisionModel(1000000), 4326); //SRID matches 10-character Plus code values.  Precision model means round all points to 7 decimal places to not exceed float's useful range.
                SimplifyAreas = true;                                                                                  //rounds off points that are within a Cell10's distance of each other. Makes fancy architecture and highly detailed paths less pretty on map tiles, but works for gameplay data.
            }

            Log.Verbosity = (Log.VerbosityLevels)config["LogLevel"].ToInt();

            if (config["KeepElementsInMemory"] == "True")
            {
                memorySource = new List <DbTables.Place>(20000);
            }

            if (config["UseMariaDBInFile"] == "True" && config["DbMode"] != "MariaDB")
            {
                Log.WriteLog("You set a MariaDB-only option on and aren't using MariaDB! Fix the configs to use MariaDB or disable the InFile setting and run again.", Log.VerbosityLevels.High);
                return;
            }
        }
示例#3
0
        /// <summary>
        /// Call once when the server or app is started. Loads all the styles and caches baseline data for later use.
        /// </summary>
        /// <param name="onlyDefaults">if true, skip loading the styles from the DB and use Praxismapper's defaults </param>
        public static void Initialize(bool onlyDefaults = false, IMapTiles mapTiles = null)
        {
            MapTiles = mapTiles;
            List <StyleEntry> styles;

            if (onlyDefaults)
            {
                styles = Singletons.defaultStyleEntries;

                long i = 1;
                foreach (var s in styles)
                {
                    foreach (var p in s.PaintOperations)
                    {
                        p.Id = i++;
                    }
                }
            }
            else
            {
                try
                {
                    //Load TPE entries from DB for app.
                    var db = new PraxisContext();
                    styles = db.StyleEntries.Include(t => t.StyleMatchRules).Include(t => t.PaintOperations).ToList();
                    if (styles == null || styles.Count() == 0)
                    {
                        styles = Singletons.defaultStyleEntries;
                    }

                    var bitmaps = db.StyleBitmaps.ToList();
                    foreach (var b in bitmaps)
                    {
                        cachedBitmaps.Add(b.Filename, b.Data); //Actual MapTiles dll will process the bitmap, we just load it here.
                    }
                }
                catch (Exception ex)
                {
                    //The database doesn't exist, use defaults.
                    Log.WriteLog("Error initializing:" + ex.Message, Log.VerbosityLevels.Errors);
                    styles = Singletons.defaultStyleEntries;
                }
            }

            var groups = styles.GroupBy(s => s.StyleSet);

            foreach (var g in groups)
            {
                allStyleGroups.Add(g.Key, g.Select(gg => gg).OrderBy(gg => gg.MatchOrder).ToDictionary(k => k.Name, v => v));
            }

            //Default style should be transparent, matches anything (assumed other styles were checked first)
            defaultStyle = new StyleEntry()
            {
                MatchOrder      = 10000,
                Name            = "unmatched",
                StyleSet        = "mapTiles",
                PaintOperations = new List <StylePaint>()
                {
                    new StylePaint()
                    {
                        HtmlColorCode = "00000000", FillOrStroke = "fill", LineWidthDegrees = 1, LinePattern = "solid", LayerId = 101
                    }
                },
                StyleMatchRules = new List <StyleMatchRule>()
                {
                    new StyleMatchRule()
                    {
                        Key = "*", Value = "*", MatchType = "default"
                    }
                }
            };
            MapTiles.Initialize();
        }
示例#4
0
 public MapTileController(IConfiguration configuration, IMemoryCache memoryCacheSingleton, IMapTiles mapTile)
 {
     Configuration = configuration;
     cache         = memoryCacheSingleton;
     MapTiles      = mapTile;
 }
 public AdminViewController(IConfiguration config, IMapTiles mapTiles)
 {
     Configuration = config;
     MapTiles      = mapTiles;
 }