Пример #1
0
        /// <summary>
        /// AddWeight("administrative", "", 2.5).
        /// weight is casted into <see cref="GoogleMapStyleWeight"/> element
        /// </summary>
        /// <param name="featureType"></param>
        /// <param name="elementType"></param>
        /// <param name="weight">decimal value between 0 and 8 : sets the weight of the feature, in pixels.<br/>
        /// Setting the weight to a high value may result in clipping near tile borders.</param>
        public GoogleMapStyleBuilder AddWeight(string featureType, string elementType, double weight)
        {
            MapTypeStyle s = new MapTypeStyle();

            s.elementType = elementType;
            s.featureType = featureType;
            s.stylers     = new[] { (GoogleMapStyleWeight)weight };
            _styles.Add(s);

            return(this);
        }
Пример #2
0
        /// <summary>
        /// Use AddColor, AddVisibility, AddLightness, AddSaturation, or AddWeight. Else use custom explicit operator inheritance object
        /// </summary>
        /// <param name="featureType"></param>
        /// <param name="elementType"></param>
        /// <param name="element"></param>
        /// <returns></returns>
        public GoogleMapStyleBuilder AddStyle(string featureType, string elementType, GoogleMapStyleElement element)
        {
            MapTypeStyle s = new MapTypeStyle();

            s.elementType = elementType;
            s.featureType = featureType;
            s.stylers     = new[] { element };
            _styles.Add(s);

            return(this);
        }
Пример #3
0
        /// <summary>
        /// AddSaturation("administrative", "", -10).
        /// saturation is casted into <see cref="GoogleMapStyleSaturation"/> element
        /// </summary>
        /// <param name="featureType"></param>
        /// <param name="elementType"></param>
        /// <param name="saturation">integer value between -100 and +100 : indicates the percentage change in intensity of the basic color to apply to the element.<br/>
        /// E.g., -100 removes all intensity from the color of a feature, regardless of its starting color. The effect is to render the feature grayscale.</param>
        public GoogleMapStyleBuilder AddSaturation(string featureType, string elementType, int saturation)
        {
            MapTypeStyle s = new MapTypeStyle();

            s.elementType = elementType;
            s.featureType = featureType;
            s.stylers     = new[] { (GoogleMapStyleSaturation)saturation };
            _styles.Add(s);

            return(this);
        }
Пример #4
0
        /// <summary>
        /// AddLightness("administrative", "", 45).
        /// lightness is casted into <see cref="GoogleMapStyleLightness"/> element
        /// </summary>
        /// <param name="featureType"></param>
        /// <param name="elementType"></param>
        /// <param name="lightness">integer value between -100 and +100 : indicates the percentage change in brightness of the element.<br/>
        /// Negative values increase darkness (where -100 specifies black) while positive values increase brightness (where +100 specifies white).</param>
        public GoogleMapStyleBuilder AddLightness(string featureType, string elementType, int lightness)
        {
            MapTypeStyle s = new MapTypeStyle();

            s.elementType = elementType;
            s.featureType = featureType;
            s.stylers     = new[] { (GoogleMapStyleLightness)lightness };
            _styles.Add(s);

            return(this);
        }
Пример #5
0
        /// <summary>
        /// For example AddColor("", "geometry", (GoogleMapStyleColor)"#1d2c4d");
        /// Color is casted into <see cref="GoogleMapStyleColor"/>  element
        /// </summary>
        /// <param name="featureType"></param>
        /// <param name="elementType"></param>
        /// <param name="colorHex"></param>
        /// <returns></returns>
        public GoogleMapStyleBuilder AddColor(string featureType, string elementType, string colorHex)
        {
            MapTypeStyle s = new MapTypeStyle();

            s.elementType = elementType;
            s.featureType = featureType;
            s.stylers     = new[] { (GoogleMapStyleColor)colorHex };
            _styles.Add(s);

            return(this);
        }
Пример #6
0
        /// <summary>
        /// AddVisibility("administrative", "", false).
        /// Color is casted into <see cref="GoogleMapStyleVisibility"/>  element
        /// </summary>
        /// <param name="featureType"></param>
        /// <param name="elementType"></param>
        /// <param name="visibility"></param>
        public GoogleMapStyleBuilder AddVisibility(string featureType, string elementType, bool visibility)
        {
            MapTypeStyle s = new MapTypeStyle();

            s.elementType = elementType;
            s.featureType = featureType;
            s.stylers     = new[] { (GoogleMapStyleVisibility)visibility };
            _styles.Add(s);

            return(this);
        }
Пример #7
0
        /// <summary>
        /// Json from https://mapstyle.withgoogle.com/
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public GoogleMapStyleBuilder AddStyle(string json)
        {
            var dirResult = JsonConvert.DeserializeObject <dynamic>(json);

            foreach (var styleItem in dirResult)
            {
                MapTypeStyle s = new MapTypeStyle();
                s.elementType = styleItem.elementType;
                s.featureType = styleItem.featureType;
                if (IsPropertyExist(styleItem, "stylers"))
                {
                    if (IsPropertyExist(styleItem.stylers[0], "visibility"))
                    {
                        string stylerValue = styleItem.stylers[0].visibility?.ToString();
                        if (!string.IsNullOrEmpty(stylerValue))
                        {
                            s.stylers = new[] { new GoogleMapStyleVisibility()
                                                {
                                                    visibility = stylerValue
                                                } };
                        }
                    }

                    if (IsPropertyExist(styleItem.stylers[0], "color"))
                    {
                        string stylerValue = styleItem.stylers[0].color?.ToString();
                        if (!string.IsNullOrEmpty(stylerValue))
                        {
                            s.stylers = new[] { new GoogleMapStyleColor()
                                                {
                                                    color = stylerValue
                                                } };
                        }
                    }
                }

                _styles.Add(s);
            }

            return(this);
        }
Пример #8
0
        /// <summary>
        /// Json from https://mapstyle.withgoogle.com/
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        public GoogleMapStyleBuilder AddStyle(string json)
        {
            var dirResult = JsonConvert.DeserializeObject <dynamic>(json);

            foreach (var styleItem in dirResult)
            {
                MapTypeStyle s = new MapTypeStyle();
                s.elementType = styleItem.elementType;
                s.featureType = styleItem.featureType;
                if (IsPropertyExist(styleItem, "stylers"))
                {
                    if (IsPropertyExist(styleItem.stylers[0], "visibility"))
                    {
                        string stylerValue = styleItem.stylers[0].visibility?.ToString();
                        if (!string.IsNullOrEmpty(stylerValue))
                        {
                            s.stylers = new[] { new GoogleMapStyleVisibility()
                                                {
                                                    visibility = stylerValue
                                                } };
                        }
                    }

                    if (IsPropertyExist(styleItem.stylers[0], "color"))
                    {
                        string stylerValue = styleItem.stylers[0].color?.ToString();
                        if (!string.IsNullOrEmpty(stylerValue))
                        {
                            s.stylers = new[] { new GoogleMapStyleColor()
                                                {
                                                    color = stylerValue
                                                } };
                        }
                    }

                    if (IsPropertyExist(styleItem.stylers[0], "lightness"))
                    {
                        string stylerValue = styleItem.stylers[0].lightness?.ToString();
                        if (!string.IsNullOrEmpty(stylerValue) && int.TryParse(stylerValue, out int l))
                        {
                            s.stylers = new[] { new GoogleMapStyleLightness {
                                                    lightness = l
                                                } };
                        }
                    }

                    if (IsPropertyExist(styleItem.stylers[0], "saturation"))
                    {
                        string stylerValue = styleItem.stylers[0].saturation?.ToString();
                        if (!string.IsNullOrEmpty(stylerValue) && int.TryParse(stylerValue, out int sat))
                        {
                            s.stylers = new[] { new GoogleMapStyleSaturation {
                                                    saturation = sat
                                                } };
                        }
                    }

                    if (IsPropertyExist(styleItem.stylers[0], "weight"))
                    {
                        string stylerValue = styleItem.stylers[0].weight?.ToString();
                        if (!string.IsNullOrEmpty(stylerValue) && double.TryParse(stylerValue, out double w))
                        {
                            s.stylers = new[] { new GoogleMapStyleWeight {
                                                    weight = w
                                                } };
                        }
                    }
                }

                _styles.Add(s);
            }

            return(this);
        }