Exemple #1
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;
        }
Exemple #2
0
        protected override void Dispose(bool disposing) {
            lock (this) {
                // Detach objects
                if (_baseMapViewRenderer != null) {
                    _baseMapViewRenderer.Detach();
                }
                if (_redrawRequestListener != null) {
                    _redrawRequestListener.Detach();
                }
                if (_baseMapView != null) {
                    _baseMapView.SetRedrawRequestListener(null);
                }

                // Dispose objects
                if (_configChooser != null) {
                    _configChooser.Dispose();
                    _configChooser = null;
                }
                if (_baseMapViewRenderer != null) {
                    _baseMapViewRenderer.Dispose(); // allow the Java object to be collected later
                    _baseMapViewRenderer = null;
                }
                if (_baseMapView != null) {
                    _baseMapView.Dispose();
                    _baseMapView = null;
                }
                if (_redrawRequestListener != null) {
                    _redrawRequestListener.Dispose();
                    _redrawRequestListener = null;
                }
            }
            base.Dispose(disposing);
        }
Exemple #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;
        }