public void Preview(IResource res, IEditorService edSvc, string locale) { IMapDefinition mapDef = null; var conn = edSvc.CurrentConnection; if (res.ResourceType == ResourceTypes.LayerDefinition.ToString()) { var ldf = (ILayerDefinition)res; string wkt; var env = ldf.GetSpatialExtent(conn, true, out wkt); if (env == null) { throw new ApplicationException(Strings.CouldNotComputeExtentsForPreview); } mapDef = Utility.CreateMapDefinition(conn, "Preview"); mapDef.CoordinateSystem = wkt; mapDef.SetExtents(env.MinX, env.MinY, env.MaxX, env.MaxY); string resId = "Session:" + edSvc.SessionID + "//" + Guid.NewGuid() + "." + res.ResourceType.ToString(); conn.ResourceService.SetResourceXmlData(resId, ObjectFactory.Serialize(res)); mapDef.AddLayer(null, "PreviewLayer", resId); } else if (res.ResourceType == ResourceTypes.MapDefinition.ToString()) { mapDef = (IMapDefinition)res; } else if (res.ResourceType == ResourceTypes.WatermarkDefinition.ToString()) { string resId = "Session:" + edSvc.SessionID + "//" + Guid.NewGuid() + "." + res.ResourceType.ToString(); conn.ResourceService.SetResourceXmlData(resId, ObjectFactory.Serialize(res)); var csFact = new MgCoordinateSystemFactory(); var arbXY = csFact.ConvertCoordinateSystemCodeToWkt("XY-M"); mapDef = ObjectFactory.CreateMapDefinition(new Version(2, 3, 0), "Preview"); mapDef.CoordinateSystem = arbXY; mapDef.SetExtents(-100000, -100000, 100000, 100000); var wm = ((IMapDefinition2)mapDef).AddWatermark(((IWatermarkDefinition)res)); wm.ResourceId = resId; } var mapResId = new MgResourceIdentifier("Session:" + edSvc.SessionID + "//" + mapDef.ResourceType.ToString() + "Preview" + Guid.NewGuid() + "." + mapDef.ResourceType.ToString()); conn.ResourceService.SetResourceXmlData(mapResId.ToString(), ObjectFactory.Serialize(mapDef)); //MgdMap map = new MgdMap(mapResId); //var diag = new MapPreviewWindow(map, conn); //diag.ShowDialog(); var diag = new UI.MapPreviewWindow(conn); diag.Init(mapResId); diag.ShowDialog(); }
public override string ConvertCoordinateSystemCodeToWkt(string coordcode) => m_cf.ConvertCoordinateSystemCodeToWkt(coordcode);
public override void Execute(IPlatformFactory factory, ITestLogger logger) { //For a map definition that links to a default provider tile set and both have the same coordinate //system, it should be using the map definition's extents and we should not have null extents or view //center MgCoordinateSystemFactory csFactory = new MgCoordinateSystemFactory(); string csWkt = csFactory.ConvertCoordinateSystemCodeToWkt("LL84"); MgResourceService resSvc = (MgResourceService)factory.CreateService(MgServiceType.ResourceService); var root = "../../TestData/TileService/"; LoadResource(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", root + "UT_RoadCenterLines.fs"); LoadResourceData(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", "UT_RoadCenterLines.sdf", MgResourceDataType.File, root + "UT_RoadCenterLines.sdf"); LoadResource(resSvc, "Library://UnitTests/Layers/RoadCenterLines.LayerDefinition", root + "UT_RoadCenterLines.ldf"); LoadResource(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", root + "UT_VotingDistricts.fs"); LoadResourceData(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", "UT_VotingDistricts.sdf", MgResourceDataType.File, root + "UT_VotingDistricts.sdf"); LoadResource(resSvc, "Library://UnitTests/Layers/VotingDistricts.LayerDefinition", root + "UT_VotingDistricts.ldf"); LoadResource(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", root + "UT_Parcels.fs"); LoadResourceData(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", "UT_Parcels.sdf", MgResourceDataType.File, root + "UT_Parcels.sdf"); LoadResource(resSvc, "Library://UnitTests/Layers/Parcels.LayerDefinition", root + "UT_Parcels.ldf"); string tsd = Encoding.UTF8.GetString(Properties.Resources.UT_BaseMapTileSet); tsd = string.Format(tsd, csWkt, -87.5, 43.5, -86.5, 44.5); byte[] tsdBytes = Encoding.UTF8.GetBytes(tsd); MgByteSource sourceTSD = new MgByteSource(tsdBytes, tsdBytes.Length); MgByteReader contentTSD = sourceTSD.GetReader(); MgResourceIdentifier resTSD = new MgResourceIdentifier("Library://UnitTests/TileSets/Test.TileSetDefinition"); resSvc.SetResource(resTSD, contentTSD, null); string mdf = Encoding.UTF8.GetString(Properties.Resources.UT_LinkedTileSet); mdf = string.Format(mdf, csWkt, -87.0, 43.0, -86.0, 44.0, resTSD.ToString()); byte[] mdfBytes = Encoding.UTF8.GetBytes(mdf); MgByteSource sourceMDF = new MgByteSource(mdfBytes, mdfBytes.Length); MgByteReader contentMDF = sourceMDF.GetReader(); MgResourceIdentifier resMDF = new MgResourceIdentifier("Library://UnitTests/Maps/LinkedTileSet.MapDefinition"); resSvc.SetResource(resMDF, contentMDF, null); MgMapBase map = factory.CreateMap(resMDF); MgEnvelope extent = map.GetMapExtent(); Assert.IsNotNull(extent); Assert.IsNotNull(map.MapExtent); MgPoint center = map.GetViewCenter(); Assert.IsNotNull(center); Assert.IsNotNull(map.ViewCenter); MgCoordinate ll = extent.GetLowerLeftCoordinate(); MgCoordinate ur = extent.GetUpperRightCoordinate(); Assert.IsNotNull(ll); Assert.IsNotNull(ur); Assert.AreEqual(-87.0, ll.X); Assert.AreEqual(43.0, ll.Y); Assert.AreEqual(-86.0, ur.X); Assert.AreEqual(44.0, ur.Y); }
public void Preview(IResource res, IEditorService edSvc, string locale) { IMapDefinition mapDef = null; var conn = res.CurrentConnection; if (res.ResourceType == ResourceTypes.LayerDefinition) { var ldf = (ILayerDefinition)res; string wkt; var env = ldf.GetSpatialExtent(true, out wkt); if (env == null) throw new ApplicationException(Strings.CouldNotComputeExtentsForPreview); mapDef = ObjectFactory.CreateMapDefinition(conn, "Preview"); mapDef.CoordinateSystem = wkt; mapDef.SetExtents(env.MinX, env.MinY, env.MaxX, env.MaxY); string resId = "Session:" + edSvc.SessionID + "//" + Guid.NewGuid() + "." + res.ResourceType.ToString(); edSvc.ResourceService.SetResourceXmlData(resId, ResourceTypeRegistry.Serialize(res)); mapDef.AddLayer(null, "PreviewLayer", resId); } else if (res.ResourceType == ResourceTypes.MapDefinition) { mapDef = (IMapDefinition)res; } else if (res.ResourceType == ResourceTypes.WatermarkDefinition) { string resId = "Session:" + edSvc.SessionID + "//" + Guid.NewGuid() + "." + res.ResourceType.ToString(); edSvc.ResourceService.SetResourceXmlData(resId, ResourceTypeRegistry.Serialize(res)); var csFact = new MgCoordinateSystemFactory(); var arbXY = csFact.ConvertCoordinateSystemCodeToWkt("XY-M"); mapDef = ObjectFactory.CreateMapDefinition(conn, new Version(2, 3, 0), "Preview"); mapDef.CoordinateSystem = arbXY; mapDef.SetExtents(-100000, -100000, 100000, 100000); var wm = ((IMapDefinition2)mapDef).AddWatermark(((IWatermarkDefinition)res)); wm.ResourceId = resId; } var mapResId = new MgResourceIdentifier("Session:" + edSvc.SessionID + "//" + mapDef.ResourceType.ToString() + "Preview" + Guid.NewGuid() + "." + mapDef.ResourceType.ToString()); edSvc.ResourceService.SetResourceXmlData(mapResId.ToString(), ResourceTypeRegistry.Serialize(mapDef)); //MgdMap map = new MgdMap(mapResId); //var diag = new MapPreviewWindow(map, conn); //diag.ShowDialog(); var diag = new UI.MapPreviewWindow(conn); diag.Init(mapResId); diag.ShowDialog(); }