コード例 #1
0
        private void HandleStyleLoaded(MapStyle obj)
        {
            map.Functions.AddSource(new VectorSource(
                                        "ethnicity-source",
                                        "http://api.mapbox.com/v4/examples.8fgz4egr.json?access_token=" + MapBoxService.AccessToken
                                        ));

            var circleLayer = new CircleLayer("population", "ethnicity-source")
            {
                SourceLayer  = "sf2010",
                CircleRadius =
                    Expression.Interpolate(
                        Expression.Exponential(1.75f),
                        Expression.Zoom(),
                        Expression.CreateStop(12f, 2f),
                        Expression.CreateStop(22f, 180f)
                        ),
                CircleColor =
                    Expression.Match(
                        Expression.Get("ethnicity"), Expression.Rgb(0f, 0f, 0f),
                        Expression.CreateStop("white", Expression.Rgb(251f, 176f, 59f)),
                        Expression.CreateStop("Black", Expression.Rgb(34f, 59f, 83f)),
                        Expression.CreateStop("Hispanic", Expression.Rgb(229f, 94f, 94f)),
                        Expression.CreateStop("Asian", Expression.Rgb(59f, 178f, 208f)),
                        Expression.CreateStop("Other", Expression.Rgb(204f, 204f, 204f)))
            };

            map.Functions.AddLayer(circleLayer);
        }
コード例 #2
0
        private void HandleStyleLoaded(MapStyle obj)
        {
            map.Functions.AddSource(
                // Point to GeoJSON data. This example visualizes all M1.0+ earthquakes from
                // 12/22/15 to 1/21/16 as logged by USGS' Earthquake hazards program.
                new GeoJsonSource("earthquakes",
                                  "https://www.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson")
            {
                Options = new GeoJsonOptions()
                {
                    Cluster        = (true),
                    ClusterMaxZoom = (15),    // Max zoom to cluster points on
                    ClusterRadius  = (20),    // Use small cluster radius for the hotspots look
                }
            }
                );

            // Use the earthquakes source to create four layers:
            // three for each cluster category, and one for unclustered points

            // Each point range gets a different fill color.
            var layers = new KeyValuePair <int, Color>[] {
                new KeyValuePair <int, Color> (150, Color.FromHex("#E55E5E")),
                new KeyValuePair <int, Color>(20, Color.FromHex("#F9886C")),
                new KeyValuePair <int, Color>(0, Color.FromHex("#FBB03B"))
            };

            CircleLayer unclustered = new CircleLayer("unclustered-points", "earthquakes")
            {
                CircleColor  = Color.FromHex("#FBB03B"),
                CircleRadius = 20f,
                CircleBlur   = 1f,
                Filter       = Expression.Neq(Expression.Get("cluster"), Expression.Literal(true))
            };

            map.Functions.AddLayerBelow(unclustered, "building");

            for (int i = 0; i < layers.Length; i++)
            {
                var pointCount = Expression.ToNumber(Expression.Get("point_count"));
                var circles    = new CircleLayer("cluster-" + i, "earthquakes")
                {
                    CircleColor  = layers[i].Value,
                    CircleRadius = 70f,
                    CircleBlur   = 1f,
                    Filter       = i == 0
                    ? Expression.Gte(pointCount, Expression.Literal(layers[i].Key))
                    : Expression.All(
                        Expression.Gte(pointCount, Expression.Literal(layers[i].Key)),
                        Expression.Lt(pointCount, Expression.Literal(layers[i - 1].Key))
                        )
                };
                map.Functions.AddLayerBelow(circles, "building");
            }
        }
コード例 #3
0
        private void AddPointsLayer()
        {
            // Create and style a CircleLayer that uses the Point Features' coordinates in the GeoJSON data
            CircleLayer individualCirclesLayer = new CircleLayer("points", GEOJSON_SOURCE_ID)
            {
                CircleColor  = Color.Yellow,
                CircleRadius = 3f,
                Filter       = Expression.Eq(Expression.Literal("$type"), Expression.Literal("Point"))
            };

            map.Functions.AddLayer(individualCirclesLayer);
        }
コード例 #4
0
        private void AddCircleLayer()
        {
            CircleLayer circleLayer = new CircleLayer(CIRCLE_LAYER_ID, EARTHQUAKE_SOURCE_ID)
            {
                // Size circle radius by earthquake magnitude and zoom level
                CircleRadius =
                    Expression.Interpolate(
                        Expression.Linear(), Expression.Zoom(),
                        Expression.Literal(7), Expression.Interpolate(
                            Expression.Linear(), Expression.Get("mag"),
                            Expression.CreateStop(1, 1),
                            Expression.CreateStop(6, 4)
                            ),
                        Expression.Literal(16), Expression.Interpolate(
                            Expression.Linear(), Expression.Get("mag"),
                            Expression.CreateStop(1, 5),
                            Expression.CreateStop(6, 50)
                            )
                        )
                ,

                // Color circle by earthquake magnitude
                CircleColor = (
                    Expression.Interpolate(
                        Expression.Linear(), Expression.Get("mag"),
                        Expression.Literal(1), Expression.Rgba(33, 102, 172, 0),
                        Expression.Literal(2), Expression.Rgb(103, 169, 207),
                        Expression.Literal(3), Expression.Rgb(209, 229, 240),
                        Expression.Literal(4), Expression.Rgb(253, 219, 199),
                        Expression.Literal(5), Expression.Rgb(239, 138, 98),
                        Expression.Literal(6), Expression.Rgb(178, 24, 43)
                        )
                    ),

                // Transition from heatmap to circle layer by zoom level
                CircleOpacity =
                    Expression.Interpolate(
                        Expression.Linear(), Expression.Zoom(),
                        Expression.CreateStop(7, 0),
                        Expression.CreateStop(8, 1)
                        )
                ,
                CircleStrokeColor = "white",
                CircleStrokeWidth = 1.0f
            };

            map.Functions.AddLayerBelow(circleLayer, HEATMAP_LAYER_ID);
        }
コード例 #5
0
        private void HandleStyleLoaded(MapStyle obj)
        {
            var source = new VectorSource("museums_source", "mapbox://mapbox.2opop9hr");

            map.Functions.AddSource(source);

            museumsLayer = new CircleLayer("museums", "museums_source")
            {
                SourceLayer  = "museum-cusco",
                Visibility   = Expression.Visibility(true),
                CircleRadius = 8,
                CircleColor  = Expression.Rgb(55, 148, 179)
            };

            map.Functions.AddLayer(museumsLayer);
        }
コード例 #6
0
        public static Sdk.Style.Layers.CircleLayer ToNative(this CircleLayer layer)
        {
            if (layer == null)
            {
                return(null);
            }

            var native = new Sdk.Style.Layers.CircleLayer(layer.Id.Prefix(), layer.SourceId.Prefix());

            native.SetProperties(
                Sdk.Style.Layers.PropertyFactory.CircleColor(layer.CircleColor.ToAndroid()),
                Sdk.Style.Layers.PropertyFactory.CircleOpacity(new Java.Lang.Float(layer.CircleOpacity)),
                Sdk.Style.Layers.PropertyFactory.CircleRadius(new Java.Lang.Float(layer.CircleRadius))
                );

            return(native);
        }
コード例 #7
0
        private void AddClusteredGeoJsonSource()
        {
            map.Functions.AddSource(
                // Point to GeoJSON data. This example visualizes all M1.0+ earthquakes from
                // 12/22/15 to 1/21/16 as logged by USGS' Earthquake hazards program.
                new GeoJsonSource("earthquakes",
                                  "https://www.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson")
            {
                Options = new GeoJsonOptions
                {
                    Cluster        = (true),
                    ClusterMaxZoom = (14),
                    ClusterRadius  = (50),
                }
            }
                );

            // Use the earthquakes GeoJSON source to create three layers: One layer for each cluster category.
            // Each point range gets a different fill color.
            var layers = new KeyValuePair <int, Color>[] {
                new KeyValuePair <int, Color> (150, Color.FromHex("#f74e4e")),
                new KeyValuePair <int, Color>(20, Color.FromHex("#f74e4e")),
                new KeyValuePair <int, Color>(0, Color.FromHex("#f74e4e"))
            };

            //Creating a marker layer for single data points
            SymbolLayer unclustered = new SymbolLayer("unclustered-points", "earthquakes")
            {
                IconImage = "cross-icon-id",
                IconSize  = Expression.Division(
                    Expression.Get("mag"), Expression.Literal(4.0f)
                    ),
                IconColor = Expression.Interpolate(
                    Expression.Exponential(1), Expression.Get("mag"),
                    Expression.CreateStop(2.0, Expression.Rgb(0, 255, 0)),
                    Expression.CreateStop(4.5, Expression.Rgb(0, 0, 255)),
                    Expression.CreateStop(7.0, Expression.Rgb(255, 0, 0)))
            };

            map.Functions.AddLayer(unclustered);

            for (int i = 0; i < layers.Length; i++)
            {
                var pointCount = Expression.ToNumber(Expression.Get("point_count"));

                //Add clusters' circles
                var circles = new CircleLayer("cluster-" + i, "earthquakes")
                {
                    CircleColor  = layers[i].Value,
                    CircleRadius = 18f,

                    // Add a filter to the cluster layer that hides the circles based on "point_count"
                    Filter = i == 0
                        ? Expression.All(Expression.Has("point_count"), Expression.Gte(pointCount, Expression.Literal(layers[i].Key)))
                        : Expression.All(Expression.Has("point_count"),
                                         Expression.Gte(pointCount, Expression.Literal(layers[i].Key)),
                                         Expression.Lt(pointCount, Expression.Literal(layers[i - 1].Key)))
                };
                map.Functions.AddLayer(circles);
            }

            //Add the count labels
            SymbolLayer count = new SymbolLayer("count", "earthquakes")
            {
                TextField           = Expression.ToString(Expression.Get("point_count")),
                TextSize            = 12f,
                TextColor           = Color.White,
                TextIgnorePlacement = (true),
                TextAllowOverlap    = (true)
            };

            map.Functions.AddLayer(count);
        }