From ebad9ac9ffb026f7e71bd82a41b8fcdc0e88db2c Mon Sep 17 00:00:00 2001 From: Armando Date: Thu, 23 Jun 2022 16:09:24 +0200 Subject: [PATCH] Add circle support --- .gitignore | 1 + src/Circle.js | 20 ++++++ src/index.js | 185 +++++++++++++++++++++++++------------------------- 3 files changed, 114 insertions(+), 92 deletions(-) create mode 100644 src/Circle.js diff --git a/.gitignore b/.gitignore index 04e61805..96485cea 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ yarn-error.log dist /.vscode +.history \ No newline at end of file diff --git a/src/Circle.js b/src/Circle.js new file mode 100644 index 00000000..635f2a8d --- /dev/null +++ b/src/Circle.js @@ -0,0 +1,20 @@ +import React, { Component } from "react"; +import { Circle } from "react-google-maps"; + +class MapViewCircle extends Component { + render() { + return ( + + ); + } +} + +export default MapViewCircle; diff --git a/src/index.js b/src/index.js index dab5f226..48197df5 100755 --- a/src/index.js +++ b/src/index.js @@ -1,112 +1,113 @@ -import React, { Component } from 'react'; -import { View, StyleSheet } from 'react-native'; -import { withGoogleMap, GoogleMap } from 'react-google-maps'; -import Marker from './Marker'; -import Polyline from './Polyline'; -import Callout from './Callout'; +import React, { Component } from "react"; +import { View, StyleSheet } from "react-native"; +import { withGoogleMap, GoogleMap } from "react-google-maps"; +import Marker from "./Marker"; +import Polyline from "./Polyline"; +import Callout from "./Callout"; +import Circle from "./Circle"; -const GoogleMapContainer = withGoogleMap(props => ( - -)); +const GoogleMapContainer = withGoogleMap((props) => ); class MapView extends Component { - state = { - center: null, - }; + state = { + center: null, + }; - handleMapMounted = map => { - this.map = map; - this.props.onMapReady && this.props.onMapReady(); - }; + handleMapMounted = (map) => { + this.map = map; + this.props.onMapReady && this.props.onMapReady(); + }; - getCamera = () => { - return { - zoom: this.map.getZoom(), - center: this.map.getCenter(), - heading: this.map.getHeading(), - }; - }; + getCamera = () => { + return { + zoom: this.map.getZoom(), + center: this.map.getCenter(), + heading: this.map.getHeading(), + }; + }; - animateCamera(camera) { - this.setState({ zoom: camera.zoom }); - this.setState({ center: camera.center }); - } + animateCamera(camera) { + this.setState({ zoom: camera.zoom }); + this.setState({ center: camera.center }); + } - animateToRegion(coordinates) { - this.setState({ - center: { lat: coordinates.latitude, lng: coordinates.longitude }, - }); - } + animateToRegion(coordinates) { + this.setState({ + center: { lat: coordinates.latitude, lng: coordinates.longitude }, + }); + } - onDragEnd = () => { - const { onRegionChangeComplete } = this.props; - if (this.map && onRegionChangeComplete) { - const center = this.map.getCenter(); - onRegionChangeComplete({ - latitude: center.lat(), - longitude: center.lng(), - }); - } - }; + onDragEnd = () => { + const { onRegionChangeComplete } = this.props; + if (this.map && onRegionChangeComplete) { + const center = this.map.getCenter(); + onRegionChangeComplete({ + latitude: center.lat(), + longitude: center.lng(), + }); + } + }; - render() { - const { region, initialRegion, onRegionChange, onPress, options, defaultZoom } = this.props; - const { center } = this.state; - const style = this.props.style || styles.container; + render() { + const { region, initialRegion, onRegionChange, onPress, options, defaultZoom } = this.props; + const { center } = this.state; + const style = this.props.style || styles.container; - const googleMapProps = center - ? { center } - : region - ? { - center: { - lat: region.latitude, - lng: region.longitude, - }, - } - : { - defaultCenter: { - lat: initialRegion.latitude, - lng: initialRegion.longitude, - }, - }; - const zoom = - defaultZoom || - (region && region.latitudeDelta - ? Math.round(Math.log(360 / region.latitudeDelta) / Math.LN2) - : initialRegion && initialRegion.latitudeDelta - ? Math.round(Math.log(360 / initialRegion.latitudeDelta) / Math.LN2) - : 15); - googleMapProps['zoom'] = this.state.zoom ? this.state.zoom : zoom; - return ( - - } - mapElement={
} - onZoomChanged={() => { - this.setState({ zoom: this.map.getZoom() }); - }} - {...googleMapProps} - onDragStart={onRegionChange} - onIdle={this.onDragEnd} - defaultZoom={zoom} - onClick={onPress} - options={options}> - {this.props.children} - - - ); - } + const googleMapProps = center + ? { center } + : region + ? { + center: { + lat: region.latitude, + lng: region.longitude, + }, + } + : { + defaultCenter: { + lat: initialRegion.latitude, + lng: initialRegion.longitude, + }, + }; + const zoom = + defaultZoom || + (region && region.latitudeDelta + ? Math.round(Math.log(360 / region.latitudeDelta) / Math.LN2) + : initialRegion && initialRegion.latitudeDelta + ? Math.round(Math.log(360 / initialRegion.latitudeDelta) / Math.LN2) + : 15); + googleMapProps["zoom"] = this.state.zoom ? this.state.zoom : zoom; + return ( + + } + mapElement={
} + onZoomChanged={() => { + this.setState({ zoom: this.map.getZoom() }); + }} + {...googleMapProps} + onDragStart={onRegionChange} + onIdle={this.onDragEnd} + defaultZoom={zoom} + onClick={onPress} + options={options} + > + {this.props.children} + + + ); + } } MapView.Marker = Marker; MapView.Polyline = Polyline; MapView.Callout = Callout; +MapView.Circle = Circle; const styles = StyleSheet.create({ - container: { - height: '100%', - }, + container: { + height: "100%", + }, }); export default MapView;