Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

2600 offset map center #3523

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/mbgl/ios/MGLMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ IB_DESIGNABLE
/** The button shown in the lower-right of the map which when pressed displays the map attribution information. */
@property (nonatomic, readonly) UIButton *attributionButton;

/** Defines with insets an area where the contents (marker, user position) of the map will be centered.*/
@property (nonatomic) UIEdgeInsets mapViewInsets;

#pragma mark - Accessing the Delegate

/** @name Accessing the Delegate */
Expand Down
5 changes: 5 additions & 0 deletions include/mbgl/map/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class Map : private util::noncopyable {
// Pitch
void setPitch(double pitch, const Duration& = Duration::zero());
double getPitch() const;
void setPitching(bool pitching);

// North Orientation
void setNorthOrientation(NorthOrientation);
Expand Down Expand Up @@ -187,6 +188,10 @@ class Map : private util::noncopyable {

bool isFullyLoaded() const;
void dumpDebugLogs() const;

// Insets
void setInsets(EdgeInsets insets);
EdgeInsets getInsets() const;

private:
View& view;
Expand Down
2 changes: 2 additions & 0 deletions include/mbgl/map/view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <functional>
#include <memory>

#include <mbgl/map/map.hpp>

namespace mbgl {

class Map;
Expand Down
17 changes: 17 additions & 0 deletions ios/app/MBXDebugView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// MBXDebugView.h
// ios
//
// Created by Mappy SA on 04/01/2016.
//
//

#import <UIKit/UIKit.h>

@interface MBXDebugView : UIView

@property (nonatomic, assign) UIEdgeInsets insets;

- (instancetype)initWithFrame:(CGRect)frame andWithInsets:(UIEdgeInsets) insets;

@end
39 changes: 39 additions & 0 deletions ios/app/MBXDebugView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// MBXDebugView.m
// ios
//
// Created by Mappy SA on 04/01/2016.
//
//

#import "MBXDebugView.h"

@implementation MBXDebugView

- (instancetype)initWithFrame:(CGRect)frame andWithInsets:(UIEdgeInsets) insets {
if (self = [super initWithFrame:frame]) {
self.insets = insets;
self.backgroundColor = [UIColor clearColor];
[self setUserInteractionEnabled:NO];
}
return self;
}

- (void)drawRect:(__unused CGRect) rect{
UIEdgeInsets insets = self.insets;
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect insetsRect = CGRectMake(insets.left,
insets.top,
self.frame.size.width - insets.right - insets.left,
self.frame.size.height - insets.bottom - insets.top);

UIColor * redColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];

CGContextSetStrokeColorWithColor(context, redColor.CGColor);
CGContextStrokeRect(context, insetsRect);
CGPoint center = CGPointMake(CGRectGetMidX(insetsRect), CGRectGetMidY(insetsRect));
CGRect circleRect = CGRectMake(center.x - 10, center.y - 10, 20, 20);
CGContextStrokeEllipseInRect(context, circleRect);
}

@end
6 changes: 6 additions & 0 deletions ios/app/MBXViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#import <CoreLocation/CoreLocation.h>
#import <OpenGLES/ES2/gl.h>

#import "MBXDebugView.h"

static UIColor *const kTintColor = [UIColor colorWithRed:0.120 green:0.550 blue:0.670 alpha:1.000];

static const CLLocationCoordinate2D WorldTourDestinations[] = {
Expand Down Expand Up @@ -61,6 +63,7 @@ - (void)viewDidLoad
[super viewDidLoad];

self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds];
self.mapView.mapViewInsets = UIEdgeInsetsMake(0, 300, 200, 0);
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.mapView.delegate = self;
[self.view addSubview:self.mapView];
Expand Down Expand Up @@ -91,6 +94,9 @@ - (void)viewDidLoad
[self.mapView addGestureRecognizer:[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]];

[self restoreState:nil];

MBXDebugView *debugView = [[MBXDebugView alloc] initWithFrame:self.mapView.frame andWithInsets:self.mapView.mapViewInsets];
[self.view addSubview:debugView];
}

- (void)saveState:(__unused NSNotification *)notification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.annotations.InfoWindow;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdate;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
Expand Down Expand Up @@ -1368,6 +1368,10 @@ public void setZoomLevel(@FloatRange(from = 0.0, to = MAXIMUM_ZOOM_LEVEL) double
mNativeMapView.setZoom(zoomLevel, duration);
}

public void setMapPadding(int left, int top, int right, int bottom) {
mNativeMapView.setInsets(top / mScreenDensity, left / mScreenDensity, bottom / mScreenDensity, right / mScreenDensity);
}

/**
* Returns whether the user may zoom the map.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ public void removeCustomLayer(String id) {
nativeRemoveCustomLayer(mNativeMapViewPtr, id);
}

public void setInsets(double top, double left, double bottom, double right) {nativeSetInsets(mNativeMapViewPtr, top, left, bottom, right);}

//
// Callbacks
//
Expand Down Expand Up @@ -658,4 +660,6 @@ private native void nativeSetVisibleCoordinateBounds(long mNativeMapViewPtr, Lat
private native void nativeAddCustomLayer(long nativeMapViewPtr, CustomLayer customLayer, String before);

private native void nativeRemoveCustomLayer(long nativeMapViewPtr, String id);

private native void nativeSetInsets(long nativeMapViewPtr, double top, double left, double bottom, double right);
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public class MainActivity extends AppCompatActivity {

// Used for info window
private static final DecimalFormat LAT_LON_FORMATTER = new DecimalFormat("#.#####");
public static final int LEFT = 100;
public static final int TOP = 400;
public static final int RIGHT = 200;
public static final int BOTTOM = 10;

//
// Instance members
Expand Down Expand Up @@ -178,6 +182,9 @@ public void onMyLocationChange(@Nullable Location location) {
}
});

findViewById(R.id.debugView).setPadding(LEFT, TOP, RIGHT, BOTTOM);
mMapView.setMapPadding(LEFT, TOP, RIGHT, BOTTOM);

mFpsTextView = (TextView) findViewById(R.id.view_fps);
mFpsTextView.setText("");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:color="#00F" android:width="2dp"/>
<solid android:color="#40F0"/>
</shape>
Original file line number Diff line number Diff line change
@@ -1,69 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/primary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>

<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar">
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar">

<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.mapbox.mapboxsdk.views.MapView
android:id="@+id/mainMapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:id="@+id/mainMapView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<TextView
android:id="@+id/view_fps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@string/label_fps"
android:textAppearance="?android:attr/textAppearanceLarge" />
android:id="@+id/view_fps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@string/label_fps"
android:textAppearance="?android:attr/textAppearanceLarge"/>


<android.support.design.widget.FloatingActionButton
android:id="@+id/locationFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_gps_fixed_24dp"
app:backgroundTint="@color/white" />
android:id="@+id/locationFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_gps_fixed_24dp"
app:backgroundTint="@color/white"/>

</android.support.design.widget.CoordinatorLayout>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/debugView">


<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/debug_view_background">
<View android:layout_width="1dip" android:layout_height="15dip"
android:layout_centerInParent="true"
android:background="#00F"/>
<View android:layout_width="15dip" android:layout_height="1dip"
android:layout_centerInParent="true"
android:background="#00F"/>
</RelativeLayout>
</RelativeLayout>

</FrameLayout>

</RelativeLayout>

<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="@menu/menu_drawer" />
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="@menu/menu_drawer"/>

</android.support.v4.widget.DrawerLayout>
10 changes: 10 additions & 0 deletions platform/android/src/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,14 @@ void JNICALL nativeEaseTo(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdou
nativeMapView->getMap().easeTo(options);
}

void JNICALL nativeSetInsets(JNIEnv *env, jobject obj,long nativeMapViewPtr, double top, double left, double bottom, double right) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeSetInsets");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
mbgl::EdgeInsets insets = {top, left, bottom, right};
nativeMapView->setInsets(insets);
}

void JNICALL nativeFlyTo(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jdouble angle, jobject centerLatLng, jlong duration, jdouble pitch, jdouble zoom) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeFlyTo");
assert(nativeMapViewPtr != 0);
Expand Down Expand Up @@ -2130,6 +2138,8 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
reinterpret_cast<void *>(&nativeAddCustomLayer)},
{"nativeRemoveCustomLayer", "(JLjava/lang/String;)V",
reinterpret_cast<void *>(&nativeRemoveCustomLayer)},
{"nativeSetInsets", "(JDDDD)V",
reinterpret_cast<void *>(&nativeSetInsets)}
};

if (env->RegisterNatives(nativeMapViewClass, methods.data(), methods.size()) < 0) {
Expand Down
7 changes: 7 additions & 0 deletions platform/android/src/native_map_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,5 +751,12 @@ void NativeMapView::resizeFramebuffer(int w, int h) {
map->update(mbgl::Update::Repaint);
}

void NativeMapView::setInsets(EdgeInsets insets) {
map->setInsets(insets);
}

EdgeInsets NativeMapView::getInsets() {
return map->getInsets();
}
}
}
3 changes: 3 additions & 0 deletions platform/android/src/native_map_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class NativeMapView : public mbgl::View, private mbgl::util::noncopyable {
void resizeView(int width, int height);
void resizeFramebuffer(int width, int height);

void setInsets(EdgeInsets insets);
EdgeInsets getInsets();

private:
EGLConfig chooseConfig(const EGLConfig configs[], EGLint numConfigs);

Expand Down
Loading