react-native-mechanic-map
Version:
React Native wrapper for Mechanic Map
246 lines (245 loc) • 6.53 kB
TypeScript
import type { WebViewProps } from 'react-native-webview';
import MechanicMap from './MechanicMap';
declare type LocationId = String;
declare type LevelId = String;
declare type RGB = `rgb(${number}, ${number}, ${number})`;
declare type RGBA = `rgba(${number}, ${number}, ${number}, ${number})`;
declare type HEX = `#${string}`;
export declare type Color = RGB | RGBA | HEX;
export declare enum LocationTypes {
STORE = "store",
SERVICE = "service"
}
export declare enum LocationActions {
ZOOM = "zoom",
SELECT = "select",
TOOLTIP = "tooltip",
NOT_EMPTY = "not-empty"
}
export declare enum MapActions {
INIT = "init",
SHOW_NAVIGATION = "showNavigation",
CLOSE_NAVIGATION = "closeNavigation",
SHOW_LOCATION = "selectLocation",
SET_FLOOR = "selectFloor",
HIGHLIGHT_LOCATIONS = "highlightLocations",
HIDE_LOCATION = "hideLocation",
SET_CURRENT_LOCATION = "setCurrentLocation",
SHOW_CURRENT_LOCATION = "showCurrentLocation",
MOVE_CURRENT_LOCATION = "moveCurrentLocation",
REMOVE_CURRENT_LOCATION = "removeCurrentLocation",
ZOOM_IN = "zoomIn",
ZOOM_OUT = "zoomOut",
ADD_LEVEL = "addLevel",
RESET_LEVEL = "resetLevel",
MOVE_TO = "moveTo",
ZOOM_TO = "zoomTo",
CHANGE_COLORS = "changeColors",
RELOAD = "reload"
}
export declare enum MapResponses {
MAP_LOADED = "mapLoaded",
LOCATION_OPENED = "locationOpened",
LOCATION_CLOSED = "locationClosed",
LEVEL_SWITCHED = "levelSwitched",
LOCATION_HIGHLIGHTED = "locationsHighlighted",
NAVIGATION_CANCELLED = "navigationCancelled",
ERROR = "error"
}
export interface EventPayload {
action: MapResponses;
data?: any;
}
export interface Location {
id: LocationId;
type: LocationTypes | String;
title: String;
image_url: String;
zoom?: Number;
action?: LocationActions;
explanation?: String;
}
export interface MechanicMapPayload {
id: LevelId;
no: Number;
mapWidth: Number;
mapHeight: Number;
title: String;
map: String;
locations: Location[];
show: Boolean;
}
export declare enum MapModes {
DEFAULT = "default",
PICKER = "picker"
}
export declare enum MapActionModes {
DEFAULT = "default",
TOOLTIP = "tooltip",
SELECT = "select",
ZOOM = "zoom",
NOT_EMPTY = "not-empty"
}
export declare enum MapAnimationModes {
LINE = "line",
DOT = "dot",
ARROW = "arrow",
FOOT = "foot",
FEET = "feet"
}
interface ColorParams {
activeStores?: Color;
inactiveStores?: Color;
services?: Color;
background?: Color;
locations?: {
[key: string]: Color;
};
}
export interface MechanicMapOptions {
mode?: MapModes;
action?: MapActionModes;
initialScaleFactor?: Number;
maxScale?: Number;
rotate?: Number;
selector?: String;
serviceSelector?: String;
rectSelector?: String;
rotateServices?: Boolean;
draggable?: Boolean;
landmark?: Boolean;
developer?: Boolean;
zoom?: Boolean;
zoomToSelected?: Boolean;
hoverTip?: Boolean;
cssAnimation?: Boolean;
textOnRect?: {
fontFamily?: String;
fillColor?: String;
fontSize: Number;
};
strokeOptions?: {
width?: Number;
color?: String;
};
mapFill?: Boolean;
tooltip?: {
enabled: Boolean;
navigation?: Boolean;
detail?: Boolean;
};
smartip?: Boolean;
animation?: {
mode?: MapAnimationModes;
speedFactor?: Number;
frequencyFactor?: Number;
stackAnimation?: Boolean;
};
stackMode?: {
offset: Number;
};
beaconMode?: Boolean;
colors?: ColorParams;
}
export interface PostMessagePayload {
action: MapActions;
payload?: object;
}
interface InitParams {
payload: MechanicMapPayload[];
options?: MechanicMapOptions;
languageCode?: String;
}
export interface MechanicMapProps extends InitParams, WebViewProps {
disableAutoInit?: Boolean;
onEvent?: (event: EventPayload) => void;
onLevelSwitched?: (newLevel: {
id: LevelId;
no: Number;
}) => void;
onLocationOpened?: (location: Location) => void;
onLocationClosed?: () => void;
onMapLoaded?: () => void;
onNavigationCancalled?: () => void;
onLocationHighlighted?: () => void;
onMapError?: (data: {
message: String;
source: String;
lineno: Number;
colno: Number;
error: String;
}) => void;
}
export interface Route {
nodes: Array<String>;
direction: Array<Number>;
floors: Array<{
no: Number;
lines: Array<{
x1: Number;
y1: Number;
x2: Number;
y2: Number;
node_level_changer?: String;
}>;
}>;
end: String;
start: {
location: String;
};
}
export declare type MechanicMapHandle = {
postMessage: (params: PostMessagePayload) => void;
init: (params: InitParams) => void;
showLocation: (params: {
id: LocationId;
type: LocationTypes;
duration?: Boolean;
closeNavigation?: Boolean;
moveAndZoom?: Boolean;
}) => void;
closeNavigation: (resetLevel?: Boolean) => void;
showNavigation: (route: Route, options?: {
autoMode?: Boolean;
zoomEnabled?: Boolean;
showPins?: Boolean;
}) => void;
setFloor: (floorNo: Number, options?: {
resetZoom?: Boolean;
hideLocation?: Boolean;
}) => void;
highlightLocations: (ids: Array<String>, options?: {
type?: LocationTypes;
zoomEnabled?: Boolean;
duration?: Number;
}) => void;
hideLocation: () => void;
setCurrentLocation: (x: Number, y: Number, options?: {
floorNo?: Number;
}) => void;
showCurrentLocation: () => void;
moveCurrentLocation: (coords: Array<{
x: Number;
y: Number;
}>, options?: {
floorNo?: Number;
}) => void;
removeCurrentLocation: () => void;
zoomIn: () => void;
zoomOut: () => void;
moveTo: (x: Number, y: Number, options?: {
scale?: Number;
duration?: Number;
easing?: String;
}) => void;
zoomTo: (x: Number, y: Number, options?: {
scale?: Number;
duration?: Number;
easing?: String;
}) => void;
addLevel: (level: MechanicMapPayload) => void;
resetLevel: () => void;
changeColors: (colors: ColorParams) => void;
reload: () => void;
};
export default MechanicMap;