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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceGLMapViewRenderer.AnimateCallbackCalled to configure animation.static interfaceGLMapViewRenderer.GLMapPlacementstatic interfaceGLMapViewRenderer.GLMapTileStatestatic interfaceGLMapViewRenderer.ScreenCaptureCallbackCalled when GLMapView finished rendering map and text to Bitmapstatic interfaceGLMapViewRenderer.ScreenCaptureRawCallbackCalled when GLMapView finished rendering map and text to raw data
-
Field Summary
Fields Modifier and Type Field Description android.view.ViewattachedViewfloatscreenScaleintsurfaceHeightintsurfaceWidth
-
Constructor Summary
Constructors Constructor Description GLMapViewRenderer(android.app.Activity activity)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(GLMapDrawObject drawObject)Adds the GLMapDrawObject to map.GLMapAnimationanimate(GLMapViewRenderer.AnimateCallback callback)Create and starts animation using provided callbackGLMapAnimationanimate(GLMapViewRenderer.AnimateCallback callback, java.lang.Runnable onFinish)Create and starts animation using provided callbackvoidattachToSurfaceView(android.content.Context context, android.view.SurfaceView surfaceView)booleanattachToTextureView(android.content.Context context, android.view.TextureView textureView)voidcaptureFrameWhenFinish(GLMapViewRenderer.ScreenCaptureCallback callback)Captures frame when surface will be created and loading of resources finished.MapPointconvertDisplayDeltaToInternal(MapPoint val)Converts a distance between two points on the screen to delta in internal format of GLMapView.MapPointconvertDisplayDeltaToInternal(MapPoint val, double mapZoom, double mapAngle)Converts a distance between two points on the screen to delta in internal format of GLMapView.MapPointconvertDisplayToInternal(MapPoint val)Converts a point on the surface to an internal map coordinate.MapPointconvertInternalToDisplay(MapPoint val)Converts a point in internal format of GLMapView to point on the surface of view.doubleconvertMetersToInternal(double meters)Converts meters distance to internal distancestatic voidcrashNDK()static voidcrashNDK2()voiddisableClipping()Disables clipping of visible map areavoiddispose()voiddoWhenSurfaceCreated(java.lang.Runnable r)Runs command on internal rendering thread.voidenableClipping(GLMapBBox bbox, float minLevel, float maxLevel)Enables clipping of visible map areastatic voidForceOpenGL2()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.GLMapTileSourcegetBase()GLMapBBoxgetBBox()BBox of current visible part of GLMapViewintgetCenterTileState()Return state of center tileMapPointgetCurrentMapCenter(MapPoint point)Gets current coordinates of the origin point of the map.doublegetCurrentMapScale()Gets current scale of the map.doublegetCurrentMapZoom()Gets current zoom level of the map.booleangetDrawElevationLines()booleangetDrawHillshades()floatgetFontScale()floatgetFps()Returns fpsGLMapLocaleSettingsgetLocaleSettings()floatgetMapAngle()Gets current angle of the map.MapPointgetMapCenter()Gets coordinates of the origin point of the map.MapPointgetMapCenter(MapPoint point)Gets coordinates of the origin point of the map.MapGeoPointgetMapGeoCenter()Gets coordinates of the origin point of the map.MapPointgetMapOrigin()MapPointgetMapOrigin(MapPoint point)Origin point of the map coordinate system.doublegetMapScale()Gets scale of the map.doublegetMapZoom()Get zoom level of the map.doublegetMaxScale()Gets maximum scale of the mapGLMapTileSource[]getOverlays()booleanisClippingEnabled()Checks if clipping is enableddoublemapZoomForBBox(GLMapBBox bbox, int mapWidth, int mapHeight)Calculates zoom of map to fit given bboxvoidonSurfaceTextureAvailable(android.graphics.SurfaceTexture surfaceTexture, int width, int height)booleanonSurfaceTextureDestroyed(android.graphics.SurfaceTexture surfaceTexture)voidonSurfaceTextureSizeChanged(android.graphics.SurfaceTexture surfaceTexture, int width, int height)voidonSurfaceTextureUpdated(android.graphics.SurfaceTexture surfaceTexture)voidreloadTiles()Force reloading of all tiles.voidremove(GLMapDrawObject drawObject)Removes `GLMapDrawObject` from map.voidremoveAllObjects()Remove all images, image groups, tracks and marker layers from mapvoidsetAttributionPosition(int placement)Sets position of attribution.voidsetBase(GLMapTileSource base)By default base is vector tile source.voidsetCenterTileStateChangedCallback(java.lang.Runnable callback)Set callback that will be called when center tile state is changedvoidsetDrawElevationLines(boolean drawElevationLines)Sets visibility of elevation lines.voidsetDrawHillshades(boolean drawHillshades)Sets visibility of hill shades.voidsetFontScale(float scale)Sets scale of font.voidsetFps(float fps)Sets fpsvoidsetLocaleSettings(GLMapLocaleSettings localeSettings)Sets map locale settingsvoidsetMapAngle(float newAngle)Sets zoom level of the map.voidsetMapCenter(MapPoint center)Sets coordinates of the origin point of the map.voidsetMapDidMoveCallback(java.lang.Runnable callback)Sets callback that will be called after move animation finishedvoidsetMapGeoCenter(MapGeoPoint geoCenter)Sets coordinates of the origin point of the map.voidsetMapOrigin(float x, float y)Origin point of the map coordinate system (X, Y).voidsetMapScale(double newScale)Set scale of the map.voidsetMapZoom(double newZoom)Sets zoom level of the map.voidsetMaxScale(double maxScale)Sets maximum scale of the mapvoidsetNeedRedraw()Force redrawvoidsetOverlays(GLMapTileSource[] overlays)By default overlays is null.voidsetScaleRulerBottomText(java.lang.String text)Sets text that will be displayed under scale ruler.voidsetScaleRulerStyle(int placement, int paddingX, int paddingY, double maxWidth)Set style of scale ruler.voidsetStyle(GLMapVectorCascadeStyle style)Sets map stylevoidstartAnimation(GLMapAnimation animation)Starts animation.voidsurfaceChanged(android.view.SurfaceHolder holder, int format, int width, int height)voidsurfaceCreated(android.view.SurfaceHolder holder)voidsurfaceDestroyed(android.view.SurfaceHolder holder)voidsurfaceRedrawNeeded(android.view.SurfaceHolder holder)voidsurfaceRedrawNeededAsync(android.view.SurfaceHolder holder, java.lang.Runnable drawingFinished)
-
-
-
Method Detail
-
dispose
public void dispose()
- Overrides:
disposein classGLNativeObject
-
attachToTextureView
public boolean attachToTextureView(@NonNull android.content.Context context, @NonNull android.view.TextureView textureView)
-
attachToSurfaceView
public void attachToSurfaceView(@NonNull android.content.Context context, @NonNull android.view.SurfaceView surfaceView)
-
surfaceChanged
public void surfaceChanged(android.view.SurfaceHolder holder, int format, int width, int height)- Specified by:
surfaceChangedin interfaceandroid.view.SurfaceHolder.Callback
-
surfaceCreated
public void surfaceCreated(android.view.SurfaceHolder holder)
- Specified by:
surfaceCreatedin interfaceandroid.view.SurfaceHolder.Callback
-
surfaceDestroyed
public void surfaceDestroyed(android.view.SurfaceHolder holder)
- Specified by:
surfaceDestroyedin interfaceandroid.view.SurfaceHolder.Callback
-
surfaceRedrawNeededAsync
public void surfaceRedrawNeededAsync(android.view.SurfaceHolder holder, java.lang.Runnable drawingFinished)- Specified by:
surfaceRedrawNeededAsyncin interfaceandroid.view.SurfaceHolder.Callback2
-
surfaceRedrawNeeded
public void surfaceRedrawNeeded(android.view.SurfaceHolder holder)
- Specified by:
surfaceRedrawNeededin interfaceandroid.view.SurfaceHolder.Callback2
-
onSurfaceTextureAvailable
public void onSurfaceTextureAvailable(android.graphics.SurfaceTexture surfaceTexture, int width, int height)- Specified by:
onSurfaceTextureAvailablein interfaceandroid.view.TextureView.SurfaceTextureListener
-
onSurfaceTextureSizeChanged
public void onSurfaceTextureSizeChanged(android.graphics.SurfaceTexture surfaceTexture, int width, int height)- Specified by:
onSurfaceTextureSizeChangedin interfaceandroid.view.TextureView.SurfaceTextureListener
-
onSurfaceTextureDestroyed
public boolean onSurfaceTextureDestroyed(android.graphics.SurfaceTexture surfaceTexture)
- Specified by:
onSurfaceTextureDestroyedin interfaceandroid.view.TextureView.SurfaceTextureListener
-
onSurfaceTextureUpdated
public void onSurfaceTextureUpdated(android.graphics.SurfaceTexture surfaceTexture)
- Specified by:
onSurfaceTextureUpdatedin 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
public void setCenterTileStateChangedCallback(@Nullable java.lang.Runnable callback)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
public MapPoint convertDisplayDeltaToInternal(@NonNull MapPoint val)
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:
convertDisplayToInternal(MapPoint)
-
convertDisplayDeltaToInternal
@NonNull public MapPoint convertDisplayDeltaToInternal(@NonNull MapPoint val, double mapZoom, double 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(MapPoint)
-
convertDisplayToInternal
@NonNull public MapPoint convertDisplayToInternal(@NonNull MapPoint val)
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(MapPoint)
-
convertInternalToDisplay
@NonNull public MapPoint convertInternalToDisplay(@NonNull MapPoint val)
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:
convertDisplayToInternal(MapPoint)
-
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
public void doWhenSurfaceCreated(@NonNull java.lang.Runnable r)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
public void setStyle(@NonNull GLMapVectorCascadeStyle style)Sets map style- Parameters:
style- style to use for map
-
setLocaleSettings
public void setLocaleSettings(@NonNull GLMapLocaleSettings localeSettings)Sets map locale settings- Parameters:
localeSettings- New locale settings to use for translating map labels
-
getLocaleSettings
@NonNull public GLMapLocaleSettings getLocaleSettings()
- Returns:
- GLMapLocaleSettings that was previously set
-
setBase
public void setBase(@NonNull GLMapTileSource base)By default base is vector tile source.- Parameters:
base- Base to use
-
setOverlays
public void setOverlays(@Nullable GLMapTileSource[] overlays)By default overlays is null.- Parameters:
overlays- Overlays to use
-
getOverlays
@Nullable public GLMapTileSource[] getOverlays()
- Returns:
- value that was previously set.
-
getBase
@Nullable public GLMapTileSource getBase()
- Returns:
- value that was previously set.
-
setDrawElevationLines
public void setDrawElevationLines(boolean drawElevationLines)
Sets visibility of elevation lines. By default is false.- Parameters:
drawElevationLines- visibility of elevation lines
-
getDrawElevationLines
public boolean getDrawElevationLines()
- Returns:
- value that was previously set.
-
setDrawHillshades
public void setDrawHillshades(boolean drawHillshades)
Sets visibility of hill shades. By default is false.- Parameters:
drawHillshades- visibility of hill shades.
-
getDrawHillshades
public boolean getDrawHillshades()
- Returns:
- value that was previously set.
-
captureFrameWhenFinish
public void captureFrameWhenFinish(@NonNull GLMapViewRenderer.ScreenCaptureCallback callback)Captures frame when surface will be created and loading of resources finished.ScreenCaptureCallbackprovides Bitmap as a result- Parameters:
callback- ScreenCaptureCallback to call with result
-
mapZoomForBBox
public double mapZoomForBBox(@NonNull GLMapBBox bbox, int mapWidth, int mapHeight)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
@NonNull public MapPoint getMapCenter(@NonNull MapPoint point)
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:
setMapCenter(MapPoint)
-
getCurrentMapCenter
@NonNull public MapPoint getCurrentMapCenter(@NonNull MapPoint point)
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
@NonNull public MapPoint getMapCenter()
Gets coordinates of the origin point of the map.MapPoint pt = mapView.getMapCenter();- Returns:
- Returns coordinates of map center point.
- See Also:
setMapCenter(MapPoint)
-
setMapCenter
public void setMapCenter(MapPoint center)
Sets coordinates of the origin point of the map.mapView.setMapCenter(center);- Parameters:
center- New map center.- See Also:
getMapCenter(MapPoint)
-
getMapGeoCenter
@NonNull public MapGeoPoint getMapGeoCenter()
Gets coordinates of the origin point of the map.MapPoint pt = mapView.getMapCenter();- Returns:
- Returns coordinates of map center point.
- See Also:
setMapGeoCenter(MapGeoPoint)
-
setMapGeoCenter
public void setMapGeoCenter(@NonNull MapGeoPoint geoCenter)Sets coordinates of the origin point of the map.mapView.setMapGeoCenter(center);- Parameters:
geoCenter- New map center.- See Also:
getMapCenter(MapPoint)
-
getMapOrigin
@NonNull public MapPoint getMapOrigin(@NonNull MapPoint point)
Origin point of the map coordinate system.- Parameters:
point- The point to be filled with values.- Returns:
- The same object that was passed to method call.
-
getMapOrigin
@NonNull public MapPoint getMapOrigin()
- Returns:
- Returns origin point of the map coordinate system.
-
setMapOrigin
public void setMapOrigin(float x, float y)Origin point of the map coordinate system (X, Y). Changing the values in this property between 0 and 1 in relative coordinates describes the point of GLMapView which is considered as a center point for `mapCenter` and `setMapCenter:animated:`.- Parameters:
x- x of originy- y of origin
-
getBBox
@NonNull public GLMapBBox getBBox()
BBox of current visible part of GLMapView- Returns:
- bbox of visible part of GLMapView
-
enableClipping
public void enableClipping(GLMapBBox bbox, float minLevel, float maxLevel)
Enables clipping of visible map area- Parameters:
bbox- clipping bbox to setminLevel- min zoom levelmaxLevel- max zoom level
-
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 scale of font. Will trigger reloadTiles automatically;- Parameters:
scale- New font scale (default is 1).
-
getFontScale
public float getFontScale()
- Returns:
- value of font scale
-
getMapAngle
public float getMapAngle()
Gets current angle of the map.- Returns:
- Current angle of the map.
-
setMapAngle
public void setMapAngle(float newAngle)
Sets zoom level of the map.mapView.setMapZoom(16, false);- Parameters:
newAngle- new zoom level for map.- See Also:
getMapAngle()
-
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:
setMapZoom(double)
-
getCurrentMapZoom
public double getCurrentMapZoom()
Gets current zoom level of the map.double zoom = mapView.getCurrentMapZoom();- Returns:
- Current zoom of the map.
- See Also:
setMapZoom(double)
-
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:
getMapZoom()
-
setMapZoom
public void setMapZoom(double newZoom)
Sets zoom level of the map.mapView.setMapZoom(16);- Parameters:
newZoom- new zoom level for map.- See Also:
getMapZoom()
-
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:
getMapZoom()
-
setScaleRulerStyle
public void setScaleRulerStyle(int placement, int paddingX, int paddingY, double maxWidth)Set style of scale ruler.mapView.setScaleRulerStyle(GLUnitSystem.International, GLMapPlacement.BottomCenter, new MapPoint(10, 10), 200);- Parameters:
placement- alignment of textpaddingX- x padding of scale ruler in pointspaddingY- y padding of scale ruler in pointsmaxWidth- width of scale hit in points
-
setScaleRulerBottomText
public void setScaleRulerBottomText(@Nullable java.lang.String text)Sets text that will be displayed under scale ruler.- Parameters:
text- text to display
-
setAttributionPosition
public void setAttributionPosition(int placement)
Sets position of attribution.mapView.setAttributionPosition(GLMapPlacement.TopCenter);- Parameters:
placement- placement of attribution
-
removeAllObjects
public void removeAllObjects()
Remove all images, image groups, tracks and marker layers from map- See Also:
remove(GLMapDrawObject)
-
add
public void add(@NonNull GLMapDrawObject drawObject)Adds the GLMapDrawObject to map.- Parameters:
drawObject- object to add- See Also:
remove(GLMapDrawObject)
-
remove
public void remove(@NonNull GLMapDrawObject drawObject)Removes `GLMapDrawObject` from map.- Parameters:
drawObject- object to remove- See Also:
add(GLMapDrawObject)
-
startAnimation
public void startAnimation(@NonNull GLMapAnimation animation)Starts animation.- Parameters:
animation- animation to start
-
animate
@NonNull public GLMapAnimation animate(@NonNull GLMapViewRenderer.AnimateCallback callback)
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 java.lang.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
public void setMapDidMoveCallback(@Nullable java.lang.Runnable callback)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.
-
crashNDK
public static void crashNDK()
-
crashNDK2
public static void crashNDK2()
-
-