Exemplo n.º 1
0
        public void DefaultWalker_TotalCalculation_ShouldMatchMgCookerOriginal()
        {
            var mdfId = "Library://Samples/Sheboygan/MapsTiled/Sheboygan.MapDefinition";
            var mdf   = ObjectFactory.CreateMapDefinition(new Version(1, 0, 0), "Sheboygan");

            mdf.ResourceID = mdfId;
            mdf.InitBaseMap();
            var group = mdf.BaseMap.AddBaseLayerGroup("Base Layer Group");

            group.Visible = true;
            foreach (double scale in TileTests.SCALE_LIST.Reverse())
            {
                mdf.BaseMap.AddFiniteDisplayScale(scale);
            }
            mdf.SetExtents(-87.764986990962839, 43.691398128787782, -87.695521510899724, 43.797520000480347);

            var walkOptions = new DefaultTileWalkOptions(mdf);

            walkOptions.MetersPerUnit = 111319.490793274;
            var walker = new DefaultTileWalker(walkOptions);

            var tiles = walker.GetTileList();

            Assert.Equal(mdfId, walker.ResourceID);
            Assert.Equal(127472, tiles.Length);
        }
Exemplo n.º 2
0
        public void TileSeeder_WithDefaultWalker()
        {
            var mdfId = "Library://Samples/Sheboygan/MapsTiled/Sheboygan.MapDefinition";
            var mdf   = ObjectFactory.CreateMapDefinition(new Version(1, 0, 0), "Sheboygan");

            mdf.ResourceID = mdfId;
            mdf.InitBaseMap();
            var group = mdf.BaseMap.AddBaseLayerGroup("Base Layer Group");

            group.Visible = true;
            foreach (double scale in TileTests.SCALE_LIST.Reverse())
            {
                mdf.BaseMap.AddFiniteDisplayScale(scale);
            }
            mdf.SetExtents(-87.764986990962839, 43.691398128787782, -87.695521510899724, 43.797520000480347);

            var walkOptions = new DefaultTileWalkOptions(mdf);

            walkOptions.MetersPerUnit = 111319.490793274;
            var walker = new DefaultTileWalker(walkOptions);

            var mockTileSvc = new Mock <ITileService>();

            mockTileSvc
            .Setup(t => t.GetTile(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns(() => MemoryStreamPool.GetStream());

            var options = new TileSeederOptions();
            var seeder  = new TileSeeder(mockTileSvc.Object, walker, options);
            var stats   = seeder.Run();

            Assert.Equal(mdfId, stats.ResourceID);
            Assert.Equal(127472, stats.TilesRendered);

            mockTileSvc.Verify(t => t.GetTile(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()), Times.Exactly(stats.TilesRendered));

            /*
             * var tiles = walker.GetTileList();
             * for (int i = 0; i < tiles.Length; i++)
             * {
             *  var t = tiles[i];
             *  mockTileSvc.Verify(ts => ts.GetTile(mdfId, t.GroupName, t.Col, t.Row, t.Scale), Times.Once());
             * }
             */
        }
Exemplo n.º 3
0
        public void TileSeeder_WithDefaultWalkerAndCustomBounds()
        {
            var mdfId = "Library://Samples/Sheboygan/MapsTiled/Sheboygan.MapDefinition";
            var mdf   = ObjectFactory.CreateMapDefinition(new Version(1, 0, 0), "Sheboygan");

            mdf.ResourceID = mdfId;
            mdf.InitBaseMap();
            var group = mdf.BaseMap.AddBaseLayerGroup("Base Layer Group");

            group.Visible = true;
            foreach (double scale in TileTests.SCALE_LIST.Reverse())
            {
                mdf.BaseMap.AddFiniteDisplayScale(scale);
            }
            mdf.SetExtents(-87.764986990962839, 43.691398128787782, -87.695521510899724, 43.797520000480347);
            var ovExtents = ObjectFactory.CreateEnvelope(-87.7278601614039, 43.7443959276596, -87.7135994943579, 43.7592852552018);

            var walkOptions = new DefaultTileWalkOptions(mdf);

            walkOptions.MetersPerUnit   = 111319.490793274;
            walkOptions.OverrideExtents = ovExtents;
            var walker = new DefaultTileWalker(walkOptions);

            var mockTileSvc = new Mock <ITileService>();

            mockTileSvc
            .Setup(t => t.GetTile(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns(() => MemoryStreamPool.GetStream());

            var options = new TileSeederOptions();
            var seeder  = new TileSeeder(mockTileSvc.Object, walker, options);
            var stats   = seeder.Run();

            Assert.Equal(mdfId, stats.ResourceID);

            //I don't know the exact number here, but it should be less than the original and
            //greater than the bogus amount of 10 tiles
            Assert.True(stats.TilesRendered < 127472);
            Assert.True(stats.TilesRendered > 10);

            mockTileSvc.Verify(t => t.GetTile(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()), Times.Exactly(stats.TilesRendered));
        }
Exemplo n.º 4
0
        public void DefaultWalker_WithCustomBounds_TotalCalculation_ShouldMatchMgCookerOriginal()
        {
            var mdfId = "Library://Samples/Sheboygan/MapsTiled/Sheboygan.MapDefinition";
            var mdf   = ObjectFactory.CreateMapDefinition(new Version(1, 0, 0), "Sheboygan");

            mdf.ResourceID = mdfId;
            mdf.InitBaseMap();
            var group = mdf.BaseMap.AddBaseLayerGroup("Base Layer Group");

            group.Visible = true;
            foreach (double scale in TileTests.SCALE_LIST.Reverse())
            {
                mdf.BaseMap.AddFiniteDisplayScale(scale);
            }
            mdf.SetExtents(-87.764986990962839, 43.691398128787782, -87.695521510899724, 43.797520000480347);
            var ovExtents = ObjectFactory.CreateEnvelope(-87.7278601614039, 43.7443959276596, -87.7135994943579, 43.7592852552018);

            var walkOptions = new DefaultTileWalkOptions(mdf);

            walkOptions.MetersPerUnit = 111319.490793274;
            var walker = new DefaultTileWalker(walkOptions);

            var tiles = walker.GetTileList();

            Assert.Equal(mdfId, walker.ResourceID);
            Assert.Equal(127472, tiles.Length);

            walkOptions.OverrideExtents = ovExtents;
            walker = new DefaultTileWalker(walkOptions);
            tiles  = walker.GetTileList();

            //I don't know the exact number here, but it should be less than the original and
            //greater than the bogus amount of 10 tiles
            Assert.True(tiles.Length < 127472);
            Assert.True(tiles.Length > 10);
        }
Exemplo n.º 5
0
        static int RunMapGuide(MgTileSeederOptions options)
        {
            int ret = 0;

            try
            {
                options.Validate();

                var conn = ConnectionProviderRegistry.CreateConnection("Maestro.Http",
                                                                       "Url", options.MapAgentUri,
                                                                       "Username", options.Username,
                                                                       "Password", options.Password);

                var tileSvc = (ITileService)conn.GetService((int)ServiceType.Tile);
                var res     = conn.ResourceService.GetResource(options.ResourceID);
                DefaultTileWalkOptions walkOptions = null;
                switch (res)
                {
                case IMapDefinition mdf:
                    walkOptions = new DefaultTileWalkOptions(mdf, options.Groups.ToArray());
                    //If meters-per-unit not specified and this is >= 2.6 or higher, we can use
                    //CREATERUNTIMEMAP to get this value
                    if (options.MetersPerUnit == default(double))
                    {
                        if (conn.SiteVersion >= new Version(2, 6))
                        {
                            Console.WriteLine("Using CREATERUNTIMEMAP to obtain required meters-per-unit value");
                            var createRt = (ICreateRuntimeMap)conn.CreateCommand((int)CommandType.CreateRuntimeMap);
                            createRt.MapDefinition     = options.ResourceID;
                            createRt.RequestedFeatures = (int)RuntimeMapRequestedFeatures.None;
                            var rtMapInfo = createRt.Execute();
                            options.MetersPerUnit = rtMapInfo.CoordinateSystem.MetersPerUnit;
                            Console.WriteLine($"Using meters-per-unit value of: {options.MetersPerUnit}");
                        }
                    }
                    break;

                case ITileSetDefinition tsd:
                    walkOptions = new DefaultTileWalkOptions(tsd, options.Groups.ToArray());

                    //Wrong options. Fortunately we have enough information here to tell them what the *correct*
                    //arguments are
                    if (tsd.TileStoreParameters.TileProvider == "XYZ")
                    {
                        var bbox = tsd.Extents;
                        var urls = new List <string>();
                        foreach (var grp in tsd.BaseMapLayerGroups)
                        {
                            urls.Add(options.MapAgentUri + "?OPERATION=GETTILEIMAGE&VERSION=1.2.0&USERNAME=Anonymous&MAPDEFINITION=" + tsd.ResourceID + "&BASEMAPLAYERGROUPNAME=" + grp.Name + "&TILECOL={y}&TILEROW={x}&SCALEINDEX={z}");
                        }

                        Console.WriteLine("[ERROR]: Cannot use mapguide tiling mode for seeding XYZ tile sets. Use xyz tiling mode instead. Example(s):");
                        foreach (var url in urls)
                        {
                            Console.WriteLine($"  MgTileSeeder xyz --url \"{url}\" --minx {bbox.MinX} --miny {bbox.MinY} --maxx {bbox.MaxX} --maxy {bbox.MaxY}");
                        }
                        if (options.Wait)
                        {
                            Console.WriteLine("Press any key to continue");
                            Console.Read();
                        }
                        return(1);
                    }

                    //If meters-per-unit not specified and the tile set is using the "Default" provider, we can create
                    //a Map Definition linked to the tile set, save it to a temp resource and call CREATERUNTIMEMAP
                    //from it to obtain the reuqired meters-per-unit value
                    if (options.MetersPerUnit == default(double) && tsd.TileStoreParameters.TileProvider == "Default")
                    {
                        IMapDefinition3 mdf3  = (IMapDefinition3)ObjectFactory.CreateMapDefinition(new Version(3, 0, 0), "LinkedTileSet");
                        string          tmpId = $"Session:{conn.SessionID}//{mdf3.Name}.MapDefinition";
                        var             text  = tsd.Extents;
                        mdf3.SetExtents(text.MinX, text.MinY, text.MaxX, text.MaxY);
                        mdf3.CoordinateSystem    = tsd.GetDefaultCoordinateSystem();
                        mdf3.TileSetDefinitionID = tsd.ResourceID;
                        conn.ResourceService.SaveResourceAs(mdf3, tmpId);

                        Console.WriteLine("Using CREATERUNTIMEMAP to obtain required meters-per-unit value");
                        var createRt = (ICreateRuntimeMap)conn.CreateCommand((int)CommandType.CreateRuntimeMap);
                        createRt.MapDefinition     = tmpId;
                        createRt.RequestedFeatures = (int)RuntimeMapRequestedFeatures.None;
                        var rtMapInfo = createRt.Execute();
                        options.MetersPerUnit = rtMapInfo.CoordinateSystem.MetersPerUnit;
                        Console.WriteLine($"Using meters-per-unit value of: {options.MetersPerUnit}");
                    }
                    break;

                default:
                    throw new ArgumentException("Invalid resource type");
                }

                walkOptions.MetersPerUnit = options.MetersPerUnit;
                var walker = new DefaultTileWalker(walkOptions);

                var seederOptions = new TileSeederOptions();
                seederOptions.MaxDegreeOfParallelism = options.MaxDegreeOfParallelism;
                seederOptions.ErrorLogger            = ErrorLogger;
                var seeder = new TileSeeder(tileSvc, walker, seederOptions);

                var progress = new ConsoleProgress();
                var stats    = seeder.Run(progress);

                Console.WriteLine($"Rendered {stats.TilesRendered} tiles in {stats.Duration}");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                ret = 1;
            }
            finally
            {
                if (options.Wait)
                {
                    Console.WriteLine("Press any key to continue");
                    Console.Read();
                }
            }
            return(ret);
        }