GithubHelp home page GithubHelp logo

tuonbondol / mapscaleview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pengrad/mapscaleview

0.0 2.0 0.0 669 KB

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

License: Apache License 2.0

Java 100.00%

mapscaleview's Introduction

Map Scale View

Download Android Arsenal

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

Image

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 to start with.

Usage

dependencies {
    implementation 'com.github.pengrad:mapscaleview:1.4.2'
}

Include in layout file over map

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/mapFragment"
        class="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <com.github.pengrad.mapscaleview.MapScaleView
        android:id="@+id/scaleView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="4dp"/>
</FrameLayout>

With miles or custom style

<com.github.pengrad.mapscaleview.MapScaleView
        android:id="@+id/scaleView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="4dp"
        app:scale_color="#009"
        app:scale_miles="true"
        app:scale_outline="true"
        app:scale_strokeWidth="3dp"
        app:scale_textSize="20sp"
        app:scale_expandRtl="true"/>

Update on map changed

MapScaleView scaleView = (MapScaleView) findViewById(R.id.scaleView);
CameraPosition cameraPosition = map.getCameraPosition();
// need to pass zoom and latitude
scaleView.update(cameraPosition.zoom, cameraPosition.target.latitude);

Full example with subscribing to map events and updating scale view

@Override
public void onMapReady(GoogleMap googleMap) {
    map = googleMap;
    googleMap.setOnCameraMoveListener(this);
    googleMap.setOnCameraIdleListener(this);
    googleMap.setOnCameraChangeListener(this);
}

@Override
public void onCameraMove() {
    CameraPosition cameraPosition = map.getCameraPosition();
    scaleView.update(cameraPosition.zoom, cameraPosition.target.latitude);
}

@Override
public void onCameraIdle() {
    CameraPosition cameraPosition = map.getCameraPosition();
    scaleView.update(cameraPosition.zoom, cameraPosition.target.latitude);
}

@Override
public void onCameraChange(CameraPosition cameraPosition) {
    scaleView.update(cameraPosition.zoom, cameraPosition.target.latitude);
}

Customization

mapScaleView.setColor(@ColorInt int color)
mapScaleView.setTextSize(float textSize)
mapScaleView.setStrokeWidth(float strokeWidth)

// enable/disable white outline
mapScaleView.setOutlineEnabled(boolean enabled)

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

// expand scale bar from right to left
mapScaleView.setExpandRtlEnabled(true)

mapscaleview's People

Contributors

pengrad avatar kptlronyttcna avatar

Watchers

James Cloos avatar Tuon Bondol avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.