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 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(); }