예제 #1
0
    private List <CommonLayer> GetLegendLayers()
    {
        StringCollection visibleLayers = null;

        if (_pixelSize > 0 && _appState.VisibleLayers.ContainsKey(_appState.MapTab))
        {
            visibleLayers = _appState.VisibleLayers[_appState.MapTab];
        }

        Configuration config = AppContext.GetConfiguration();

        Configuration.MapTabRow mapTab    = config.MapTab.FindByMapTabID(_appState.MapTab);
        CommonDataFrame         dataFrame = AppContext.GetDataFrame(mapTab);

        List <CommonLayer> layerList      = new List <CommonLayer>();
        List <String>      mapTabLayerIds = new List <String>();

        foreach (Configuration.MapTabLayerRow mapTabLayer in mapTab.GetMapTabLayerRows())
        {
            Configuration.LayerRow layer = mapTabLayer.LayerRow;
            mapTabLayerIds.Add(layer.LayerID);

            CommonLayer commonLayer = dataFrame.Layers.FirstOrDefault(lyr => String.Compare(lyr.Name, layer.LayerName, true) == 0);

            if (commonLayer.Type == CommonLayerType.Feature && !layerList.Contains(commonLayer))
            {
                bool hasClasses         = GetNumClasses(commonLayer) > 0;
                bool visibleAtScale     = _pixelSize <= 0 || commonLayer.IsWithinScaleThresholds(_pixelSize);
                bool shownInLegend      = !mapTabLayer.IsShowInLegendNull() && mapTabLayer.ShowInLegend == 1;
                bool checkedInLegend    = mapTabLayer.IsCheckInLegendNull() || mapTabLayer.CheckInLegend < 0 || visibleLayers == null || visibleLayers.Contains(layer.LayerID);
                bool shownInPrintLegend = !(!mapTabLayer.IsShowInPrintLegendNull() && mapTabLayer.ShowInPrintLegend == 0);

                if (hasClasses && visibleAtScale && shownInLegend && checkedInLegend && shownInPrintLegend)
                {
                    layerList.Add(commonLayer);

                    while (commonLayer.Parent != null)
                    {
                        commonLayer = commonLayer.Parent;

                        if (!layerList.Contains(commonLayer))
                        {
                            layerList.Add(commonLayer);
                        }
                    }
                }
            }
        }

        if (!mapTab.IsBaseMapIDNull() && !mapTab.IsShowBaseMapInLegendNull() && mapTab.ShowBaseMapInLegend == 1)
        {
            foreach (Configuration.LayerRow layer in config.Layer.Where(o => !o.IsBaseMapIDNull() && o.BaseMapID == mapTab.BaseMapID))
            {
                if (!mapTabLayerIds.Contains(layer.LayerID))
                {
                    CommonLayer commonLayer = dataFrame.Layers.FirstOrDefault(o => String.Compare(o.Name, layer.LayerName, true) == 0);

                    if (commonLayer.Type == CommonLayerType.Feature && !layerList.Contains(commonLayer))
                    {
                        bool hasClasses     = GetNumClasses(commonLayer) > 0;
                        bool visibleAtScale = _pixelSize <= 0 || commonLayer.IsWithinScaleThresholds(_pixelSize);

                        if (hasClasses && visibleAtScale)
                        {
                            layerList.Add(commonLayer);

                            while (commonLayer.Parent != null)
                            {
                                commonLayer = commonLayer.Parent;

                                if (!layerList.Contains(commonLayer))
                                {
                                    layerList.Add(commonLayer);
                                }
                            }
                        }
                    }
                }
            }
        }

        return(layerList);
    }
예제 #2
0
    public void Initialize(Configuration config, AppState appState, Configuration.ApplicationRow application)
    {
        foreach (Configuration.ApplicationMapTabRow appMapTabRow in application.GetApplicationMapTabRows())
        {
            Configuration.MapTabRow mapTabRow = appMapTabRow.MapTabRow;
            CommonDataFrame         dataFrame = AppContext.GetDataFrame(mapTabRow);

            bool      isInteractive = !mapTabRow.IsInteractiveLegendNull() && mapTabRow.InteractiveLegend == 1;
            CheckMode checkMode     = CheckMode.None;

            List <CommonLayer>     configuredLayers = new List <CommonLayer>();
            List <LayerProperties> layerProperties  = new List <LayerProperties>();
            List <String>          mapTabLayerIds   = new List <String>();

            string name        = null;
            string metaDataUrl = null;

            StringCollection visibleLayers = isInteractive ? appState.VisibleLayers[mapTabRow.MapTabID] : null;

            // find layers attached via MapTabLayer

            foreach (Configuration.MapTabLayerRow mapTabLayerRow in mapTabRow.GetMapTabLayerRows())
            {
                if (!mapTabLayerRow.IsShowInLegendNull() && mapTabLayerRow.ShowInLegend == 1)
                {
                    CommonLayer layer = dataFrame.Layers.FirstOrDefault(lyr => String.Compare(lyr.Name, mapTabLayerRow.LayerRow.LayerName, true) == 0);

                    name        = mapTabLayerRow.LayerRow.IsDisplayNameNull() ? mapTabLayerRow.LayerRow.LayerName : mapTabLayerRow.LayerRow.DisplayName;
                    metaDataUrl = mapTabLayerRow.LayerRow.IsMetaDataURLNull() ? null : mapTabLayerRow.LayerRow.MetaDataURL;
                    bool isExclusive = mapTabLayerRow.IsIsExclusiveNull() ? false : mapTabLayerRow.IsExclusive == 1;

                    string tag = mapTabLayerRow.LayerID;
                    mapTabLayerIds.Add(tag);

                    if (isInteractive)
                    {
                        bool layerVisible = visibleLayers != null && visibleLayers.Contains(mapTabLayerRow.LayerID);
                        checkMode = mapTabLayerRow.IsCheckInLegendNull() || mapTabLayerRow.CheckInLegend < 0 ? CheckMode.Empty :
                                    layerVisible ? CheckMode.Checked : CheckMode.Unchecked;
                    }

                    configuredLayers.Add(layer);
                    layerProperties.Add(new LayerProperties(name, tag, checkMode, isExclusive, metaDataUrl));
                }
            }

            // find layers attached via BaseMapID

            if (!mapTabRow.IsBaseMapIDNull() && !mapTabRow.IsShowBaseMapInLegendNull() && mapTabRow.ShowBaseMapInLegend == 1)
            {
                if (checkMode != CheckMode.None)
                {
                    checkMode = CheckMode.Empty;
                }

                foreach (DataRow row in config.Layer.Select("BaseMapID = '" + mapTabRow.BaseMapID + "'"))
                {
                    Configuration.LayerRow layerRow = (Configuration.LayerRow)row;

                    if (!mapTabLayerIds.Contains(layerRow.LayerID))
                    {
                        CommonLayer layer = dataFrame.Layers.FirstOrDefault(lyr => String.Compare(lyr.Name, layerRow.LayerName, true) == 0);
                        metaDataUrl = layerRow.IsMetaDataURLNull() ? null : layerRow.MetaDataURL;

                        configuredLayers.Add(layer);
                        layerProperties.Add(new LayerProperties(layerRow.Name, null, checkMode, false, metaDataUrl));
                    }
                }
            }

            // add group layers as necessary

            for (int i = 0; i < configuredLayers.Count; ++i)
            {
                checkMode = !isInteractive ? CheckMode.None : layerProperties[i].CheckMode == CheckMode.Checked ? CheckMode.Checked : CheckMode.Unchecked;
                CommonLayer parent = configuredLayers[i].Parent;

                while (parent != null)
                {
                    int index = configuredLayers.IndexOf(parent);

                    if (index < 0)
                    {
                        configuredLayers.Add(parent);
                        layerProperties.Add(new LayerProperties(parent.Name, null, checkMode, false, null));
                    }
                    else
                    {
                        if (checkMode == CheckMode.Checked && layerProperties[index].CheckMode == CheckMode.Unchecked)
                        {
                            layerProperties[index].CheckMode = CheckMode.Checked;
                        }
                    }

                    parent = parent.Parent;
                }
            }

            // create the top level legend control for this map tab

            HtmlGenericControl parentLegend = new HtmlGenericControl("div");
            pnlLegendScroll.Controls.Add(parentLegend);
            parentLegend.Attributes["data-maptab"] = appMapTabRow.MapTabID;
            parentLegend.Attributes["class"]       = "LegendTop";
            parentLegend.Style["display"]          = appMapTabRow.MapTabID == appState.MapTab ? "block" : "none";

            // add the Legend controls for the configured layers

            foreach (CommonLayer layer in dataFrame.TopLevelLayers)
            {
                AddLayerToLegend(mapTabRow.MapTabID, configuredLayers, layerProperties, parentLegend, layer);
            }
        }
    }