ste*_*opo 3 reactjs react-google-maps
我正在使用react-google-maps包在我的反应应用程序中呈现 Google 地图。我想禁用街景。
从文档中,我看到有以下道具:
默认街景
街景
代码片段在这里:
import React, { Component } from 'react';
import { withScriptjs, withGoogleMap, GoogleMap, Marker } from "react-google-maps";
import PropTypes from 'prop-types';
const Map = withScriptjs(withGoogleMap((props) => {
return(
<GoogleMap
defaultZoom={17}
defaultCenter={{ lat: props.lat, lng: props.lng }}
// defaultStreetView={false}
// streetView={false}
>
{props.isMarkerShown && <Marker position={{ lat: props.lat, lng: props.lng }} />}
</GoogleMap>
)
}))
Map.propTypes = {
lat: PropTypes.number.isRequired,
lng: PropTypes.number.isRequired,
isMarkerShown: PropTypes.bool.isRequired
}
export default Map;
Run Code Online (Sandbox Code Playgroud)
在这种情况下,似乎道具 defaultStreetView 和 streetView 实际上并不相关。
正确代码:
import React, { Component } from 'react';
import { withScriptjs, withGoogleMap, GoogleMap, Marker } from "react-google-maps";
import PropTypes from 'prop-types';
const Map = withScriptjs(withGoogleMap((props) => {
return(
<GoogleMap
defaultZoom={17}
defaultCenter={{ lat: props.lat, lng: props.lng }}
options={{streetViewControl: false}}
>
{props.isMarkerShown && <Marker position={{ lat: props.lat, lng: props.lng }} />}
</GoogleMap>
)
}))
Map.propTypes = {
lat: PropTypes.number.isRequired,
lng: PropTypes.number.isRequired,
isMarkerShown: PropTypes.bool.isRequired
}
export default Map;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2400 次 |
| 最近记录: |