From 06645cdac4184f5c1cf50f2a4b94be3d72d634f0 Mon Sep 17 00:00:00 2001 From: Alexander NeonXP Kiryukhin Date: Mon, 10 Jun 2019 03:15:51 +0300 Subject: More improvements --- src/Components/Map.tsx | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src/Components/Map.tsx') diff --git a/src/Components/Map.tsx b/src/Components/Map.tsx index bb0b660..db0bed9 100644 --- a/src/Components/Map.tsx +++ b/src/Components/Map.tsx @@ -1,6 +1,6 @@ import React, { Component } from 'react'; import { StyleSheet, View, Dimensions, ActivityIndicator } from 'react-native'; -import MapView, { Marker, Region, UrlTile } from 'react-native-maps'; +import MapView, { Marker, Region } from 'react-native-maps'; import { connect } from 'redux-su'; import { NavigationActions } from 'react-navigation'; @@ -10,6 +10,7 @@ import PortalPanel from './PortalPanel'; import { getBottomSpace } from '../helper'; import actions from '../Actions/actions'; import { LatLng } from '../Api/interfaces'; +import { getZoomByRegion, getDataZoomForMapZoom } from '../Api/api'; const { width, height } = Dimensions.get("screen") const draggableRange = { @@ -32,6 +33,7 @@ class Map extends Component { this.state = { user: undefined, region: null, + dataZoom: 15, } } componentDidMount() { @@ -63,7 +65,9 @@ class Map extends Component { ) } onRegionChange = (region: Region) => { - this.setState({ region }) + const zoom = getZoomByRegion(width, region) + const dataZoom = getDataZoomForMapZoom(zoom); + this.setState({ region, dataZoom }) setImmediate(() => this.load(false)) } @@ -79,7 +83,15 @@ class Map extends Component { } onPortalClick = (guid: string, coords: LatLng) => { - this.setState({ selectedPortal: { guid, coords } }) + if (this.state.selectedPortal && this.state.selectedPortal.guid == guid) { + this.setState({ selectedPortal: false }) + } else { + this.setState({ selectedPortal: { guid, coords } }) + } + } + + onPortalDismiss = () => { + this.setState({ selectedPortal: false }) } onOpenPortal = (guid: string, coords: LatLng) => { @@ -115,8 +127,13 @@ class Map extends Component { shouldRasterizeIOS renderToHardwareTextureAndroid > - - {this.state.selectedPortal && } + + {this.state.selectedPortal && }