コード例 #1
0
        public static List <TangramLayerGroup> ProcessLayers(Dictionary <string, string> replacedSources, IList <Layer> layers)
        {
            List <Layer> layerWithNoSourceList = layers.Where(item => item.Type == null && !IsLayerIgnored(item)).ToList();
            List <Layer> layerWithSourceList   = layers.Where(item => item.Type != null && !IsLayerIgnored(item)).ToList();

            List <Layer> reSourcedList = new List <Layer>();
            List <Layer> usedLayers    = new List <Layer>();

            List <TangramLayerGroup> tangramLayerGroups = new List <TangramLayerGroup>();

            ProcessLayers(replacedSources, layerWithNoSourceList, layerWithSourceList, reSourcedList, tangramLayerGroups, usedLayers);

            if (reSourcedList.Count > 0)
            {
                layerWithSourceList.Clear();
                layerWithSourceList.AddRange(reSourcedList);
                reSourcedList.Clear();
                ProcessLayers(replacedSources, layerWithNoSourceList, layerWithSourceList, reSourcedList, tangramLayerGroups, usedLayers);
            }

            foreach (Layer layer in usedLayers)
            {
                TangramLayer layerFound = null;

                foreach (var layerGroup in tangramLayerGroups)
                {
                    foreach (var layerGroupLayer in layerGroup)
                    {
                        if (layerGroupLayer.LayerWithSource == layer)
                        {
                            layerFound = layerGroupLayer;
                        }
                    }

                    if (layerFound != null)
                    {
                        layerGroup.Remove(layerFound);
                        break;
                    }
                }
            }

            foreach (var layerMissed in layerWithNoSourceList)
            {
                Converter.AppendDebug("missed layer", layerMissed.Id);
            }

            return(tangramLayerGroups);
        }
コード例 #2
0
        private static void ProcessLayers(Dictionary <string, string> replacedSources, List <Layer> layerWithNoSourceList, List <Layer> layerWithSourceList, List <Layer> reSourcedList, List <TangramLayerGroup> tangramLayerGroups, List <Layer> usedLayers)
        {
            foreach (var layerWithSource in layerWithSourceList)
            {
                bool isCasing = IsCasing(layerWithSource.Id);

                List <Layer> refLayers = null;
                if (layerWithSource.Ref == null)
                {
                    refLayers = layerWithNoSourceList.Where(item => item.Ref == layerWithSource.Id).ToList <Layer>();
                    if (refLayers != null)
                    {
                        foreach (Layer refLayer in refLayers)
                        {
                            layerWithNoSourceList.Remove(refLayer);
                            refLayer.Filter      = layerWithSource.Filter;
                            refLayer.Source      = layerWithSource.Source;
                            refLayer.SourceLayer = layerWithSource.SourceLayer;

                            if (refLayer.Layout != null)
                            {
                                refLayer.Layout.LineCap  = layerWithSource.Layout.LineCap;
                                refLayer.Layout.LineJoin = layerWithSource.Layout.LineJoin;
                            }
                            else
                            {
                                refLayer.Layout = layerWithSource.Layout;
                            }

                            reSourcedList.Add(refLayer);
                        }
                    }
                    //refLayers.Clear();
                }

                if (layerWithSource.Id.StartsWith("bridge") && (layerWithSource.Id.EndsWith(CaseSuffix) || layerWithSource.Id.EndsWith(CasingSuffix)))
                {
                    var realLayers = layerWithSourceList.Where(item => item.Id == NormaliseName(layerWithSource.Id)).ToList();
                    if (realLayers.Count > 0)
                    {
                        refLayers.Add(realLayers[0]);
                        usedLayers.Add(realLayers[0]);
                    }
                }

                // to join OpenMapTiles casing and regular road layers together as we need to specify width for lines with outlines
                if (layerWithSource.Id.EndsWith("_casing") && refLayers.Count == 0)
                {
                    var lineWidthLayers = layerWithSourceList.Where(item => item.Id == layerWithSource.Id.Replace("_casing", "")).ToList();
                    if (lineWidthLayers.Count == 1)
                    {
                        refLayers.Add(lineWidthLayers[0]);
                    }
                }

                TangramLayer tangramLayer = new TangramLayer(layerWithSource, refLayers);

                TangramLayerGroup tangramLayerGroup = tangramLayerGroups.FirstOrDefault(item => item.SourceLayer != null && item.SourceLayer.ToString() == layerWithSource.SourceLayer && item.IsCasing == isCasing);

                if (tangramLayerGroup == null)
                {
                    tangramLayerGroup = new TangramLayerGroup(replacedSources, layerWithSource.SourceLayer, isCasing);
                    tangramLayerGroups.Add(tangramLayerGroup);
                }

                tangramLayerGroup.Add(tangramLayer);
            }
        }