diff options
author | Tobrun <tobrun@mapbox.com> | 2016-04-21 10:50:01 +0200 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2016-05-20 12:00:01 +0200 |
commit | 028ef7a32356ffce8ba66b203016445e02637644 (patch) | |
tree | b04e8d8e228c29125533a18919335fb7df232f7f /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java | |
parent | ef257c257d8ba681005c3b7ce4618b09caaa0f37 (diff) | |
download | qtlocation-mapboxgl-028ef7a32356ffce8ba66b203016445e02637644.tar.gz |
[android] #3276 - WIP Android View Annotations, showing an Android SDK view on the screen
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java new file mode 100644 index 0000000000..3e9d120343 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java @@ -0,0 +1,69 @@ +package com.mapbox.mapboxsdk.annotations; + +import android.content.Context; +import android.graphics.PointF; +import android.util.AttributeSet; +import android.util.Log; +import android.view.ViewGroup; +import android.widget.FrameLayout; + +import com.mapbox.mapboxsdk.constants.MapboxConstants; +import com.mapbox.mapboxsdk.geometry.LatLng; +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.Projection; + +public class MarkerView extends FrameLayout { + + private LatLng latLng; + private Projection projection; + private Marker marker; + + private float widthOffset; + private float heightOffset; + + public MarkerView(Context context) { + super(context); + init(context); + } + + public MarkerView(Context context, AttributeSet attrs) { + super(context, attrs); + init(context); + } + + public MarkerView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(context); + } + + private void init(Context context){ + setLayoutParams(new MapView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + } + + public void setProjection(Projection projection) { + this.projection = projection; + } + + public void setLatLng(LatLng latLng) { + this.latLng = latLng; + } + + public void setMarker(Marker marker) { + this.marker = marker; + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + widthOffset = getMeasuredWidth() / 2; + heightOffset = getMeasuredHeight() / 2; + + Log.v(MapboxConstants.TAG,"Measure "+widthOffset + heightOffset); + } + + public void update() { + PointF point = projection.toScreenLocation(latLng); + setX(point.x - widthOffset); + setY(point.y - heightOffset); + } +} |