/// <summary> /// Merges the given newProperties with this one. /// </summary> /// <param name="newProperties"></param> /// <returns></returns> internal MapCSSRuleProperties Merge(MapCSSRuleProperties newProperties) { // determine the tightest zoom. int minZoom = this.MinZoom; int maxZoom = this.MaxZoom; if (this.MinZoom < newProperties.MinZoom) { minZoom = newProperties.MinZoom; } if (this.MaxZoom > newProperties.MaxZoom) { maxZoom = newProperties.MaxZoom; } // create a new rule and merge properties from both. var rule = new MapCSSRuleProperties(minZoom, maxZoom); foreach (var key in this.GetKeys()) { object value; this.TryGetProperty(key, out value); rule.AddProperty(key, value); } foreach (var key in newProperties.GetKeys()) { object value; newProperties.TryGetProperty(key, out value); rule.AddProperty(key, value); } return(rule); }
/// <summary> /// Returns the ranged properties. /// </summary> /// <returns></returns> public List <MapCSSRuleProperties> GetRanges() { var rules = new List <MapCSSRuleProperties>(); MapCSSRuleProperties currentRule = null; string previousRuleString = string.Empty; int minZoom = 0, maxZoom = 20; for (int zoomLevel = 0; zoomLevel < 20; zoomLevel++) { // get the current rule string. string currentRuleString = this.GetRuleStringForZoom(zoomLevel); if (previousRuleString != currentRuleString) { // there is a new rule. // store the previous rule. if (currentRule != null) { // the current rule exists; store it. currentRule.MinZoom = minZoom; currentRule.MaxZoom = maxZoom + 1; rules.Add(currentRule); currentRule = null; } if (!string.IsNullOrWhiteSpace(currentRuleString)) { // only do this part when string is not empty. minZoom = zoomLevel; // set the min zoom. MapCSSRuleProperties props = this.GetRulesForZoom(zoomLevel); if (props != null) { currentRule = new MapCSSRuleProperties(minZoom, 20); currentRule = currentRule.Merge(props); } } previousRuleString = currentRuleString; } maxZoom = zoomLevel; // set the max zoom. } // store the previous rule. if (currentRule != null) { // the current rule exists; store it. currentRule.MinZoom = minZoom; currentRule.MaxZoom = maxZoom + 1; rules.Add(currentRule); } return(rules); }
/// <summary> /// Returns the rules for the given zoom. /// </summary> /// <param name="zoom"></param> /// <returns></returns> public MapCSSRuleProperties GetRulesForZoom(int zoom) { MapCSSRuleProperties rule = null; for (int idx = 0; idx < _properties.Count; idx++) { if (_properties[idx].IsForZoom(zoom)) { if (rule == null) { rule = new MapCSSRuleProperties(_properties[idx].MinZoom, _properties[idx].MaxZoom); rule = rule.Merge(_properties[idx]); } else { rule = rule.Merge(_properties[idx]); } } } return(rule); }
/// <summary> /// Adds the given properties to the ones already here. /// </summary> /// <param name="properties"></param> public void AddProperties(MapCSSRuleProperties properties) { _properties.Add(properties); }
/// <summary> /// Returns true if the min/max zoom are equal. /// </summary> /// <param name="properties"></param> /// <returns></returns> public bool IsEqualForZoom(MapCSSRuleProperties properties) { return(this.IsEqualForZoom( properties.MinZoom, properties.MaxZoom)); }