简体   繁体   English

样式 google-map-react 地图

[英]styling google-map-react map

I am building a map with google-map-react and trying to style it with no luck.我正在使用google-map-react构建地图,并试图在没有运气的情况下对其进行样式设置。 I am using the documentation here: https://github.com/google-map-react/google-map-react/blob/master/API.md and adding styles via a prop called options like it says but I am not seeing any styles being applied.我在这里使用文档: https : //github.com/google-map-react/google-map-react/blob/master/API.md并通过名为options的道具添加样式,就像它说的,但我没有看到正在应用的任何样式。

Here is my code:这是我的代码:

const createMapOptions = () => {
  return {
    styles: [{stylers: [{'saturation': -100}, {'gamma': 0.2}, {'lightness': 4}, {'visibility': 'on'}]}]
  }
}

const Map = ({center, children, onGoogleApiLoaded, useGoogleMapsApis, zoom}) => {

  return (
    <div className='h-100p w-100p'>
      <GoogleMap
        bootstrapURLKeys={{key: '...'}}
        defaultCenter={center}
        defaultZoom={zoom}
        options={createMapOptions}
        yesIWantToUseGoogleMapApiInternals={useGoogleMapsApis}
        onGoogleApiLoaded={onGoogleApiLoaded}
      >
        {children}
      </GoogleMap>
    </div>
  )
}

Any guidance on how to get ANY styling applied would be greatly appreciated.任何关于如何应用任何样式的指导将不胜感激。

Note - I am using a developer key, not sure if that could be why I am not seeing the styling?注意- 我正在使用开发人员密钥,不确定这是否可能是我看不到样式的原因?

Also Note - I do not want tips on react-google-maps a similar library, but not the same as google-map-react .另请注意- 我不希望关于react-google-maps的提示与类似的库,但与google-map-react Ive seen other google-map-react questions answered and up voted with people referring to react-google-maps .我已经看到其他google-map-react问题得到了回答,并与提到react-google-maps人一起投票。

Some times styling in react as difficult when you use packages.有时,当您使用包时,样式的反应会很困难。 So the Best Way to do it is所以最好的方法是

  1. Open Inspect Element in your browser在浏览器中打开 Inspect Element
  2. Select the Particular Element whose styling you want to modify.选择要修改其样式的特定元素。
  3. Copy the class that is used in it already.复制已在其中使用的类。
  4. Make changes to the same css className in your own scss or css file and will modify.在您自己的 scss 或 css 文件中对相同的 css className 进行更改并将进行修改。

Note : If nothing Happens Try using the !important in the property.注意:如果没有发生任何事情尝试使用属性中的 !important。

https://developers.google.com/maps/documentation/javascript/controls#ControlOptions https://developers.google.com/maps/documentation/javascript/controls#ControlOptions

Use this as resource to change css for the package.将此用作资源来更改包的 css。

Screenshot from the the above resource以上资源截图在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM