|
1 | | -import { withScriptjs, withGoogleMap, GoogleMap, TrafficLayer, Marker } from "react-google-maps"; |
| 1 | +import { withScriptjs, withGoogleMap, GoogleMap, TrafficLayer } from "react-google-maps"; |
2 | 2 | const { SearchBox } = require("react-google-maps/lib/components/places/SearchBox"); |
3 | | -import React, {Component, Children} from 'react'; |
| 3 | +import React from 'react'; |
4 | 4 |
|
5 | 5 | const TrafficMapComponent = withScriptjs(withGoogleMap((props) => { |
6 | 6 |
|
@@ -32,18 +32,20 @@ const TrafficMapComponent = withScriptjs(withGoogleMap((props) => { |
32 | 32 | ); |
33 | 33 |
|
34 | 34 | var traffic = React.createElement(TrafficLayer, { }); |
| 35 | + var childs = [props.markers ]; |
| 36 | + if(props.showSearchBox) { childs = [ searchBox, ...childs ] }; |
| 37 | + if(props.showTrafficLayer) { childs = [ traffic, ...childs ] }; |
| 38 | + |
35 | 39 | return ( |
36 | | - <GoogleMap |
37 | | - defaultZoom={props.defaultZoom} |
38 | | - onZoomChanged={props.onZoomChanged} |
39 | | - onIdle={props.onIdle} |
40 | | - defaultCenter={props.defaultCenter} |
41 | | - center={props.center} |
42 | | - ref={props.onMapMounted} > |
43 | | - {props.showSearchBox && searchBox} |
44 | | - {props.showTrafficLayer && traffic } |
45 | | - {props.markers} |
46 | | - </GoogleMap>) |
| 40 | + React.createElement( |
| 41 | + GoogleMap, |
| 42 | + { defaultZoom : props.defaultZoom, |
| 43 | + onZoomChanged : props.onZoomChanged, |
| 44 | + onIdle : props.onIdle, |
| 45 | + defaultCenter : props.defaultCenter, |
| 46 | + center : props.center, |
| 47 | + ref : props.onMapMounted }, |
| 48 | + childs)) |
47 | 49 | })); |
48 | 50 |
|
49 | 51 | export class GoogleMapComponent extends React.PureComponent { |
|
0 commit comments