[英]I am not able to reduce the size of the Google Maps Component made by google-maps-react in my React application
Map
組件下的樣式正在減小嵌入在組件內的地圖的大小,而不是實際組件本身。 這在屏幕截圖中會更清楚。 我故意寫了style={{ width: '10%', height: '10%'}}
來表明即使我將尺寸縮小很多,組件仍然保持相同的尺寸。
代碼:
import React, { Component } from 'react';
import { Map, GoogleApiWrapper, Marker } from 'google-maps-react';
var config = require("../config/config").default();
export class GoogleMap2 extends Component {
constructor(props) {
super(props);
this.state = {
stores: [{lat: 47.49855629475769, lng: -122.14184416996333},
{latitude: 47.359423, longitude: -122.021071},
{latitude: 47.2052192687988, longitude: -121.988426208496},
{latitude: 47.6307081, longitude: -122.1434325},
{latitude: 47.3084488, longitude: -122.2140121},
{latitude: 47.5524695, longitude: -122.0425407}]
}
}
displayMarkers = () => {
return this.state.stores.map((store, index) => {
return <Marker key={index} id={index} position={{
lat: store.latitude,
lng: store.longitude
}}
onClick={() => console.log("You clicked me!")} />
})
}
render() {
return (
<Map
google={this.props.google}
zoom={8}
style={{ width: '10%', height: '10%'}}
initialCenter={{ lat: 47.444, lng: -122.176}}
>
{this.displayMarkers()}
</Map>
);
}
}
export default GoogleApiWrapper({
apiKey: config.apiKey,
signature: config.signature
})(GoogleMap2)
如您所見,即使我使用style
屬性減小了Map
的大小,該組件仍然具有height: 100%
和width: 100%
。 請幫助我實際減小它的大小。
Map
組件有一個名為containerStyle
的屬性,通常當您想要更改默認位置“絕對”時。 這將負責Map
容器。 相應地更改樣式。
這是新的Map
組件:
<Map
google={this.props.google}
zoom={8}
style={{ width: '10%', height: '10%'}}
containerStyle={{width: "40%", height: "29%", position: "fixed"}}
initialCenter={{ lat: 47.444, lng: -122.176}}
>
{this.displayMarkers()}
</Map>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.