NAXAM / mapbox-android-binding

Xamarin binding for MapBox Android SDK
Other
24 stars 15 forks source link

Building extrusion #13

Closed Emixam23 closed 1 year ago

Emixam23 commented 6 years ago

Hey !

I would like to know if your package provides 3D building extrusion?

Thanks,

Max

tuyen-vuduc commented 6 years ago

@Emixam23

It's binding library for Mapbox native SDK, so what the native version provides will be there.

Cheers.

Emixam23 commented 6 years ago

Perfect !

I will give it a try then, thank you :)

Emixam23 commented 6 years ago

Hey !

I did give a try and... I am close but still not working. I am trying to translate this piece of Java:

https://github.com/mapbox/mapbox-android-demo/blob/master/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/extrusions/PopulationDensityExtrusionActivity.java

However, I can't find the interpolate function, it's the only part I couldn't code so far...

using System.Linq.Expressions;
using Android.App;
using Android.OS;
using Com.Mapbox.Mapboxsdk.Camera;
using Com.Mapbox.Mapboxsdk.Geometry;
using Com.Mapbox.Mapboxsdk.Maps;
using Com.Mapbox.Mapboxsdk.Style.Functions;
using Com.Mapbox.Mapboxsdk.Style.Functions.Stops;
using Com.Mapbox.Mapboxsdk.Style.Layers;
using static Com.Mapbox.Mapboxsdk.Style.Layers.Filter;
using static Com.Mapbox.Mapboxsdk.Style.Layers.PropertyFactory;
using MapboxAccountManager = Com.Mapbox.Mapboxsdk.Mapbox;
using System;
using Android.Graphics;
using Java.Lang;

namespace MapBoxPOC.Android
{
    [Activity(Label = "MapBoxPOC.Android", MainLauncher = true)]
    public class MainActivity : Activity, IOnMapReadyCallback
    {
        private MapView mapViewControl;
        private MapboxMap mapboxMapControl;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Mapbox Access token
            MapboxAccountManager.GetInstance(Application.Context, "MAPBOX_TOKEN");

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            mapViewControl = FindViewById<MapView>(Resource.Id.mapViewControl);
            mapViewControl.OnCreate(savedInstanceState);
            mapViewControl.GetMapAsync(this);
        }

        public void OnMapReady(MapboxMap map)
        {
            mapboxMapControl = map;
            var position = new CameraPosition.Builder()
                           .Target(new LatLng(41.885, -87.679)) // Sets the new camera position
                           .Zoom(11) // Sets the zoom
                           .Build(); // Creates a CameraPosition from the builder

            map.AnimateCamera(CameraUpdateFactory.NewCameraPosition(position));
            AddFillsLayer();
            AddExtrusionLayer();
        }

        private void AddFillsLayer()
        {
            FillLayer fillsLayer = new FillLayer("fills", "population");
            fillsLayer.SourceLayer = "outgeojson";
            fillsLayer.SetFilter(All(Lt("pkm2", 300000)));
            fillsLayer.SetProperties(
                FillExtrusionColor(
                    Function.Composite(
                        "pkm2",
                        Stops.Categorical(
                            Stop.InvokeStop(0, FillExtrusionColor("#160e23")),
                            Stop.InvokeStop(14500, FillExtrusionColor("#00617f")),
                            Stop.InvokeStop(145000, FillExtrusionColor("#55e9ff"))))));
            mapboxMapControl.AddLayer(fillsLayer);
        }

        private void AddExtrusionLayer()
        {
            FillExtrusionLayer fillExtrusionLayer = new FillExtrusionLayer("extrusions", "population");
            fillExtrusionLayer.SourceLayer = "outgeojson";
            fillExtrusionLayer.SetFilter(All(Gt("p", 1), Lt("pkm2", 300000)));
            fillExtrusionLayer.SetProperties(
                FillExtrusionColor(
                    Function.Composite(
                        "pkm2",
                        Stops.Categorical(
                            Stop.InvokeStop(0, FillExtrusionColor("#160e23")),
                            Stop.InvokeStop(14500, FillExtrusionColor("#00617f")),
                            Stop.InvokeStop(145000, FillExtrusionColor("#55e9ff"))))),
                FillExtrusionBase(new Float(0)),
                FillExtrusionHeight(
                    Function.Composite(
                        "pkm2",
                        Stops.Categorical(
                            Stop.InvokeStop(0, new PropertyValue("0", 0)),
                            Stop.InvokeStop(1450000, new PropertyValue("20000f", 20000))
            ))));
            mapboxMapControl.AddLayer(fillExtrusionLayer);
        }

        protected override void OnPause()
        {
            base.OnPause();
            mapViewControl.OnPause();
        }

        protected override void OnResume()
        {
            base.OnResume();
            if (mapViewControl != null)
                mapViewControl.OnResume();
        }

        public override void OnLowMemory()
        {
            base.OnLowMemory();
            mapViewControl.OnLowMemory();
        }

        protected override void OnDestroy()
        {
            base.OnDestroy();
            mapViewControl.OnDestroy();
        }

        protected override void OnSaveInstanceState(Bundle outState)
        {
            base.OnSaveInstanceState(outState);
            mapViewControl.OnSaveInstanceState(outState);
        }
    }
}

Thanks for any help !

tuyen-vuduc commented 1 year ago

Please check out latest version

https://www.nuget.org/packages/Com.Mapbox.Maps.Android