Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fitToCoordinate added duration paramenter for animation #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion android/src/main/java/com/rnmaps/maps/MapManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public void receiveCommand(@NonNull MapView view, String commandId, @Nullable Re
if (args == null) {
break;
}
view.fitToCoordinates(args.getArray(0), args.getMap(1), args.getBoolean(2));
view.fitToCoordinates(args.getArray(0), args.getMap(1), args.getBoolean(2),args.getInt(3));
break;

case "setMapBoundaries":
Expand Down
4 changes: 2 additions & 2 deletions android/src/main/java/com/rnmaps/maps/MapView.java
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ public void applyBaseMapPadding(int left, int top, int right, int bottom){
}

public void fitToCoordinates(ReadableArray coordinatesArray, ReadableMap edgePadding,
boolean animated) {
boolean animated,int duration) {
if (map == null) return;

LatLngBounds.Builder builder = new LatLngBounds.Builder();
Expand All @@ -1031,7 +1031,7 @@ public void fitToCoordinates(ReadableArray coordinatesArray, ReadableMap edgePad
}

if (animated) {
map.animateCamera(cu);
map.animateCamera(cu,duration,null);
} else {
map.moveCamera(cu);
}
Expand Down
8 changes: 6 additions & 2 deletions ios/AirGoogleMaps/AIRGoogleMapManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ - (UIView *)view
RCT_EXPORT_METHOD(fitToCoordinates:(nonnull NSNumber *)reactTag
coordinates:(nonnull NSArray<AIRMapCoordinate *> *)coordinates
edgePadding:(nonnull NSDictionary *)edgePadding
animated:(BOOL)animated)
animated:(BOOL)animated
duration:(NSInteger)duration)
{
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
id view = viewRegistry[reactTag];
Expand All @@ -327,7 +328,10 @@ - (UIView *)view
GMSCameraUpdate *cameraUpdate = [GMSCameraUpdate fitBounds:bounds withEdgeInsets:UIEdgeInsetsMake(top, left, bottom, right)];

if (animated) {
[mapView animateWithCameraUpdate: cameraUpdate];
[CATransaction begin];
[CATransaction setAnimationDuration:duration / 1000.0]; // Convert milliseconds to seconds
[mapView animateWithCameraUpdate:cameraUpdate];
[CATransaction commit];
} else {
[mapView moveCamera: cameraUpdate];
}
Expand Down
29 changes: 28 additions & 1 deletion lib/Geojson.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@ import { MapPolygonProps as PolygonProps } from './MapPolygon';
import { MapPolylineProps as PolylineProps } from './MapPolyline';
import { LatLng } from './sharedTypes';
export type GeojsonProps = {
/**
* Sets the anchor point for the marker.
* The anchor specifies the point in the icon image that is anchored to the marker's position on the Earth's surface.
*
* The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0],
* where (0, 0) is the top-left corner of the image, and (1, 1) is the bottom-right corner.
*
* The anchoring point in a W x H image is the nearest discrete grid point in a (W + 1) x (H + 1) grid, obtained by scaling the then rounding.
* For example, in a 4 x 2 image, the anchor point (0.7, 0.6) resolves to the grid point at (3, 1).
*
* @default {x: 0.5, y: 1.0}
* @platform iOS: Google Maps only. For Apple Maps, see the `centerOffset` prop
* @platform Android: Supported
*/
anchor?: MarkerProps['anchor'];
/**
* The offset (in points) at which to display the annotation view.
*
* By default, the center point of an annotation view is placed at the coordinate point of the associated annotation.
*
* Positive offset values move the annotation view down and to the right, while negative values move it up and to the left.
*
* @default {x: 0.0, y: 0.0}
* @platform iOS: Apple Maps only. For Google Maps, see the `anchor` prop
* @platform Android: Not supported. See see the `anchor` prop
*/
centerOffset?: MarkerProps['centerOffset'];
/**
* The pincolor used on markers
*
Expand Down Expand Up @@ -55,7 +82,7 @@ export type GeojsonProps = {
* @platform iOS: Supported
* @platform Android: Supported
*/
lineDashPattern?: PolylineProps['lineDashPattern'];
lineDashPattern?: PolygonProps['lineDashPattern'] | PolylineProps['lineDashPattern'];
/**
* The offset (in points) at which to start drawing the dash pattern.
*
Expand Down
6 changes: 3 additions & 3 deletions lib/Geojson.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ const MapMarker_1 = __importDefault(require("./MapMarker"));
const MapPolyline_1 = __importDefault(require("./MapPolyline"));
const MapPolygon_1 = __importDefault(require("./MapPolygon"));
const Geojson = (props) => {
const { geojson, strokeColor, fillColor, strokeWidth, color, title, image, zIndex, onPress, lineCap, lineJoin, tappable, tracksViewChanges, miterLimit, lineDashPhase, lineDashPattern, markerComponent, } = props;
const { anchor, centerOffset, geojson, strokeColor, fillColor, strokeWidth, color, title, image, zIndex, onPress, lineCap, lineJoin, tappable, tracksViewChanges, miterLimit, lineDashPhase, lineDashPattern, markerComponent, } = props;
const pointOverlays = makePointOverlays(geojson.features);
const lineOverlays = makeLineOverlays(geojson.features);
const polygonOverlays = makePolygonOverlays(geojson.features);
return (<React.Fragment>
{pointOverlays.map((overlay, index) => {
const markerColor = getColor(color, overlay, 'marker-color');
const pointOverlayTracksViewChanges = overlay.feature.properties?.tracksViewChanges || tracksViewChanges;
return (<MapMarker_1.default key={index} coordinate={overlay.coordinates} tracksViewChanges={pointOverlayTracksViewChanges} image={image} title={title} pinColor={markerColor} zIndex={zIndex} onPress={() => onPress && onPress(overlay)}>
return (<MapMarker_1.default key={index} coordinate={overlay.coordinates} tracksViewChanges={pointOverlayTracksViewChanges} image={image} title={title} pinColor={markerColor} zIndex={zIndex} anchor={anchor} centerOffset={centerOffset} onPress={() => onPress && onPress(overlay)}>
{markerComponent}
</MapMarker_1.default>);
})}
Expand All @@ -52,7 +52,7 @@ const Geojson = (props) => {
const polygonFillColor = getColor(fillColor, overlay, 'fill');
const lineStrokeColor = getColor(strokeColor, overlay, 'stroke');
const lineStrokeWidth = getStrokeWidth(strokeWidth, overlay);
return (<MapPolygon_1.default key={index} coordinates={overlay.coordinates} holes={overlay.holes} strokeColor={lineStrokeColor} fillColor={polygonFillColor} strokeWidth={lineStrokeWidth} tappable={tappable} onPress={() => onPress && onPress(overlay)} zIndex={zIndex}/>);
return (<MapPolygon_1.default key={index} coordinates={overlay.coordinates} holes={overlay.holes} strokeColor={lineStrokeColor} fillColor={polygonFillColor} strokeWidth={lineStrokeWidth} lineDashPhase={lineDashPhase} lineDashPattern={lineDashPattern} lineCap={lineCap} lineJoin={lineJoin} miterLimit={miterLimit} tappable={tappable} onPress={() => onPress && onPress(overlay)} zIndex={zIndex}/>);
})}
</React.Fragment>);
};
Expand Down
2 changes: 1 addition & 1 deletion lib/MapPolygon.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export type MapPolygonProps = ViewProps & {
* followed by the first gap length, followed by the second line segment length, and so on.
*
* @platform iOS: Apple Maps only
* @platform Android: Not supported
* @platform Android: Supported
*/
lineDashPattern?: number[];
/**
Expand Down
2 changes: 1 addition & 1 deletion lib/MapPolyline.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export declare class MapPolyline extends React.Component<MapPolylineProps> {
}
declare const _default: typeof MapPolyline;
export default _default;
type PolylinePressEvent = NativeSyntheticEvent<{
export type PolylinePressEvent = NativeSyntheticEvent<{
action: 'polyline-press';
/**
* @platform iOS: Google Maps
Expand Down
4 changes: 2 additions & 2 deletions lib/MapView.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ class MapView extends React.Component {
}
fitToCoordinates(coordinates = [], options = {}) {
if (this.map.current) {
const { edgePadding = { top: 0, right: 0, bottom: 0, left: 0 }, animated = true, } = options;
MapViewNativeComponent_1.Commands.fitToCoordinates(this.map.current, coordinates, edgePadding, animated);
const { edgePadding = { top: 0, right: 0, bottom: 0, left: 0 }, animated = true, duration = 400, } = options;
MapViewNativeComponent_1.Commands.fitToCoordinates(this.map.current, coordinates, edgePadding, animated, duration);
}
}
/**
Expand Down
1 change: 1 addition & 0 deletions lib/MapView.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export type ChangeEvent = NativeSyntheticEvent<{
export type FitToOptions = {
edgePadding?: EdgePadding;
animated?: boolean;
duration?: number;
};
export type BoundingBox = {
northEast: LatLng;
Expand Down
2 changes: 1 addition & 1 deletion lib/MapViewNativeComponent.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface NativeCommands {
animateCamera: (viewRef: NonNullable<React.RefObject<MapViewNativeComponentType>['current']>, camera: Partial<Camera>, duration: number) => void;
fitToElements: (viewRef: NonNullable<React.RefObject<MapViewNativeComponentType>['current']>, edgePadding: EdgePadding, animated: boolean) => void;
fitToSuppliedMarkers: (viewRef: NonNullable<React.RefObject<MapViewNativeComponentType>['current']>, markers: string[], edgePadding: EdgePadding, animated: boolean) => void;
fitToCoordinates: (viewRef: NonNullable<React.RefObject<MapViewNativeComponentType>['current']>, coordinates: LatLng[], edgePadding: EdgePadding, animated: boolean) => void;
fitToCoordinates: (viewRef: NonNullable<React.RefObject<MapViewNativeComponentType>['current']>, coordinates: LatLng[], edgePadding: EdgePadding, animated: boolean, duration: number) => void;
setMapBoundaries: (viewRef: NonNullable<React.RefObject<MapViewNativeComponentType>['current']>, northEast: LatLng, southWest: LatLng) => void;
setIndoorActiveLevelIndex: (viewRef: NonNullable<React.RefObject<MapViewNativeComponentType>['current']>, activeLevelIndex: number) => void;
scrollMap: (viewRef: NonNullable<React.RefObject<MapViewNativeComponentType>['current']>, xPixel: number, YPixel: number, animated: boolean) => void;
Expand Down
6 changes: 4 additions & 2 deletions src/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ class MapView extends React.Component<MapViewProps, State> {
onMapReady();
}
});
}, 100)
}, 100);
}

setNativeProps(props: Partial<NativeProps>) {
Expand All @@ -774,7 +774,7 @@ class MapView extends React.Component<MapViewProps, State> {
}

private _onMapReady() {
if(this.callMapReady) {
if (this.callMapReady) {
clearTimeout(this.mapReadytimerId);
const {onMapReady} = this.props;
this.setState({isReady: true}, () => {
Expand Down Expand Up @@ -867,13 +867,15 @@ class MapView extends React.Component<MapViewProps, State> {
const {
edgePadding = {top: 0, right: 0, bottom: 0, left: 0},
animated = true,
duration = 400,
} = options;

Commands.fitToCoordinates(
this.map.current,
coordinates,
edgePadding,
animated,
duration,
);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/MapView.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export type ChangeEvent = NativeSyntheticEvent<{
export type FitToOptions = {
edgePadding?: EdgePadding;
animated?: boolean;
duration?: number;
};

export type BoundingBox = {northEast: LatLng; southWest: LatLng};
Expand Down
1 change: 1 addition & 0 deletions src/MapViewNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ interface NativeCommands {
coordinates: LatLng[],
edgePadding: EdgePadding,
animated: boolean,
duration: number,
) => void;

setMapBoundaries: (
Expand Down