예제 #1
0
        private void InitBase()
        {
            _active             = false;
            _surfaceCreated     = false;
            _activeDrawableSize = new CGSize(0, 0);
            _scale             = (float)UIScreen.MainScreen.NativeScale;
            ContentScaleFactor = _scale;

            _baseMapView = new BaseMapView();
            _baseMapView.GetOptions().DPI = 160 * _scale;

            _redrawRequestListener = new MapRedrawRequestListener(this);
            _baseMapView.SetRedrawRequestListener(_redrawRequestListener);

            if (Window != null)
            {
                InitContext();
                _active = true;
                SetNeedsDisplay();
            }

            _willResignActiveNotificationObserver    = NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.WillResignActiveNotification, OnAppWillResignActive, null);
            _didEnterBackgroundNotificationObserver  = NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.DidEnterBackgroundNotification, OnAppDidEnterBackground, null);
            _willEnterForegroundNotificationObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.WillEnterForegroundNotification, OnAppWillEnterForeground, null);
        }
예제 #2
0
        /// <summary>
        /// Constructs a new MapView object from a context object and attributes.
        /// </summary>
        /// <param name="context">The context object.</param>
        /// <param name="attrs">The attributes.</param>
        public MapView(Context context, IAttributeSet attrs) : base(context, attrs)
        {
            // Connect context info and assets manager to native part
            AndroidUtils.SetContext(context);
            if (_assetManager == null)
            {
                Carto.Utils.Log.Warn("MapView: MapView created before MapView.RegisterLicense is called");

                _assetManager = context.ApplicationContext.Assets;
                AssetUtils.SetAssetManagerPointer(_assetManager);
            }

            // Create base map view, attach redraw listener
            _baseMapView = new BaseMapView();
            _baseMapView.GetOptions().DPI = (int)Resources.DisplayMetrics.DensityDpi;

            _redrawRequestListener = new MapRedrawRequestListener(this);
            _baseMapView.SetRedrawRequestListener(_redrawRequestListener);

            // Create base map renderer and EGL configuration chooser
            _baseMapViewRenderer = new BaseMapViewRenderer(_baseMapView);

            try {
                System.Reflection.PropertyInfo prop = typeof(GLSurfaceView).GetProperty("PreserveEGLContextOnPause");
                prop.SetValue(this, true);
            } catch (System.Exception) {
                Carto.Utils.Log.Info("MapView: Preserving EGL context on pause is not possible");
            }

            SetEGLContextClientVersion(2);
            SetEGLConfigChooser(new ConfigChooser());
            SetRenderer(_baseMapViewRenderer);
            RenderMode = Rendermode.WhenDirty;
        }
예제 #3
0
        /// <summary>
        /// Constructs a new MapView object from a context object and attributes.
        /// </summary>
        /// <param name="context">The context object.</param>
        /// <param name="attrs">The attributes.</param>
        public MapView(Context context, IAttributeSet attrs) : base(context, attrs)
        {
            // Connect context info and assets manager to native part
            AndroidUtils.SetContext(context);
            if (_assetManager == null)
            {
                Carto.Utils.Log.Warn("MapView: MapView created before MapView.RegisterLicense is called");

                _assetManager = context.ApplicationContext.Assets;
                AssetUtils.SetAssetManagerPointer(_assetManager);
            }

            // Unless explictly not clickable, make clickable by default
            bool clickable     = true;
            bool longClickable = true;

            try {
                TypedArray ta = context.ObtainStyledAttributes(attrs, new int[] { Android.Resource.Attribute.Clickable, Android.Resource.Attribute.LongClickable });
                clickable     = ta.GetBoolean(0, true);
                longClickable = ta.GetBoolean(1, true);
                ta.Recycle();
            } catch (System.Exception e) {
                Carto.Utils.Log.Warn("MapView: Failed to read attributes");
            }
            Clickable     = clickable;
            LongClickable = longClickable;

            // Create base map view, attach redraw listener
            _baseMapView = new BaseMapView();
            _baseMapView.GetOptions().DPI = (int)Resources.DisplayMetrics.DensityDpi;

            _redrawRequestListener = new MapRedrawRequestListener(this);
            _baseMapView.SetRedrawRequestListener(_redrawRequestListener);

            // Create base map renderer and EGL configuration chooser
            _baseMapViewRenderer = new BaseMapViewRenderer(_baseMapView);

            try {
                System.Reflection.PropertyInfo prop = typeof(GLSurfaceView).GetProperty("PreserveEGLContextOnPause");
                prop.SetValue(this, true);
            } catch (System.Exception) {
                Carto.Utils.Log.Info("MapView: Preserving EGL context on pause is not possible");
            }

            SetEGLContextClientVersion(2);
            SetEGLConfigChooser(new ConfigChooser());
            SetRenderer(_baseMapViewRenderer);
            RenderMode = Rendermode.WhenDirty;
        }
예제 #4
0
        private void InitBase()
        {
            this.Delegate = new MapViewGLKViewDelegate();

            _didEnterBackgroundNotificationObserver  = NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.DidEnterBackgroundNotification, OnAppDidEnterBackground, null);
            _willEnterForegroundNotificationObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.WillEnterForegroundNotification, OnAppWillEnterForeground, null);

            _active = true;

            _scale       = (float)UIScreen.MainScreen.Scale;
            _baseMapView = new BaseMapView();
            _baseMapView.SetRedrawRequestListener(new MapRedrawRequestListener(this));
            _baseMapView.GetOptions().DPI = 160 * _scale;

            DispatchQueue.MainQueue.DispatchAsync(
                new System.Action(InitGL)
                );
        }
예제 #5
0
        /// <summary>
        /// Constructs a new MapView object.
        /// </summary>
        public MapView()
        {
            _baseMapView = new BaseMapView();

            InitializeComponent();

            this.Loaded += new Windows.UI.Xaml.RoutedEventHandler(OnPageLoaded);

            Windows.UI.Core.CoreWindow window = Windows.UI.Xaml.Window.Current.CoreWindow;
            window.VisibilityChanged += new Windows.Foundation.TypedEventHandler <Windows.UI.Core.CoreWindow, Windows.UI.Core.VisibilityChangedEventArgs> (OnVisibilityChanged);

            _swapChainPanel.SizeChanged += new Windows.UI.Xaml.SizeChangedEventHandler(OnSwapChainPanelSizeChanged);
            _swapChainPanelSize          = new Windows.Foundation.Size(_swapChainPanel.RenderSize.Width, _swapChainPanel.RenderSize.Height);

            Windows.Graphics.Display.DisplayInformation dispInfo = Windows.Graphics.Display.DisplayInformation.GetForCurrentView();
            _resolutionScale = (float)dispInfo.RawPixelsPerViewPixel;
            _baseMapView.GetOptions().DPI = (float)dispInfo.RawDpiX;

            _baseMapView.SetRedrawRequestListener(new MapViewRedrawRequestListener(this));
        }
예제 #6
0
        private void InitBase()
        {
            this.Delegate = new MapViewGLKViewDelegate();

            _didEnterBackgroundNotificationObserver  = NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.DidEnterBackgroundNotification, OnAppDidEnterBackground, null);
            _willEnterForegroundNotificationObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.WillEnterForegroundNotification, OnAppWillEnterForeground, null);

            _active = true;

            _scale = (float)UIScreen.MainScreen.NativeScale;

            _baseMapView = new BaseMapView();
            _baseMapView.GetOptions().DPI = 160 * _scale;

            _redrawRequestListener = new MapRedrawRequestListener(this);
            _baseMapView.SetRedrawRequestListener(_redrawRequestListener);

            _viewContext = new EAGLContext(EAGLRenderingAPI.OpenGLES2);
            if (_viewContext == null)
            {
                Log.Fatal("MapView.InitGL: Failed to create OpenGLES 2.0 context");
            }
            this.Context            = _viewContext;
            this.ContentScaleFactor = _scale;

            DrawableColorFormat   = GLKViewDrawableColorFormat.RGBA8888;
            DrawableDepthFormat   = GLKViewDrawableDepthFormat.Format24;
            DrawableMultisample   = GLKViewDrawableMultisample.None;
            DrawableStencilFormat = GLKViewDrawableStencilFormat.Format8;
            MultipleTouchEnabled  = true;

            if (_viewContext != null)
            {
                EAGLContext.SetCurrentContext(_viewContext);
                _baseMapView.OnSurfaceCreated();
                _baseMapView.OnSurfaceChanged((int)(Bounds.Size.Width * _scale), (int)(Bounds.Size.Height * _scale));
            }

            SetNeedsDisplay();
        }