Package globus.glmap
Class GLMapViewRenderer
java.lang.Object
globus.glmap.GLNativeObject
globus.glmap.GLMapViewRenderer
- All Implemented Interfaces:
android.view.SurfaceHolder.Callback
,android.view.SurfaceHolder.Callback2
,android.view.TextureView.SurfaceTextureListener
public class GLMapViewRenderer
extends GLNativeObject
implements android.view.SurfaceHolder.Callback2, android.view.TextureView.SurfaceTextureListener
Renderer of map
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Callback that is called to automatically create animationstatic @interface
Placement of screen-bound objectsstatic @interface
State of tilestatic interface
Screen capture callbackstatic interface
Raw screen capture callback -
Field Summary
Modifier and TypeFieldDescriptionandroid.view.View
View where this render is attachedfloat
Screen scaleint
Surface heightint
Surface width -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(GLMapDrawObject drawObject) Adds aGLMapDrawObject
to the map.void
addTextForbiddenArea
(int name, MapPoint origin, int offsetX, int offsetY, int width, int height) Adds or updates area where text (and associated icon) must not drawanimate
(GLMapViewRenderer.AnimateCallback callback) Create and starts animation using provided callbackanimate
(GLMapViewRenderer.AnimateCallback callback, Runnable onFinish) Create and starts animation using provided callbackvoid
attachToSurfaceView
(android.view.SurfaceView surfaceView) Attach renderer to surface viewboolean
attachToTextureView
(android.view.TextureView textureView) Attach renderer to texture viewvoid
Cancels all active animations on the map.void
Captures frame when surface will be created and loading of resources finished.void
changeDrawOrder
(GLMapDrawObject drawObject, int drawOrder) Changes the draw order of the specifiedGLMapDrawObject
.Converts a distance between two points on the screen to delta in internal format of GLMapView.convertDisplayDeltaToInternal
(MapPoint val, double mapZoom, float mapAngle) Converts a distance between two points on the screen to delta in internal format of GLMapView.Converts a point on the surface to an internal map coordinate.Converts a point in internal format of GLMapView to point on the surface of view.double
convertMetersToInternal
(double meters) Converts meters distance to internal distancestatic void
crashNDK()
Function to test native crashesstatic void
Function to test native crashesvoid
Disables clipping of visible map areastatic void
Call this function before creating GLMapView to disable background loading of resources.void
dispose()
Call this method when object does not needed.void
Runs command on internal rendering thread.void
enableClipping
(GLMapBBox bbox, float minLevel, float maxLevel) Enables clipping of the visible map area using the specified bounding box (BBox) and zoom levels.static void
After calling this function any new GLMapView will use OpenGL 2.0 even if device supports OpenGL 3.0 Some cheap Android devices have problems with drivers.getBase()
Retrieves the base tile source that was previously set.getBBox()
Retrieves the bounding box (BBox) of the currently visible part of theGLMapView
.getBBoxWithInsets
(int left, int right, int top, int bottom) Retrieves the bounding box (BBox) of the visible part of theGLMapView
with applied insets.int
Return state of center tilegetCurrentMapCenter
(MapPoint point) Gets current coordinates of the origin point of the map.double
Gets current scale of the map.double
Gets current zoom level of the map.boolean
Retrieves the visibility state of elevation lines.boolean
Retrieves the visibility state of hill shades.boolean
Retrieves the visibility state of slopes.float
Retrieves the current font scale.float
getFps()
Returns fpsRetrieves the previously set locale settings.float
Gets current angle of the map.Retrieves the coordinates of the center point of the map.getMapCenter
(MapPoint point) Gets coordinates of the origin point of the map.Retrieves the coordinates of the center point of the map.Retrieves the origin point of the map coordinate system.getMapOrigin
(MapPoint point) Retrieves the origin point of the map coordinate system and fills the providedMapPoint
object with its values.float
Gets current pitch of the map.double
Gets scale of the map.double
Get zoom level of the map.double
Gets maximum scale of the mapRetrieves the overlay tile sources that were previously set.boolean
Checks if clipping is enableddouble
mapZoomForBBox
(GLMapBBox bbox, int mapWidth, int mapHeight) Calculates zoom of map to fit given bboxvoid
onSurfaceTextureAvailable
(android.graphics.SurfaceTexture surfaceTexture, int width, int height) boolean
onSurfaceTextureDestroyed
(android.graphics.SurfaceTexture surfaceTexture) void
onSurfaceTextureSizeChanged
(android.graphics.SurfaceTexture surfaceTexture, int width, int height) void
onSurfaceTextureUpdated
(android.graphics.SurfaceTexture surfaceTexture) void
Force reloading of all tiles.void
remove
(GLMapDrawObject drawObject) Removes aGLMapDrawObject
from the map.void
Removes all images, image groups, tracks, and marker layers from the map.void
removeTextForbiddenArea
(int name) Removes areavoid
setAttributionPosition
(int placement) Sets the position of the map attribution.void
setBase
(GLMapTileSource base) Sets the base tile source.void
setCenterTileStateChangedCallback
(Runnable callback) Set callback that will be called when center tile state is changedvoid
setDrawElevationLines
(boolean drawElevationLines) Sets the visibility of elevation lines.void
setDrawHillshades
(boolean drawHillshades) Sets the visibility of hill shades.void
setDrawSlopes
(boolean drawSlopes) Sets the visibility of slopes.void
setFontScale
(float scale) Sets the scale of the font used in the map.void
setFps
(float fps) Sets fpsvoid
setLocaleSettings
(GLMapLocaleSettings localeSettings) Sets map locale settingsvoid
setMapAngle
(float newAngle) Sets angle of the map.void
setMapCenter
(MapPoint center) Sets the coordinates of the center point of the map.void
setMapDidMoveCallback
(Runnable callback) Sets callback that will be called after move animation finishedvoid
setMapGeoCenter
(MapGeoPoint geoCenter) Sets the coordinates of the center point of the map.void
setMapOrigin
(float x, float y) Sets the origin point of the map coordinate system (X, Y).void
setMapPitch
(float newAngle) Sets pitch of the map.void
setMapScale
(double newScale) Set scale of the map.void
setMapZoom
(double newZoom) Sets zoom level of the map.void
setMaxScale
(double maxScale) Sets maximum scale of the mapvoid
Force redrawvoid
setOverlays
(GLMapTileSource[] overlays) Sets the overlay tile sources.void
setSafeArea
(int left, int top, int right, int bottom) Sets the safe area insets for the scale ruler and other map objects.void
setStyle
(GLMapVectorCascadeStyle style) Sets map stylevoid
startAnimation
(GLMapAnimation animation) Starts the specified animation on the map.void
surfaceChanged
(android.view.SurfaceHolder holder, int format, int width, int height) void
surfaceCreated
(android.view.SurfaceHolder holder) void
surfaceDestroyed
(android.view.SurfaceHolder holder) void
surfaceRedrawNeeded
(android.view.SurfaceHolder holder) void
surfaceRedrawNeededAsync
(android.view.SurfaceHolder holder, Runnable drawingFinished)
-
Field Details
-
screenScale
public float screenScaleScreen scale -
attachedView
public android.view.View attachedViewView where this render is attached -
surfaceWidth
public int surfaceWidthSurface width -
surfaceHeight
public int surfaceHeightSurface height
-
-
Constructor Details
-
GLMapViewRenderer
public GLMapViewRenderer(android.content.Context context) Default constructor- Parameters:
context
- context
-
-
Method Details
-
dispose
public void dispose()Description copied from class:GLNativeObject
Call this method when object does not needed. This will free some native resources.- Overrides:
dispose
in classGLNativeObject
-
attachToTextureView
public boolean attachToTextureView(@NonNull android.view.TextureView textureView) Attach renderer to texture view- Parameters:
textureView
- texture view where renderer will be attached- Returns:
- true if restored. false if creates new surface
-
attachToSurfaceView
public void attachToSurfaceView(@NonNull android.view.SurfaceView surfaceView) Attach renderer to surface view- Parameters:
surfaceView
- surface view where renderer will be attached
-
surfaceChanged
public void surfaceChanged(android.view.SurfaceHolder holder, int format, int width, int height) - Specified by:
surfaceChanged
in interfaceandroid.view.SurfaceHolder.Callback
-
surfaceCreated
public void surfaceCreated(android.view.SurfaceHolder holder) - Specified by:
surfaceCreated
in interfaceandroid.view.SurfaceHolder.Callback
-
surfaceDestroyed
public void surfaceDestroyed(@NonNull android.view.SurfaceHolder holder) - Specified by:
surfaceDestroyed
in interfaceandroid.view.SurfaceHolder.Callback
-
surfaceRedrawNeededAsync
public void surfaceRedrawNeededAsync(@NonNull android.view.SurfaceHolder holder, Runnable drawingFinished) - Specified by:
surfaceRedrawNeededAsync
in interfaceandroid.view.SurfaceHolder.Callback2
-
surfaceRedrawNeeded
public void surfaceRedrawNeeded(@NonNull android.view.SurfaceHolder holder) - Specified by:
surfaceRedrawNeeded
in interfaceandroid.view.SurfaceHolder.Callback2
-
onSurfaceTextureAvailable
public void onSurfaceTextureAvailable(@NonNull android.graphics.SurfaceTexture surfaceTexture, int width, int height) - Specified by:
onSurfaceTextureAvailable
in interfaceandroid.view.TextureView.SurfaceTextureListener
-
onSurfaceTextureSizeChanged
public void onSurfaceTextureSizeChanged(@NonNull android.graphics.SurfaceTexture surfaceTexture, int width, int height) - Specified by:
onSurfaceTextureSizeChanged
in interfaceandroid.view.TextureView.SurfaceTextureListener
-
onSurfaceTextureDestroyed
public boolean onSurfaceTextureDestroyed(@NonNull android.graphics.SurfaceTexture surfaceTexture) - Specified by:
onSurfaceTextureDestroyed
in interfaceandroid.view.TextureView.SurfaceTextureListener
-
onSurfaceTextureUpdated
public void onSurfaceTextureUpdated(@NonNull android.graphics.SurfaceTexture surfaceTexture) - Specified by:
onSurfaceTextureUpdated
in interfaceandroid.view.TextureView.SurfaceTextureListener
-
getFps
public float getFps()Returns fps- Returns:
- fps
-
setFps
public void setFps(float fps) Sets fps- Parameters:
fps
- fps to set
-
setCenterTileStateChangedCallback
Set callback that will be called when center tile state is changed- Parameters:
callback
- Runnable that will be post to main thread when center tile state is changed
-
getCenterTileState
public int getCenterTileState()Return state of center tile- Returns:
- state of center tile
-
convertDisplayDeltaToInternal
Converts a distance between two points on the screen to delta in internal format of GLMapView.- Parameters:
val
- The point with the delta- Returns:
- The same object that was passed to method call.
- See Also:
-
convertDisplayDeltaToInternal
@NonNull public MapPoint convertDisplayDeltaToInternal(@NonNull MapPoint val, double mapZoom, float mapAngle) Converts a distance between two points on the screen to delta in internal format of GLMapView.- Parameters:
val
- The point with the deltamapZoom
- Zoom to use for calculationsmapAngle
- Angle to use for calculations- Returns:
- The same object that was passed to method call.
- See Also:
-
convertDisplayToInternal
Converts a point on the surface to an internal map coordinate.MapPoint pt = mapView.convertDisplayToInternal(new MapPoint(touchX, touchY));
- Parameters:
val
- The point on surface to be converted- Returns:
- The same object that was passed to method call.
- See Also:
-
convertInternalToDisplay
Converts a point in internal format of GLMapView to point on the surface of view.- Parameters:
val
- The point to be converted- Returns:
- The same object that was passed to method call.
- See Also:
-
convertMetersToInternal
public double convertMetersToInternal(double meters) Converts meters distance to internal distance- Parameters:
meters
- The value to be converted- Returns:
- Returns distance in internal units
-
doWhenSurfaceCreated
Runs command on internal rendering thread. If surface does not exists at this moment Runnable will be executed when it will be created.final GLMapView mapView = (GLMapView) this.findViewById(R.id.map_view); mapView.doWhenSurfaceCreated(new Runnable() { public void run() { mapView.setMapCenter(center, false); mapView.scaleMap(scaleChange, null, false); } });
- Parameters:
r
- The Runnable to be executed at internal thread when surface will be created
-
setStyle
Sets map style- Parameters:
style
- style to use for map
-
setLocaleSettings
Sets map locale settings- Parameters:
localeSettings
- New locale settings to use for translating map labels
-
getLocaleSettings
Retrieves the previously set locale settings.- Returns:
- The
GLMapLocaleSettings
instance that was previously set.
-
setBase
Sets the base tile source. By default, the base is a vector tile source.- Parameters:
base
- TheGLMapTileSource
to use as the base tile source.
-
setOverlays
Sets the overlay tile sources. By default, overlays arenull
.- Parameters:
overlays
- An array ofGLMapTileSource
instances to use as overlays, ornull
to remove overlays.
-
getOverlays
Retrieves the overlay tile sources that were previously set.- Returns:
- An array of
GLMapTileSource
instances representing the current overlays, ornull
if no overlays were set.
-
getBase
Retrieves the base tile source that was previously set.- Returns:
- The
GLMapTileSource
instance representing the current base tile source, ornull
if no base source was set.
-
setDrawElevationLines
public void setDrawElevationLines(boolean drawElevationLines) Sets the visibility of elevation lines. By default, elevation lines are not drawn (false
).- Parameters:
drawElevationLines
-true
to enable elevation line visibility,false
to disable it.
-
getDrawElevationLines
public boolean getDrawElevationLines()Retrieves the visibility state of elevation lines.- Returns:
true
if elevation lines are visible,false
otherwise.
-
setDrawHillshades
public void setDrawHillshades(boolean drawHillshades) Sets the visibility of hill shades. By default, hill shades are not drawn (false
).- Parameters:
drawHillshades
-true
to enable hill shade visibility,false
to disable it.
-
getDrawHillshades
public boolean getDrawHillshades()Retrieves the visibility state of hill shades.- Returns:
true
if hill shades are visible,false
otherwise.
-
setDrawSlopes
public void setDrawSlopes(boolean drawSlopes) Sets the visibility of slopes. By default, slopes are not drawn (false
).- Parameters:
drawSlopes
-true
to enable slope visibility,false
to disable it.
-
getDrawSlopes
public boolean getDrawSlopes()Retrieves the visibility state of slopes.- Returns:
true
if slopes are visible,false
otherwise.
-
captureFrameWhenFinish
Captures frame when surface will be created and loading of resources finished.ScreenCaptureCallback
provides Bitmap as a result- Parameters:
callback
- ScreenCaptureCallback to call with result
-
mapZoomForBBox
Calculates zoom of map to fit given bbox- Parameters:
bbox
- bbox that you wish to fitmapWidth
- width of visible areamapHeight
- height of visible area- Returns:
- zoom of map to fit given bbox or NaN if bbox is empty.
-
getMapCenter
Gets coordinates of the origin point of the map. If animation is in progress - this value returns final value.MapPoint pt = mapView.getMapCenter(new MapPoint());
- Parameters:
point
- The point to be filled with values.- Returns:
- The same object that was passed to method call.
- See Also:
-
getCurrentMapCenter
Gets current coordinates of the origin point of the map.- Parameters:
point
- The point to be filled with values.- Returns:
- The same object that was passed to method call.
-
getMapCenter
Retrieves the coordinates of the center point of the map.Example usage:
MapPoint pt = mapView.getMapCenter();
- Returns:
- A
MapPoint
object representing the coordinates of the map's center point. - See Also:
-
setMapCenter
Sets the coordinates of the center point of the map.Example usage:
mapView.setMapCenter(center);
- Parameters:
center
- AMapPoint
object representing the new center coordinates of the map.- See Also:
-
getMapGeoCenter
Retrieves the coordinates of the center point of the map.Example usage:
MapPoint pt = mapView.getMapGeoCenter();
- Returns:
- A
MapGeoPoint
object representing the coordinates of the map's center point. - See Also:
-
setMapGeoCenter
Sets the coordinates of the center point of the map.Example usage:
mapView.setMapGeoCenter(center);
- Parameters:
geoCenter
- AMapGeoPoint
object representing the new center coordinates of the map.- See Also:
-
getMapOrigin
Retrieves the origin point of the map coordinate system and fills the providedMapPoint
object with its values. -
getMapOrigin
Retrieves the origin point of the map coordinate system.- Returns:
- A new
MapPoint
object containing the origin coordinates of the map.
-
setMapOrigin
public void setMapOrigin(float x, float y) Sets the origin point of the map coordinate system (X, Y).Changing the values within the range [0, 1] in relative coordinates specifies the point in the
GLMapView
that is considered the center point for `mapCenter` and `setMapCenter`.- Parameters:
x
- The X-coordinate of the origin point, in relative coordinates.y
- The Y-coordinate of the origin point, in relative coordinates.
-
setSafeArea
public void setSafeArea(int left, int top, int right, int bottom) Sets the safe area insets for the scale ruler and other map objects.The safe area defines the padding around the map view where interactive or visual elements like the scale ruler should not be placed.
- Parameters:
left
- The left inset, in pixels.top
- The top inset, in pixels.right
- The right inset, in pixels.bottom
- The bottom inset, in pixels.
-
getBBox
Retrieves the bounding box (BBox) of the currently visible part of theGLMapView
.- Returns:
- A
GLMapBBox
object representing the visible portion of the map.
-
getBBoxWithInsets
Retrieves the bounding box (BBox) of the visible part of theGLMapView
with applied insets.If an animation is in progress, the method returns the final BBox value as it will appear after the animation completes.
- Parameters:
left
- The left inset, in pixels.right
- The right inset, in pixels.top
- The top inset, in pixels.bottom
- The bottom inset, in pixels.- Returns:
- A
GLMapBBox
object representing the visible portion of the map with the specified insets applied.
-
enableClipping
Enables clipping of the visible map area using the specified bounding box (BBox) and zoom levels.- Parameters:
bbox
- TheGLMapBBox
object defining the area to clip.minLevel
- The minimum zoom level where the clipping is active.maxLevel
- The maximum zoom level where the clipping is active.
-
disableClipping
public void disableClipping()Disables clipping of visible map area -
isClippingEnabled
public boolean isClippingEnabled()Checks if clipping is enabled- Returns:
- true if enabled
-
setFontScale
public void setFontScale(float scale) Sets the scale of the font used in the map. This method will automatically trigger a tile reload.- Parameters:
scale
- The new font scale. The default value is1
.
-
getFontScale
public float getFontScale()Retrieves the current font scale.- Returns:
- The current font scale as a
float
.
-
getMapAngle
public float getMapAngle()Gets current angle of the map.- Returns:
- Current angle of the map.
-
setMapAngle
public void setMapAngle(float newAngle) Sets angle of the map.- Parameters:
newAngle
- new angle for map.- See Also:
-
getMapPitch
public float getMapPitch()Gets current pitch of the map.- Returns:
- Current pitch of the map.
-
setMapPitch
public void setMapPitch(float newAngle) Sets pitch of the map.- Parameters:
newAngle
- new pitch for map.- See Also:
-
getMapZoom
public double getMapZoom()Get zoom level of the map. If animation is in progress final value will return.double zoom = mapView.getMapZoom();
- Returns:
- Current zoom of the map.
- See Also:
-
getCurrentMapZoom
public double getCurrentMapZoom()Gets current zoom level of the map.double zoom = mapView.getCurrentMapZoom();
- Returns:
- Current zoom of the map.
- See Also:
-
getCurrentMapScale
public double getCurrentMapScale()Gets current scale of the map.- Returns:
- current scale of the map
-
getMapScale
public double getMapScale()Gets scale of the map.- Returns:
- scale of the map
- See Also:
-
setMapZoom
public void setMapZoom(double newZoom) Sets zoom level of the map.mapView.setMapZoom(16);
- Parameters:
newZoom
- new zoom level for map.- See Also:
-
setMaxScale
public void setMaxScale(double maxScale) Sets maximum scale of the map- Parameters:
maxScale
- max scale to set
-
getMaxScale
public double getMaxScale()Gets maximum scale of the map- Returns:
- maximum scale of the map
-
setMapScale
public void setMapScale(double newScale) Set scale of the map. Same as setMapZoom(pow(2, zoomLevel)). If animation is in progress final value will return.- Parameters:
newScale
- new scale for map.- See Also:
-
setAttributionPosition
public void setAttributionPosition(int placement) Sets the position of the map attribution. The default attribution text is "GLOBUS | © OpenStreetMap". If you are using map data from another provider, you should specify the appropriate attribution text.
Note: You may choose to hide the attribution on the map by setting the position to `GLMapPlacement_Hidden`. However, in this case, it is mandatory to display the attribution within the application's settings. When the attribution is tapped, it may navigate to https://globus.software/about/ and https://www.openstreetmap.org/about/ See Interactive MapsmapView.setAttributionPosition(GLMapPlacement.TopCenter);
- Parameters:
placement
- placement of attribution
-
removeAllObjects
public void removeAllObjects()Removes all images, image groups, tracks, and marker layers from the map.- See Also:
-
add
Adds aGLMapDrawObject
to the map.- Parameters:
drawObject
- TheGLMapDrawObject
to add to the map.- See Also:
-
remove
Removes aGLMapDrawObject
from the map.- Parameters:
drawObject
- TheGLMapDrawObject
to remove from the map.- See Also:
-
changeDrawOrder
Changes the draw order of the specifiedGLMapDrawObject
.- Parameters:
drawObject
- TheGLMapDrawObject
whose draw order should be modified.drawOrder
- The new draw order value for the object.- See Also:
-
startAnimation
Starts the specified animation on the map.- Parameters:
animation
- TheGLMapAnimation
to start.
-
cancelMapAnimations
public void cancelMapAnimations()Cancels all active animations on the map. -
addTextForbiddenArea
public void addTextForbiddenArea(int name, MapPoint origin, int offsetX, int offsetY, int width, int height) Adds or updates area where text (and associated icon) must not draw- Parameters:
name
- unique name for areaorigin
- origin of areaoffsetX
- x offset of area from origin (in points)offsetY
- y offset of area from origin (in points)width
- width of area (in points)height
- height of area (in points)
-
removeTextForbiddenArea
public void removeTextForbiddenArea(int name) Removes area- Parameters:
name
- name of area
-
animate
Create and starts animation using provided callback- Parameters:
callback
- Callback that will configure animation- Returns:
- created animation.
-
animate
@NonNull public GLMapAnimation animate(@NonNull GLMapViewRenderer.AnimateCallback callback, @Nullable Runnable onFinish) Create and starts animation using provided callback- Parameters:
callback
- Callback that will configure animationonFinish
- Callback that will be called when animation is finished- Returns:
- created animation.
-
reloadTiles
public void reloadTiles()Force reloading of all tiles. -
setNeedRedraw
public void setNeedRedraw()Force redraw -
setMapDidMoveCallback
Sets callback that will be called after move animation finished- Parameters:
callback
- callback that will be post to ui thread after animation finished
-
ForceOpenGL2
public static void ForceOpenGL2()After calling this function any new GLMapView will use OpenGL 2.0 even if device supports OpenGL 3.0 Some cheap Android devices have problems with drivers. -
DisableOpenGLBackgroundLoading
public static void DisableOpenGLBackgroundLoading()Call this function before creating GLMapView to disable background loading of resources. In most cases this greatly speedup application, but some cheap Android devices can not handle it properly and this leads to lags or even crashes. -
crashNDK
public static void crashNDK()Function to test native crashes -
crashNDK2
public static void crashNDK2()Function to test native crashes
-