Ejemplo n.º 1
0
 private static void SetupMapDefinitionForTest(IMapDefinition mdf)
 {
     mdf.AddGroup("Group1");
     mdf.AddLayer("Group1", "Parcels", "Library://UnitTests/Layers/Parcels.LayerDefinition");
     mdf.AddLayer("Group1", "Rail", "Library://UnitTests/Layers/Rail.LayerDefinition");
     mdf.AddGroup("Group2");
 }
Ejemplo n.º 2
0
        public void TestMapDefinitionNestedGroupDelete()
        {
            var conn = new Mock <IServerConnection>();
            var caps = new Mock <IConnectionCapabilities>();

            foreach (var rt in Enum.GetValues(typeof(ResourceTypes)))
            {
                caps.Setup(c => c.GetMaxSupportedResourceVersion(rt.ToString())).Returns(new Version(1, 0, 0));
            }
            conn.Setup(c => c.Capabilities).Returns(caps.Object);
            IMapDefinition mdf = Utility.CreateMapDefinition(conn.Object, "Test");

            /*
             *
             * [G] Group1
             *  [L] Layer1
             *  [G] Group2
             *     [L] Layer2
             *     [G] Group3
             *        [L] Layer3
             * [G] Group4
             *  [L] Layer4
             *
             */
            var grp1 = mdf.AddGroup("Group1");
            var grp2 = mdf.AddGroup("Group2");
            var grp3 = mdf.AddGroup("Group3");
            var grp4 = mdf.AddGroup("Group4");

            grp3.Group = "Group2";
            grp2.Group = "Group1";

            var lyr1 = mdf.AddLayer("Group1", "Layer1", "Library://Test.LayerDefinition");
            var lyr2 = mdf.AddLayer("Group2", "Layer2", "Library://Test.LayerDefinition");
            var lyr3 = mdf.AddLayer("Group3", "Layer3", "Library://Test.LayerDefinition");
            var lyr4 = mdf.AddLayer("Group4", "Layer4", "Library://Test.LayerDefinition");

            //Delete group 1. Expect the following structure

            /*
             * [G] Group4
             *  [L] Layer4
             */

            mdf.RemoveLayerGroupAndChildLayers("Group1");
            Assert.Equal(1, mdf.GetGroupCount());
            Assert.Equal(1, mdf.GetDynamicLayerCount());
            Assert.Null(mdf.GetLayerByName("Layer1"));
            Assert.Null(mdf.GetLayerByName("Layer2"));
            Assert.Null(mdf.GetLayerByName("Layer3"));
            Assert.NotNull(mdf.GetLayerByName("Layer4"));
            Assert.Null(mdf.GetGroupByName("Group1"));
            Assert.Null(mdf.GetGroupByName("Group2"));
            Assert.Null(mdf.GetGroupByName("Group3"));
            Assert.NotNull(mdf.GetGroupByName("Group4"));
        }
        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();
        }
Ejemplo n.º 4
0
        private static void SetTempLayer(IMapDefinition mdf, string resourceId)
        {
            var layers = new List <IMapLayer>(mdf.MapLayer);

            for (int i = 0; i < layers.Count; i++)
            {
                mdf.RemoveLayer(layers[i]);
            }

            var layer = mdf.AddLayer(null, "x", resourceId); //NOXLATE

            layer.Visible     = true;
            layer.Selectable  = true;
            layer.Name        = "x"; //NOXLATE
            layer.LegendLabel = string.Empty;
        }
Ejemplo n.º 5
0
        private void ProfileLayerDefinition(ILayerDefinition ldef)
        {
            //TODO: This was a line-by-line port from 2.x to match the 3.x APIs
            //we should find time to clean this up and ensure the profiling numbers are
            //truly reflective of actual performance metrics
            if (backgroundWorker.CancellationPending)
            {
                return;
            }

            string resourceId = ldef == m_item ? m_resourceId : ldef.ResourceID;

            MakeTempMap();

            backgroundWorker.ReportProgress(0, (string.Format(Strings.Prof_LogMessageLayerDefinition, resourceId)));
            using (new Timer(Strings.Prof_LogMessageRuntimeLayer, backgroundWorker))
            {
                try
                {
                    IMapDefinition mdef = Utility.CreateMapDefinition(m_connection, string.Empty);
                    //We cannot flub this anymore. AIMS 2012 demands the Map Definition id specified checks out
                    mdef.ResourceID = "Session:" + m_connection.SessionID + "//ProfileTest.MapDefinition"; //NOXLATE
                    m_connection.ResourceService.SaveResource(mdef);
                    IMapLayer layer = mdef.AddLayer(null, "Test Layer", ldef.ResourceID);                  //NOXLATE
                    layer.Visible    = false;
                    layer.Selectable = false;

                    if (backgroundWorker.CancellationPending)
                    {
                        return;
                    }

                    var mpsvc = (IMappingService)m_connection.GetService((int)ServiceType.Mapping);

                    var map = mpsvc.CreateMap(mdef);
                    using (new Timer(Strings.Prof_LogMessageIdentifyFetching, backgroundWorker))
                    {
                        var rtl = map.Layers["Test Layer"]; //NOXLATE
                        rtl.Visible    = true;
                        rtl.Selectable = true;
                    }

                    map.Save();
                }
                catch (Exception ex)
                {
                    //string msg = NestedExceptionMessageProcessor.GetFullMessage(ex);
                    backgroundWorker.ReportProgress(0, (string.Format(Strings.Prof_LayerDefinitionProfilingError, resourceId, ex.ToString(), Environment.NewLine)));
                }
            }

            if (backgroundWorker.CancellationPending)
            {
                return;
            }

            ILayerDefinition lx = (ILayerDefinition)ldef.Clone();

            if (lx.SubLayer.LayerType == LayerType.Vector || lx.SubLayer.LayerType == LayerType.Raster)
            {
                using (new Timer(Strings.Prof_LogMessageRenderingScales, backgroundWorker))
                {
                    if (lx.SubLayer.LayerType == LayerType.Vector)
                    {
                        IVectorLayerDefinition vlx = lx.SubLayer as IVectorLayerDefinition;
                        //VectorScaleRangeTypeCollection ranges = vlx.VectorScaleRange;
                        List <IVectorScaleRange> ranges = new List <IVectorScaleRange>(vlx.VectorScaleRange);
                        foreach (var vsr in ranges)
                        {
                            if (backgroundWorker.CancellationPending)
                            {
                                return;
                            }

                            string tmp1 = new ResourceIdentifier(Guid.NewGuid().ToString(), ResourceTypes.LayerDefinition, m_connection.SessionID);

                            try
                            {
                                double minscale = vsr.MinScale.HasValue ? vsr.MinScale.Value : 0;
                                double maxscale = vsr.MaxScale.HasValue ? vsr.MaxScale.Value : 10000000;

                                vlx.RemoveAllScaleRanges();
                                vsr.MinScale = null;
                                vsr.MaxScale = null;
                                vlx.AddVectorScaleRange(vsr);

                                m_connection.ResourceService.SaveResourceAs(lx, tmp1);

                                if (backgroundWorker.CancellationPending)
                                {
                                    return;
                                }

                                var lst = m_connection.FeatureService.GetSpatialContextInfo(vlx.ResourceId, false);

                                //Create a runtime map just containing this particular layer at this particular scale range
                                //We are profiling the stylization settings for this layer
                                var mdf = Utility.CreateMapDefinition(m_connection, "");
                                if (lst.SpatialContext != null && lst.SpatialContext.Count >= 1)
                                {
                                    mdf.CoordinateSystem = lst.SpatialContext[0].CoordinateSystemWkt;
                                    if (string.IsNullOrEmpty(m_tempmap.CoordinateSystem))
                                    {
                                        mdf.CoordinateSystem = @"LOCAL_CS[""*XY-M*"", LOCAL_DATUM[""*X-Y*"", 10000], UNIT[""Meter"", 1], AXIS[""X"", EAST], AXIS[""Y"", NORTH]]"; //NOXLATE
                                    }
                                    double llx = double.Parse(lst.SpatialContext[0].Extent.LowerLeftCoordinate.X, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
                                    double lly = double.Parse(lst.SpatialContext[0].Extent.LowerLeftCoordinate.Y, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
                                    double urx = double.Parse(lst.SpatialContext[0].Extent.UpperRightCoordinate.X, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);
                                    double ury = double.Parse(lst.SpatialContext[0].Extent.UpperRightCoordinate.Y, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture);

                                    m_tempmap.DataExtent = ObjectFactory.CreateEnvelope(llx, lly, urx, ury);
                                }

                                SetTempLayer(mdf, tmp1);

                                var mpsvc = (IMappingService)m_connection.GetService((int)ServiceType.Mapping);
                                //We cannot flub this anymore. AIMS 2012 demands the Map Definition id specified checks out
                                mdf.ResourceID = "Session:" + m_connection.SessionID + "//ProfileTest.MapDefinition"; //NOXLATE
                                m_connection.ResourceService.SaveResource(mdf);
                                var rtmap = mpsvc.CreateMap(mdf);

                                if (m_connection.ResourceService.ResourceExists(rtmap.ResourceID))
                                {
                                    m_connection.ResourceService.DeleteResource(rtmap.ResourceID);
                                }

                                rtmap.Save();

                                if (backgroundWorker.CancellationPending)
                                {
                                    return;
                                }

                                using (new Timer(string.Format(Strings.Prof_LogMessageScaleRange, minscale, maxscale), backgroundWorker))
                                {
                                    //TODO: Use extents rather than scale
                                    //using (System.IO.Stream s = m_connection.RenderRuntimeMap(tmp2, m.Extents, 1024, 800, 96))
                                    using (System.IO.Stream s = mpsvc.RenderRuntimeMap(rtmap, ((rtmap.DataExtent.MaxX - rtmap.DataExtent.MinX) / 2) + rtmap.DataExtent.MinX, ((rtmap.DataExtent.MaxY - rtmap.DataExtent.MinY) / 2) + rtmap.DataExtent.MinY, 50000, 1024, 800, 96))
                                    {
                                        backgroundWorker.ReportProgress(0, (string.Format(Strings.Prof_MapRenderingImageSize, s.Length)));
                                    }
                                }
                            }
                            finally
                            {
                                try { m_connection.ResourceService.DeleteResource(tmp1); }
                                catch { }
                            }
                        }
                    }
                }
            }

            if (backgroundWorker.CancellationPending)
            {
                return;
            }

            backgroundWorker.ReportProgress(0, ("\r\n")); //NOXLATE
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Updates and replaces the layer/group structure of the specified Map Definition with the
        /// layer/group structure of this Runtime Map
        /// </summary>
        /// <param name="newMdf"></param>
        public void UpdateMapDefinition(IMapDefinition newMdf)
        {
            newMdf.RemoveAllLayers();
            newMdf.RemoveAllGroups();
            newMdf.RemoveBaseMap();

            var baseGroups = new List<RuntimeMapGroup>();

            newMdf.CoordinateSystem = this.CoordinateSystem;
            newMdf.Extents = this.MapExtent;

            //Add dynamic groups
            for (int i = this.Groups.Count - 1; i >= 0; i--)
            {
                //Deal with base groups later
                if (this.Groups[i].Type == RuntimeMapGroup.kBaseMap)
                {
                    baseGroups.Add(this.Groups[i]);
                    continue;
                }

                var rtGroup = this.Groups[i];
                var newGroup = newMdf.AddGroup(rtGroup.Name);
                newGroup.Group = rtGroup.Group;
                newGroup.ExpandInLegend = rtGroup.ExpandInLegend;
                newGroup.LegendLabel = rtGroup.LegendLabel;
                newGroup.ShowInLegend = rtGroup.ShowInLegend;
                newGroup.Visible = rtGroup.Visible;
            }

            var baseLayers = new List<RuntimeMapLayer>();

            //Populate dynamic layers. Loop in reverse order so that they are added in correct draw order
            for (int i = this.Layers.Count - 1; i >= 0; i--)
            {
                //Deal with base layers later
                if (this.Layers[i].Type == RuntimeMapLayer.kBaseMap)
                {
                    baseLayers.Add(this.Layers[i]);
                    continue;
                }

                var rtLayer = this.Layers[i];
                var newLayer = newMdf.AddLayer(rtLayer.Group, rtLayer.Name, rtLayer.LayerDefinitionID);
                newLayer.ExpandInLegend = rtLayer.ExpandInLegend;
                newLayer.LegendLabel = rtLayer.LegendLabel;
                newLayer.Selectable = rtLayer.Selectable;
                newLayer.ShowInLegend = rtLayer.ShowInLegend;
                newLayer.Visible = rtLayer.Visible;
            }

            if (baseLayers.Count > 0 && baseGroups.Count > 0)
            {
                newMdf.InitBaseMap();

                //Add finite scales first
                for (int i = _finiteDisplayScales.Length - 1; i >= 0; i--)
                {
                    newMdf.BaseMap.AddFiniteDisplayScale(_finiteDisplayScales[i]);
                }

                var baseGroupsByName = new Dictionary<string, IBaseMapGroup>();

                //Now groups
                for (int i = baseGroups.Count - 1; i >= 0; i--)
                {
                    var rtGroup = baseGroups[i];
                    var newGroup = newMdf.BaseMap.AddBaseLayerGroup(rtGroup.Name);
                    newGroup.ExpandInLegend = rtGroup.ExpandInLegend;
                    newGroup.LegendLabel = rtGroup.LegendLabel;
                    newGroup.ShowInLegend = rtGroup.ShowInLegend;
                    newGroup.Visible = rtGroup.Visible;

                    baseGroupsByName.Add(newGroup.Name, newGroup);
                }

                //Then layers. Loop in reverse order so that they are added in correct draw order
                for (int i = baseLayers.Count - 1; i >= 0; i--)
                {
                    var rtLayer = baseLayers[i];
                    //Should always happen
                    if (baseGroupsByName.ContainsKey(rtLayer.Group))
                    {
                        var newLayer = baseGroupsByName[rtLayer.Group].AddLayer(rtLayer.Name, rtLayer.LayerDefinitionID);
                        newLayer.ExpandInLegend = rtLayer.ExpandInLegend;
                        newLayer.LegendLabel = rtLayer.LegendLabel;
                        newLayer.Selectable = rtLayer.Selectable;
                        newLayer.ShowInLegend = rtLayer.ShowInLegend;
                    }
                }
            }
        }
Ejemplo n.º 7
0
 private static void SetupMapDefinitionForTest(IMapDefinition mdf)
 {
     mdf.AddGroup("Group1");
     mdf.AddLayer("Group1", "Parcels", "Library://UnitTests/Layers/Parcels.LayerDefinition");
     mdf.AddLayer("Group1", "Rail", "Library://UnitTests/Layers/Rail.LayerDefinition");
     mdf.AddGroup("Group2");
 }
Ejemplo n.º 8
0
        private static void SetTempLayer(IMapDefinition mdf, string resourceId)
        {
            var layers = new List<IMapLayer>(mdf.MapLayer);
            for (int i = 0; i < layers.Count; i++)
            {
                mdf.RemoveLayer(layers[i]);
            }

            var layer = mdf.AddLayer(null, "x", resourceId); //NOXLATE
            layer.Visible = true;
            layer.Selectable = true;
            layer.Name = "x"; //NOXLATE
            layer.LegendLabel = string.Empty;
        }