Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/pengrad/MapScaleView

Scale bar for Android Maps (Google Maps, OSM, MapBox, Yandex)
https://github.com/pengrad/MapScaleView

android-maps

Last synced: 3 months ago
JSON representation

Scale bar for Android Maps (Google Maps, OSM, MapBox, Yandex)

Awesome Lists containing this project

README

        

# Map Scale View
[ ![Download](https://api.bintray.com/packages/pengrad/maven/mapscaleview/images/download.svg) ](https://bintray.com/pengrad/maven/mapscaleview/_latestVersion)
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-MapScaleView-green.svg?style=true)](https://android-arsenal.com/details/1/4541)

Scale view for any Android Maps SDK (not only Google Maps)

![Image](images/image_rtl.png)

## Contributing
I encourage you to participate in this project. Feel free to open issues with bugs or ideas, fork and send pull requests.
Check [list of "help wanted" issues](https://github.com/pengrad/MapScaleView/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) to start with.

## Usage
```groovy
dependencies {
implementation 'com.github.pengrad:mapscaleview:1.6.0'
}
```

Include in layout file over map
```xml

```

With miles or custom style
```xml

```

Update on map changed
```kotlin
val scaleView: MapScaleView = findViewById(R.id.scaleView)
val cameraPosition = map.cameraPosition
// need to pass zoom and latitude
scaleView.update(cameraPosition.zoom, cameraPosition.target.latitude)
```

Full example with subscribing to map events and updating scale view
```kotlin
override fun onMapReady(googleMap: GoogleMap) {
map = googleMap
googleMap.setOnCameraMoveListener(this)
googleMap.setOnCameraIdleListener(this)
}

override fun onCameraMove() {
val cameraPosition = map.cameraPosition
scaleView.update(cameraPosition.zoom, cameraPosition.target.latitude)
}

override fun onCameraIdle() {
val cameraPosition = map.cameraPosition
scaleView.update(cameraPosition.zoom, cameraPosition.target.latitude)
}
```

Refer to the sample project on how to use scale view with other Android Maps SDK (Mapbox).

## Customization
```java
mapScaleView.setColor(@ColorInt int color)
mapScaleView.setTextSize(float textSize)
mapScaleView.setStrokeWidth(float strokeWidth)
mapScaleView.setTextFont(Typeface font)

// enable/disable white outline, enabled by default
mapScaleView.setOutlineEnabled(false)

mapScaleView.metersAndMiles() // default
mapScaleView.metersOnly()
mapScaleView.milesOnly()

// expand scale bar from right to left, disabled by default
mapScaleView.setExpandRtlEnabled(true)
```