예제 #1
0
        private static Dictionary <string, Dictionary <string, CartoRule> > CollectSymbolizers(CartoDefinition def, ZoomStruct zooms, int i, Env env, ICartoTranslator cartoTranslator)
        {
            Dictionary <string, Dictionary <string, CartoRule> > symbolizers = new Dictionary <string, Dictionary <string, CartoRule> >();

            NodeList <CartoRule> rules = def.Rules;

            for (int j = i; j < rules.Count; j++)
            {
                CartoRule child   = rules[j];
                string    symName = cartoTranslator.GetSymbolizerName(child.Name);

                string key = child.Instance + "/" + symName;
                if ((zooms.Current & child.Zoom) != 0 &&
                    (!(symbolizers.ContainsKey(key)) || (symbolizers[key] != null && !(symbolizers[key].ContainsKey(child.Name)))))
                {
                    zooms.Current &= child.Zoom;
                    if (!(symbolizers.ContainsKey(key)))
                    {
                        symbolizers[key] = new Dictionary <string, CartoRule>();
                    }

                    symbolizers[key][child.Name] = child;
                }
            }

            if (symbolizers.Count > 0)
            {
                zooms.Rule &= (zooms.Available &= ~zooms.Current);

                return(symbolizers);
            }

            return(null);
        }
예제 #2
0
    private static Dictionary<string, Dictionary<string, CartoRule>> CollectSymbolizers(CartoDefinition def, ZoomStruct zooms, int i, Env env, ICartoTranslator cartoTranslator)
    {
      Dictionary<string, Dictionary<string, CartoRule>> symbolizers = new Dictionary<string, Dictionary<string, CartoRule>>();

      NodeList<CartoRule> rules = def.Rules;
      for (int j = i; j < rules.Count; j++)
      {
        CartoRule child = rules[j];
        string symName = cartoTranslator.GetSymbolizerName(child.Name);

        string key = child.Instance + "/" + symName;
        if ((zooms.Current & child.Zoom) != 0 &&
           (!(symbolizers.ContainsKey(key)) || (symbolizers[key] != null && !(symbolizers[key].ContainsKey(child.Name)))))
        {
          zooms.Current &= child.Zoom;
          if (!(symbolizers.ContainsKey(key)))
            symbolizers[key] = new Dictionary<string, CartoRule>();

          symbolizers[key][child.Name] = child;
        }
      }

      if (symbolizers.Count > 0)
      {
        zooms.Rule &= (zooms.Available &= ~zooms.Current);

        return symbolizers;
      }

      return null;
    }
예제 #3
0
        /// <summary>
        /// Creates rules
        /// </summary>
        /// <param name="style"></param>
        /// <param name="def"></param>
        /// <param name="env"></param>
        /// <param name="existingFilters"></param>
        /// <param name="cartoTranslator"></param>
        private static void CreateRules(FeatureTypeStyle style, CartoDefinition def, Env env, Dictionary <string, int> existingFilters, ICartoTranslator cartoTranslator)
        {
            string filter = def.Filters.ToString();

            if (!(existingFilters.ContainsKey(filter)))
            {
                existingFilters[filter] = 0x7FFFFF;
            }

            int        available = 0x7FFFFF;
            ZoomStruct zooms     = new ZoomStruct();

            zooms.Available = available;

            NodeList <CartoRule> rules = def.Rules;

            for (int i = 0; i < rules.Count; i++)
            {
                CartoRule cartoRule = rules[i];
                zooms.Rule = cartoRule.Zoom;

                if ((existingFilters[filter] & zooms.Rule) == 0)
                {
                    continue;
                }

                while (((zooms.Current = zooms.Rule) & available) != 0)
                {
                    Dictionary <string, Dictionary <string, CartoRule> > symbolizers = CollectSymbolizers(def, zooms, i, env, cartoTranslator);

                    if (symbolizers != null && symbolizers.Count > 0)
                    {
                        if ((existingFilters[filter] & zooms.Current) == 0)
                        {
                            continue;
                        }

                        int zoom = existingFilters[filter] & zooms.Current;
                        int startZoom = -1, endZoom = 0;
                        for (int zi = 0; zi <= 22; zi++)
                        {
                            if ((zoom & (1 << zi)) != 0)
                            {
                                if (startZoom == -1)
                                {
                                    startZoom = zi;
                                }
                                endZoom = zi;
                            }
                        }

                        Rule rule = new Rule();
                        rule.Filter = ConvertUtility.ToFilter(def.Filters, cartoTranslator);
                        rule.Name   = cartoRule.Instance;

                        if (startZoom > 0)
                        {
                            rule.MaxScale = ConvertUtility.ToScaleDenominator(startZoom);
                        }
                        if (endZoom > 0)
                        {
                            rule.MinScale = ConvertUtility.ToScaleDenominator(endZoom + 1);
                        }

                        CreateSymbolizers(rule, symbolizers, env, cartoTranslator);

                        existingFilters[filter] &= ~zooms.Current;

                        // Check whether the rule has at least one visible symbolizer
                        if (rule.Symbolizers.Count > 0 && rule.Symbolizers.Any(s => s.Enabled == true))
                        {
                            style.Rules.Add(rule);
                        }
                    }
                }
            }

            //style.Rules.Sort(new RuleComparer());
        }
예제 #4
0
    /// <summary>
    /// Creates rules
    /// </summary>
    /// <param name="style"></param>
    /// <param name="def"></param>
    /// <param name="env"></param>
    /// <param name="existingFilters"></param>
    /// <param name="cartoTranslator"></param>
    private static void CreateRules(FeatureTypeStyle style, CartoDefinition def, Env env, Dictionary<string, int> existingFilters, ICartoTranslator cartoTranslator)
    {
      string filter = def.Filters.ToString();

      if (!(existingFilters.ContainsKey(filter)))
        existingFilters[filter] = 0x7FFFFF;

      int available = 0x7FFFFF;
      ZoomStruct zooms = new ZoomStruct();
      zooms.Available = available;

      NodeList<CartoRule> rules = def.Rules;
      for (int i = 0; i < rules.Count; i++)
      {
        CartoRule cartoRule = rules[i];
        zooms.Rule = cartoRule.Zoom;

        if ((existingFilters[filter] & zooms.Rule) == 0)
          continue;

        while (((zooms.Current = zooms.Rule) & available) != 0)
        {
          Dictionary<string, Dictionary<string, CartoRule>> symbolizers = CollectSymbolizers(def, zooms, i, env, cartoTranslator);

          if (symbolizers != null && symbolizers.Count > 0)
          {
            if ((existingFilters[filter] & zooms.Current) == 0)
              continue;

            int zoom = existingFilters[filter] & zooms.Current;
            int startZoom = -1, endZoom = 0;
            for (int zi = 0; zi <= 22; zi++)
            {
              if ((zoom & (1 << zi)) != 0)
              {
                if (startZoom == -1)
                  startZoom = zi;
                endZoom = zi;
              }
            }

            Rule rule = new Rule();
            rule.Filter = ConvertUtility.ToFilter(def.Filters, cartoTranslator);
            rule.Name = cartoRule.Instance;

            if (startZoom > 0)
              rule.MaxScale = ConvertUtility.ToScaleDenominator(startZoom);
            if (endZoom > 0)
              rule.MinScale = ConvertUtility.ToScaleDenominator(endZoom + 1);

            CreateSymbolizers(rule, symbolizers, env, cartoTranslator);

            existingFilters[filter] &= ~zooms.Current;

            // Check whether the rule has at least one visible symbolizer
            if (rule.Symbolizers.Count > 0 && rule.Symbolizers.Any(s => s.Enabled == true))
              style.Rules.Add(rule);
          }
        }
      }

      //style.Rules.Sort(new RuleComparer());
    }