Beispiel #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;
        }
Beispiel #2
0
        /// <summary>
        /// Registers the SDK license. This class method and must be called before
        /// creating any actual MapView instances.
        /// </summary>
        /// <param name="licenseKey">The license string provided for this application.</param>
        /// <param name="context">Application context for the license.</param>
        /// <returns>True if license is valid, false if not.</returns>
        public static bool RegisterLicense(string licenseKey, Context context) {
            // Connect context info and assets manager to native part
            AndroidUtils.SetContext (context);
            if (_assetManager == null) {
                _assetManager = context.ApplicationContext.Assets;
                AssetUtils.SetAssetManagerPointer(_assetManager);
            }

            ISharedPreferences prefs = context.GetSharedPreferences(context.PackageName + "_carto_mobile_sdk1_preferences", FileCreationMode.Private);
            ReadKeyDelegate readKey = (string key) => { return prefs.GetString(key, null); };
            WriteKeyDelegate writeKey = (string key, string value) => { prefs.Edit().PutString(key, value); };
            return RegisterLicenseInternal(licenseKey, readKey, writeKey);
        }
Beispiel #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;
        }