Skip to content
This repository has been archived by the owner on Mar 26, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release-ios-v3.6.0-android-v5.1.0' into merge_mapbox_v5_1
Browse files Browse the repository at this point in the history
* release-ios-v3.6.0-android-v5.1.0:
  fix trackball long press timeout calling the main thread method on a background thread (mapbox#9305)
  [android] fix pulse marker view options parcelable creator (mapbox#9283)
  [android] fix custom marker views anchor issue (mapbox#9282)
  Validate camera position before transforming (mapbox#9275)
  [android] - update activity test generation with newest classes, make FillExtrusionActivity conform to generated activity test setup. (mapbox#9276)
  [core] Trigger repaint on source changes
  [ios] Update telemetry cert pinning (mapbox#9292)
  [core] Fix composite function approximation for non-integer stops

# Conflicts:
#	platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java
  • Loading branch information
Tran Thuong Tien committed Jun 20, 2017
2 parents 84b2c54 + 78426f1 commit 91b1bac
Show file tree
Hide file tree
Showing 18 changed files with 200 additions and 124 deletions.
75 changes: 53 additions & 22 deletions include/mbgl/style/function/composite_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,16 @@ class CompositeFunction {
defaultValue(std::move(defaultValue_)) {
}

std::tuple<Range<float>, Range<InnerStops>>
coveringRanges(float zoom) const {
struct CoveringRanges {
float zoom;
Range<float> coveringZoomRange;
Range<InnerStops> coveringStopsRange;
};

// Return the relevant stop zoom values and inner stops that bracket a given zoom level. This
// is the first step toward evaluating the function, and is used for in the course of both partial
// evaluation of data-driven paint properties, and full evaluation of data-driven layout properties.
CoveringRanges coveringRanges(float zoom) const {
return stops.match(
[&] (const auto& s) {
assert(!s.stops.empty());
Expand All @@ -63,7 +71,8 @@ class CompositeFunction {
minIt--;
}

return std::make_tuple(
return CoveringRanges {
zoom,
Range<float> {
minIt == s.stops.end() ? s.stops.rbegin()->first : minIt->first,
maxIt == s.stops.end() ? s.stops.rbegin()->first : maxIt->first
Expand All @@ -72,38 +81,49 @@ class CompositeFunction {
s.innerStops(minIt == s.stops.end() ? s.stops.rbegin()->second : minIt->second),
s.innerStops(maxIt == s.stops.end() ? s.stops.rbegin()->second : maxIt->second)
}
);
};
}
);
}

// Given a range of zoom values (typically two adjacent integer zoom levels, e.g. 5.0 and 6.0),
// return the covering ranges for both. This is used in the course of partial evaluation for
// data-driven paint properties.
Range<CoveringRanges> rangeOfCoveringRanges(Range<float> zoomRange) {
return Range<CoveringRanges> {
coveringRanges(zoomRange.min),
coveringRanges(zoomRange.max)
};
}

// Given the covering ranges for range of zoom values (typically two adjacent integer zoom levels,
// e.g. 5.0 and 6.0), and a feature, return the results of fully evaluating the function for that
// feature at each of the two zoom levels. These two results are what go into the paint vertex buffers
// for vertices associated with this feature. The shader will interpolate between them at render time.
template <class Feature>
Range<T> evaluate(Range<InnerStops> coveringStops,
const Feature& feature,
T finalDefaultValue) const {
optional<Value> v = feature.getValue(property);
if (!v) {
return {
Range<T> evaluate(const Range<CoveringRanges>& ranges, const Feature& feature, T finalDefaultValue) {
optional<Value> value = feature.getValue(property);
if (!value) {
return Range<T> {
defaultValue.value_or(finalDefaultValue),
defaultValue.value_or(finalDefaultValue)
};
}
auto eval = [&] (const auto& s) {
return s.evaluate(*v).value_or(defaultValue.value_or(finalDefaultValue));
};
return Range<T> {
coveringStops.min.match(eval),
coveringStops.max.match(eval)
evaluateFinal(ranges.min, *value, finalDefaultValue),
evaluateFinal(ranges.max, *value, finalDefaultValue)
};
}

T evaluate(float zoom, const GeometryTileFeature& feature, T finalDefaultValue) const {
std::tuple<Range<float>, Range<InnerStops>> ranges = coveringRanges(zoom);
Range<T> resultRange = evaluate(std::get<1>(ranges), feature, finalDefaultValue);
return util::interpolate(
resultRange.min,
resultRange.max,
util::interpolationFactor(1.0f, std::get<0>(ranges), zoom));
// Fully evaluate the function for a zoom value and feature. This is used when evaluating data-driven
// layout properties.
template <class Feature>
T evaluate(float zoom, const Feature& feature, T finalDefaultValue) const {
optional<Value> value = feature.getValue(property);
if (!value) {
return defaultValue.value_or(finalDefaultValue);
}
return evaluateFinal(coveringRanges(zoom), *value, finalDefaultValue);
}

friend bool operator==(const CompositeFunction& lhs,
Expand All @@ -115,6 +135,17 @@ class CompositeFunction {
std::string property;
Stops stops;
optional<T> defaultValue;

private:
T evaluateFinal(const CoveringRanges& ranges, const Value& value, T finalDefaultValue) const {
auto eval = [&] (const auto& s) {
return s.evaluate(value).value_or(defaultValue.value_or(finalDefaultValue));
};
return util::interpolate(
ranges.coveringStopsRange.min.match(eval),
ranges.coveringStopsRange.max.match(eval),
util::interpolationFactor(1.0f, ranges.coveringZoomRange, ranges.zoom));
}
};

} // namespace style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ImageView;

import com.mapbox.mapboxsdk.R;
Expand Down Expand Up @@ -38,6 +39,15 @@
public class MarkerViewManager implements MapView.OnMapChangedListener {

private final ViewGroup markerViewContainer;
private final ViewTreeObserver.OnPreDrawListener markerViewPreDrawObserver =
new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
invalidateViewMarkersInVisibleRegion();
markerViewContainer.getViewTreeObserver().removeOnPreDrawListener(markerViewPreDrawObserver);
return false;
}
};
private final Map<MarkerView, View> markerViewMap = new HashMap<>();
private final LongSparseArray<OnMarkerViewAddedListener> markerViewAddedListenerMap = new LongSparseArray<>();
private final List<MapboxMap.MarkerViewAdapter> markerViewAdapters = new ArrayList<>();
Expand Down Expand Up @@ -196,14 +206,16 @@ public void updateMarkerViewsPosition() {
PointF point = mapboxMap.getProjection().toScreenLocation(marker.getPosition());
if (marker.getOffsetX() == MapboxConstants.UNMEASURED) {
// ensure view is measured first
// #6805 invalidate marker views to ensure convertView width and height
// values are properly measured and up to date
if (marker.getWidth() == 0) {
convertView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
if (convertView.getMeasuredWidth() != 0) {
marker.setWidth(convertView.getMeasuredWidth());
marker.setHeight(convertView.getMeasuredHeight());
}
convertView.getViewTreeObserver().addOnPreDrawListener(markerViewPreDrawObserver);
}
}

marker.setWidth(convertView.getWidth());
marker.setHeight(convertView.getHeight());

if (marker.getWidth() != 0) {
int x = (int) (marker.getAnchorU() * marker.getWidth());
int y = (int) (marker.getAnchorV() * marker.getHeight());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mapbox.mapboxsdk.camera;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.mapbox.mapboxsdk.maps.MapboxMap;

Expand All @@ -9,6 +10,7 @@
*/
public interface CameraUpdate {

@Nullable
CameraPosition getCameraPosition(@NonNull MapboxMap mapboxMap);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.graphics.PointF;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.view.KeyEvent;
import android.view.MotionEvent;
Expand Down Expand Up @@ -204,7 +205,7 @@ boolean onTrackballEvent(MotionEvent event) {
currentTrackballLongPressTimeOut = null;
}
currentTrackballLongPressTimeOut = new TrackballLongPressTimeOut();
new Handler().postDelayed(currentTrackballLongPressTimeOut,
new Handler(Looper.getMainLooper()).postDelayed(currentTrackballLongPressTimeOut,
ViewConfiguration.getLongPressTimeout());
return true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public void onMapChanged(@MapView.MapChange int change) {
@UiThread
final void moveCamera(MapboxMap mapboxMap, CameraUpdate update, MapboxMap.CancelableCallback callback) {
CameraPosition cameraPosition = update.getCameraPosition(mapboxMap);
if (cameraPosition!= null && !cameraPosition.equals(this.cameraPosition)) {
//if (cameraPosition!= null && !cameraPosition.equals(this.cameraPosition)) {
if (isValidCameraPosition(cameraPosition)) {
trackingSettings.resetTrackingModesIfRequired(this.cameraPosition, cameraPosition, false);
cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
Expand All @@ -109,7 +110,7 @@ final void moveCamera(MapboxMap mapboxMap, CameraUpdate update, MapboxMap.Cancel
final void easeCamera(MapboxMap mapboxMap, CameraUpdate update, int durationMs, boolean easingInterpolator,
final MapboxMap.CancelableCallback callback, boolean isDismissable) {
CameraPosition cameraPosition = update.getCameraPosition(mapboxMap);
if (cameraPosition!= null && !cameraPosition.equals(this.cameraPosition)) {
if (isValidCameraPosition(cameraPosition)) {
trackingSettings.resetTrackingModesIfRequired(this.cameraPosition, cameraPosition, isDismissable);
cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
Expand All @@ -127,7 +128,7 @@ final void easeCamera(MapboxMap mapboxMap, CameraUpdate update, int durationMs,
final void animateCamera(MapboxMap mapboxMap, CameraUpdate update, int durationMs,
final MapboxMap.CancelableCallback callback) {
CameraPosition cameraPosition = update.getCameraPosition(mapboxMap);
if (cameraPosition!= null && !cameraPosition.equals(this.cameraPosition)) {
if (isValidCameraPosition(cameraPosition)) {
trackingSettings.resetTrackingModesIfRequired(this.cameraPosition, cameraPosition, false);
cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
Expand All @@ -141,6 +142,10 @@ final void animateCamera(MapboxMap mapboxMap, CameraUpdate update, int durationM
}
}

private boolean isValidCameraPosition(@Nullable CameraPosition cameraPosition) {
return cameraPosition != null && !cameraPosition.equals(this.cameraPosition);
}

@UiThread
@Nullable
CameraPosition invalidateCameraPosition() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
public class FillExtrusionActivity extends AppCompatActivity {

private MapView mapView;
private MapboxMap mapboxMap;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand All @@ -36,8 +37,8 @@ public void onCreate(Bundle savedInstanceState) {
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(@NonNull
final MapboxMap map) {
public void onMapReady(@NonNull final MapboxMap map) {
mapboxMap = map;
Polygon domTower = Polygon.fromCoordinates(new double[][][] {
new double[][] {
new double[] {
Expand Down Expand Up @@ -66,7 +67,7 @@ public void onMapReady(@NonNull
GeoJsonSource source = new GeoJsonSource("extrusion-source", domTower);
map.addSource(source);

map.addLayer(
mapboxMap.addLayer(
new FillExtrusionLayer("extrusion-layer", source.getId())
.withProperties(
fillExtrusionHeight(40f),
Expand All @@ -75,7 +76,7 @@ public void onMapReady(@NonNull
)
);

map.animateCamera(
mapboxMap.animateCamera(
CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.target(new LatLng(52.09071040847704, 5.12112557888031))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public PulseMarkerView getMarker() {
return new PulseMarkerView(this);
}

public static final Parcelable.Creator<CountryMarkerViewOptions> CREATOR
= new Parcelable.Creator<CountryMarkerViewOptions>() {
public CountryMarkerViewOptions createFromParcel(Parcel in) {
return new CountryMarkerViewOptions(in);
public static final Parcelable.Creator<PulseMarkerViewOptions> CREATOR
= new Parcelable.Creator<PulseMarkerViewOptions>() {
public PulseMarkerViewOptions createFromParcel(Parcel in) {
return new PulseMarkerViewOptions(in);
}

public CountryMarkerViewOptions[] newArray(int size) {
return new CountryMarkerViewOptions[size];
public PulseMarkerViewOptions[] newArray(int size) {
return new PulseMarkerViewOptions[size];
}
};
}
2 changes: 1 addition & 1 deletion platform/android/scripts/generate-test-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ global.camelize = function (str) {
}


const excludeActivities = ["DeleteRegionActivity","RealTimeGeoJsonActivity","UpdateMetadataActivity","CarDrivingActivity","MyLocationTrackingModeActivity","MyLocationToggleActivity","MyLocationTintActivity","MyLocationDrawableActivity","DoubleMapActivity", "LocationPickerActivity","GeoJsonClusteringActivity","RuntimeStyleTestActivity", "AnimatedMarkerActivity", "ViewPagerActivity","MapFragmentActivity","SupportMapFragmentActivity","SnapshotActivity","NavigationDrawerActivity", "QueryRenderedFeaturesBoxHighlightActivity", "MultiMapActivity", "MapInDialogActivity", "SimpleMapActivity"];
const excludeActivities = ["BaseLocationActivity","MockLocationEngine","DeleteRegionActivity","RealTimeGeoJsonActivity","UpdateMetadataActivity","CarDrivingActivity","MyLocationTrackingModeActivity","MyLocationToggleActivity","MyLocationTintActivity","MyLocationDrawableActivity","DoubleMapActivity", "LocationPickerActivity","GeoJsonClusteringActivity","RuntimeStyleTestActivity", "AnimatedMarkerActivity", "ViewPagerActivity","MapFragmentActivity","SupportMapFragmentActivity","SnapshotActivity","NavigationDrawerActivity", "QueryRenderedFeaturesBoxHighlightActivity", "MultiMapActivity", "MapInDialogActivity", "SimpleMapActivity"];
const appBasePath = 'platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity';
const testBasePath = 'platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/gen';
const subPackages = fs.readdirSync(appBasePath);
Expand Down
Loading

0 comments on commit 91b1bac

Please sign in to comment.