UNPKG

mapwize-ui-react-native

Version:

Fully featured and ready to use UI to add Mapwize Indoor Maps and Navigation in your React Native app.

196 lines (158 loc) 5.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _immer = _interopRequireDefault(require("immer")); var _mapwizeSdkReactNative = require("mapwize-sdk-react-native"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } class MapActionsDispatcher { constructor(mapwizeMap, mapwizeMapState, render, apiService, devCallbackInterceptor) { _defineProperty(this, "mapwizeMap", void 0); _defineProperty(this, "render", void 0); _defineProperty(this, "state", void 0); _defineProperty(this, "devCallbackInterceptor", void 0); _defineProperty(this, "apiService", void 0); this.mapwizeMap = mapwizeMap; this.state = mapwizeMapState; this.render = render; this.apiService = apiService; this.devCallbackInterceptor = devCallbackInterceptor; } syncState(mapwizeMapState) { this.state = { ...this.state, selectedPlace: mapwizeMapState.selectedPlace, markers: mapwizeMapState.markers }; // this.state = mapwizeMapState;//TODO check if there are drawbacks } fireError(message) { console.error(new Error(message)); } selectPlace(place, preventCenter = false) { if (!preventCenter) { const plceAny = place; plceAny.defaultCenter && this.mapwizeMap.centerOn(plceAny.defaultCenter); plceAny.markerCoordinate && this.mapwizeMap.centerOn(plceAny.markerCoordinate); } const nextState = (0, _immer.default)(this.state, draftState => { draftState.selectedPlace = place; draftState.markers = []; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } selectPlacelist(placelist) { this.apiService.getPlacesForPlacelist(placelist).then(places => { const nextState = (0, _immer.default)(this.state, draftState => { draftState.selectedPlace = undefined; //TODO check that `undefined` does unselect place draftState.markers = places.map(place => new _mapwizeSdkReactNative.MarkerProp(place.markerCoordinate)); }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); }); } unselectContent() { const nextState = (0, _immer.default)(this.state, draftState => { draftState.selectedPlace = undefined; draftState.markers = []; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } async centerOnPlace(place) { return this.mapwizeMap.getZoom().then(zoom => { // if (zoom < 19) { // zoom = 19; // } const opts = { centerOnElement: true, zoom }; if (opts !== null && opts !== void 0 && opts.centerOnElement) { return this.mapwizeMap.centerOn(place); } return Promise.resolve(); }); } async centerOnPlacelist(placelist) { return this.mapwizeMap.getZoom().then(zoom => { if (zoom > 19) { zoom = 19; } const opts = { centerOnElement: true, zoom }; if (opts !== null && opts !== void 0 && opts.centerOnElement) { return this.mapwizeMap.centerOn(placelist.venue, opts.zoom); } return Promise.resolve(); }); } centerOnVenue(venue) { this.mapwizeMap.centerOn(venue); } startDirection(direction, options, startLabel, endLabel) { options.startMarkerOptions = { textField: startLabel }; options.endMarkerOptions = { textField: endLabel }; const directionProp = new _mapwizeSdkReactNative.DirectionProp(direction, options); const nextState = (0, _immer.default)(this.state, draftState => { draftState.mapDirection = directionProp; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } stopDirection() { const nextState = (0, _immer.default)(this.state, draftState => { draftState.mapDirection = undefined; //TODO check that `undefined` remove direction draftState.mapNavigation = undefined; //TODO check that `undefined` remove direction }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } startNavigation(navigationProp) { const nextState = (0, _immer.default)(this.state, draftState => { draftState.mapNavigation = navigationProp; draftState.mapDirection = undefined; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } setLeftMargin() {//TODO setLeftMargin // this.mapwizeMap.setLeftMargin(400); } setLanguage(language) { this.mapwizeMap.setPreferredLanguage(language); } setUniverse(universe) { this.mapwizeMap.setUniverse(universe); } hasIndoorLocation() { const userLocation = this.state.userLocation; return (userLocation === null || userLocation === void 0 ? void 0 : userLocation.floor) !== undefined; } getUserLocation() { return this.state.userLocation; } setUserLocation(latLngFloor) { const nextState = (0, _immer.default)(this.state, draftState => { draftState.userLocation = latLngFloor; }); const oldState = this.state; this.state = nextState; this.render(oldState, nextState); } } exports.default = MapActionsDispatcher; //# sourceMappingURL=mapActionsDispatcher.js.map