示例#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;
        }
示例#2
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);
        }
示例#3
0
        private static bool RegisterLicenseInternal(string licenseKey, ReadKeyDelegate readKey, WriteKeyDelegate writeKey)
        {
            string oldKey = "license_key_old";
            string newKey = "license_key_new";
            LicenseManagerListener listener = new MapLicenseManagerListener((string updatedLicenseKey) => {
                try {
                    writeKey(newKey, updatedLicenseKey);
                }
                catch (System.Exception e) {
                    Carto.Utils.Log.Error("MapView.RegisterLicense: Failed to save license key: " + e);
                }
            });
            string newLicenseKey = null;

            try {
                string oldLicenseKey = readKey(oldKey);
                if (oldLicenseKey != null && oldLicenseKey != licenseKey)
                {
                    newLicenseKey = readKey(newKey);
                }
            }
            catch (System.Exception e) {
                Carto.Utils.Log.Error("MapView.RegisterLicense: Failed to read license key: " + e);
            }
            return(BaseMapView.RegisterLicense(newLicenseKey != null ? newLicenseKey : licenseKey, listener));
        }
 public void OnDrawFrame(IGL10 gl)
 {
     lock (this) {
         BaseMapView baseMapView = null;
         _baseMapView.TryGetTarget(out baseMapView);
         if (baseMapView != null)
         {
             baseMapView.OnDrawFrame();
         }
     }
 }
 public void OnSurfaceChanged(IGL10 gl, int width, int height)
 {
     lock (this) {
         BaseMapView baseMapView = null;
         _baseMapView.TryGetTarget(out baseMapView);
         if (baseMapView != null)
         {
             baseMapView.OnSurfaceChanged(width, height);
         }
     }
 }
 public void OnSurfaceCreated(IGL10 gl, Javax.Microedition.Khronos.Egl.EGLConfig config)
 {
     lock (this) {
         BaseMapView baseMapView = null;
         _baseMapView.TryGetTarget(out baseMapView);
         if (baseMapView != null)
         {
             baseMapView.OnSurfaceCreated();
         }
     }
 }
示例#7
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;
        }
示例#8
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)
                );
        }
示例#9
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));
        }
示例#10
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();
        }
 public void Detach()
 {
     lock (this) {
         _baseMapView = null;
     }
 }
 public BaseMapViewRenderer(BaseMapView baseMapView)
 {
     _baseMapView = baseMapView;
 }
示例#13
0
 public BaseMapViewRenderer(BaseMapView baseMapView)
 {
     _baseMapView = new WeakReference <BaseMapView>(baseMapView);
 }