private void btnSetZoom_Click(object sender, EventArgs e)
        {
            string coordinateSystem = null;

            if (_tsd.TileStoreParameters.TileProvider == "Default") //NOXLATE
            {
                coordinateSystem = _tsd.GetDefaultCoordinateSystem();
            }
            else
            {
                coordinateSystem = _service.CurrentConnection.CoordinateSystemCatalog.FindCoordSys("WGS84.PseudoMercator").WKT; //NOXLATE
            }
            var diag = new ExtentCalculationDialog(_service.CurrentConnection, coordinateSystem, CollectLayerIds);

            if (diag.ShowDialog() == DialogResult.OK)
            {
                var env = diag.Extents;
                if (env != null)
                {
                    txtMinX.Text = env.MinX.ToString(CultureInfo.InvariantCulture);
                    txtMinY.Text = env.MinY.ToString(CultureInfo.InvariantCulture);
                    txtMaxX.Text = env.MaxX.ToString(CultureInfo.InvariantCulture);
                    txtMaxY.Text = env.MaxY.ToString(CultureInfo.InvariantCulture);
                    OnResourceChanged();
                }
                else
                {
                    MessageBox.Show(Strings.ErrorMapExtentCalculationFailed, Strings.TitleError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public void CreateTest()
        {
            var res = ObjectFactory.CreateTileSetDefinition(new Version(3, 0, 0));

            Assert.IsAssignableFrom <ITileSetDefinition>(res);
            ITileSetDefinition tsd = (ITileSetDefinition)res;

            Assert.Equal("Default", tsd.TileStoreParameters.TileProvider);
            tsd.SetXYZProviderParameters();
            Assert.Equal("XYZ", tsd.TileStoreParameters.TileProvider);
            var p = tsd.GetParameter("TileFormat");

            Assert.NotNull(p);
            Assert.Equal("PNG", p.Value);
            Assert.Equal("PNG", tsd.GetTileFormat());
            p = tsd.GetParameter("TilePath");
            Assert.NotNull(p);
            Assert.Equal("%MG_TILE_CACHE_PATH%", p.Value);
            Assert.Equal("%MG_TILE_CACHE_PATH%", tsd.GetTilePath());

            tsd.SetDefaultProviderParameters(256, 256, "coordsys", new double[] { 100.5, 200.5, 300.5 });
            p = tsd.GetParameter("TileWidth");
            Assert.NotNull(p);
            Assert.Equal("256", p.Value);
            Assert.Equal(256, tsd.GetDefaultTileWidth());
            p = tsd.GetParameter("TileHeight");
            Assert.NotNull(p);
            Assert.Equal("256", p.Value);
            Assert.Equal(256, tsd.GetDefaultTileHeight());
            p = tsd.GetParameter("CoordinateSystem");
            Assert.NotNull(p);
            Assert.Equal("coordsys", p.Value);
            Assert.Equal("coordsys", tsd.GetDefaultCoordinateSystem());
            p = tsd.GetParameter("FiniteScaleList");
            Assert.NotNull(p);
            Assert.Equal("300.5,200.5,100.5", p.Value);
            var value = tsd.GetDefaultFiniteScaleList();

            Assert.Equal(3, value.Length);
            Assert.Contains(100.5, value);
            Assert.Contains(200.5, value);
            Assert.Contains(300.5, value);
            p = tsd.GetParameter("TileFormat");
            Assert.NotNull(p);
            Assert.Equal("PNG", p.Value);
            Assert.Equal("PNG", tsd.GetTileFormat());
            p = tsd.GetParameter("TilePath");
            Assert.NotNull(p);
            Assert.Equal("%MG_TILE_CACHE_PATH%", p.Value);
            Assert.Equal("%MG_TILE_CACHE_PATH%", tsd.GetTilePath());
        }
        public void DeserializationTest()
        {
            var res = ObjectFactory.DeserializeXml(Properties.Resources.UT_BaseMap);

            Assert.IsInstanceOf <ITileSetDefinition>(res);
            ITileSetDefinition tsd = (ITileSetDefinition)res;

            Assert.AreEqual("%MG_TILE_CACHE_PATH%", tsd.GetTilePath());
            Assert.AreEqual(256, tsd.GetDefaultTileWidth());
            Assert.AreEqual(256, tsd.GetDefaultTileHeight());
            Assert.AreEqual("PNG", tsd.GetTileFormat());

            var values = tsd.GetDefaultFiniteScaleList();

            Assert.AreEqual(10, values.Length);
            Assert.Contains(200000, values);
            Assert.Contains(100000, values);
            Assert.Contains(50000, values);
            Assert.Contains(25000, values);
            Assert.Contains(12500, values);
            Assert.Contains(6250, values);
            Assert.Contains(3125, values);
            Assert.Contains(1562.5, values);
            Assert.Contains(781.25, values);
            Assert.Contains(390.625, values);
            Assert.False(String.IsNullOrEmpty(tsd.GetDefaultCoordinateSystem()));

            var ext = tsd.Extents;

            Assert.AreEqual(-87.79786601383196, ext.MinX);
            Assert.AreEqual(-87.66452777186925, ext.MaxX);
            Assert.AreEqual(43.6868578621819, ext.MinY);
            Assert.AreEqual(43.8037962206133, ext.MaxY);

            Assert.AreEqual(1, tsd.BaseMapLayerGroups.Count());
            var grp = tsd.BaseMapLayerGroups.First();

            Assert.AreEqual("BaseLayers", grp.Name);
            Assert.True(grp.Visible);
            Assert.True(grp.ShowInLegend);
            Assert.True(grp.ExpandInLegend);
            Assert.AreEqual("Base Layers", grp.LegendLabel);
            Assert.AreEqual(2, grp.BaseMapLayer.Count());
        }
Exemple #4
0
        private void TryCalcMpu(string mapDef)
        {
            BusyWaitDialog.Run(Strings.CalculatingMpu, () =>
            {
                var currentPath = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
                var mpuCalc     = Path.Combine(currentPath, "AddIns/Local/MpuCalc.exe"); //NOXLATE
                if (!File.Exists(mpuCalc) && mapDef.EndsWith(ResourceTypes.MapDefinition.ToString()))
                {
                    int[] cmdTypes = m_connection.Capabilities.SupportedCommands;
                    if (Array.IndexOf(cmdTypes, (int)OSGeo.MapGuide.MaestroAPI.Commands.CommandType.CreateRuntimeMap) < 0)
                    {
                        IMapDefinition mdf = (IMapDefinition)m_connection.ResourceService.GetResource(mapDef);
                        var calc           = m_connection.GetCalculator();
                        return(new MpuCalcResult()
                        {
                            Method = MpuMethod.BuiltIn,
                            Result = Convert.ToDecimal(calc.Calculate(mdf.CoordinateSystem, 1.0))
                        });
                    }
                    else
                    {
                        ICreateRuntimeMap create = (ICreateRuntimeMap)m_connection.CreateCommand((int)OSGeo.MapGuide.MaestroAPI.Commands.CommandType.CreateRuntimeMap);
                        create.MapDefinition     = mapDef;
                        create.RequestedFeatures = (int)RuntimeMapRequestedFeatures.None;
                        var info = create.Execute();
                        return(new MpuCalcResult()
                        {
                            Method = MpuMethod.CreateRuntimeMap,
                            Result = Convert.ToDecimal(info.CoordinateSystem.MetersPerUnit)
                        });
                    }
                }
                else
                {
                    IResource res          = m_connection.ResourceService.GetResource(mapDef);
                    ITileSetDefinition tsd = res as ITileSetDefinition;
                    IMapDefinition mdf     = res as IMapDefinition;

                    string coordSys = null;
                    if (mdf != null)
                    {
                        coordSys = mdf.CoordinateSystem;
                    }
                    else if (tsd != null)
                    {
                        coordSys = tsd.GetDefaultCoordinateSystem();
                    }

                    string output = string.Empty;
                    if (coordSys != null)
                    {
                        var proc = new Process
                        {
                            StartInfo = new ProcessStartInfo
                            {
                                FileName               = mpuCalc,
                                Arguments              = coordSys,
                                UseShellExecute        = false,
                                RedirectStandardOutput = true,
                                CreateNoWindow         = true
                            }
                        };
                        proc.Start();
                        StringBuilder sb = new StringBuilder();
                        while (!proc.StandardOutput.EndOfStream)
                        {
                            string line = proc.StandardOutput.ReadLine();
                            // do something with line
                            sb.AppendLine(line);
                        }
                        output = sb.ToString();
                    }
                    double mpu;
                    if (double.TryParse(output, out mpu))
                    {
                        return new MpuCalcResult()
                        {
                            Method = MpuMethod.MpuCalcExe, Result = Convert.ToDecimal(mpu)
                        }
                    }
                    ;
                    else
                    {
                        return(string.Format(Strings.FailedToCalculateMpu, output));
                    }
                }
            }, (res, ex) =>
            {
                if (ex != null)
                {
                    ErrorDialog.Show(ex);
                }
                else
                {
                    var mres = res as MpuCalcResult;
                    if (mres != null)
                    {
                        MetersPerUnit.Value = mres.Result;
                        if (mres.Method == MpuMethod.BuiltIn)
                        {
                            MessageBox.Show(Strings.ImperfectMpuCalculation);
                        }
                    }
                    else
                    {
                        MessageBox.Show(res.ToString());
                    }
                }
            });
        }