首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >google-map-react自定义皮肤

google-map-react自定义皮肤
EN

Stack Overflow用户
提问于 2016-01-25 19:36:06
回答 2查看 3.9K关注 0票数 5

我正在使用react和google-map-react组件。我正试着给我的谷歌地图添加一个皮肤。你知道我在哪里做这个吗?我正在尝试使用snazzymap皮肤,他们提供了一系列的样式。

https://snazzymaps.com/style/25/blue-water

时髦的地图提供了

代码语言:javascript
复制
import React from 'react';
import ReactDom from 'react-dom';
//import shouldPureComponentUpdate from 'react-pure-render/function';

import GoogleMap from 'google-map-react';
var divStyle = {
  paddingTop: 20,
  paddingLeft: 20,
  paddingRight: 20,
  width:1024,
  height:768
};
const K_WIDTH = 40;
const K_HEIGHT = 40;

const greatPlaceStyle = {
  // initially any map object has left top corner at lat lng coordinates
  // it's on you to set object origin to 0,0 coordinates
  position: 'absolute',
  width: K_WIDTH,
  height: K_HEIGHT,
  left: -K_WIDTH / 2,
  top: -K_HEIGHT / 2,

  border: '5px solid #f44336',
  borderRadius: K_HEIGHT,
  backgroundColor: 'white',
  textAlign: 'center',
  color: '#3f51b5',
  fontSize: 16,
  fontWeight: 'bold',
  padding: 4
};

class MyGreatPlace extends React.Component {

  static propTypes = {
    text: React.PropTypes.string
  };

  static defaultProps = {};

  //shouldComponentUpdate = shouldPureComponentUpdate;

  constructor(props) {
    super(props);
  }

  render() {
    return (
       <div style={greatPlaceStyle}>
          {this.props.text}
       </div>
    );
  }
}
class SimpleMapPage extends React.Component {

  static defaultProps = {
    defaultCenter: {lat: 59.938043, lng: 30.337157},
    zoom: 12,
    greatPlaceCoords: {lat: 59.724465, lng: 30.080121}
  };

  //shouldComponentUpdate = shouldPureComponentUpdate;

  constructor(props) {
    super(props);
  }

  componentWillReceiveProps(nextProps) {
    // console.log("test")
}

  render() {
    return (
       <div style={divStyle}>
       <GoogleMap
        bootstrapURLKeys={{
          key: '312312j3kl12j321random'
        }}
        center={this.props.center}
        zoom={this.props.zoom}
        defaultCenter={this.props.defaultCenter}
        defaultZoom={this.props.zoom}
        >
        <MyGreatPlace lat={this.props.center.lat} lng={this.props.center.lng} text={'Site'} /* Kreyser Avrora */ />

      </GoogleMap>
      </div>
    );
  }
}

export default SimpleMapPage
EN

回答 2

Stack Overflow用户

发布于 2019-02-08 21:12:55

对于选项中的google-map-react put样式:

代码语言:javascript
复制
<GoogleMap
    options={{
        styles: [{ stylers: [{ 'saturation': 50 }, { 'gamma': 0.5 }] }]
    }}>
</GoogleMap>
票数 7
EN

Stack Overflow用户

发布于 2016-02-24 01:26:35

在google-map-react中加载mapStyle的位置在<GoogleMap></GoogleMap>标签中,如下所示:

代码语言:javascript
复制
<GoogleMap
    // other map attributes like defaultCenter and defaultZoom
    defaultOptions={{
        styles: require(`../../constants/fancyMapStyles.json`),
    }}>
</GoogleMap>

有关更多细节,请查看此处:http://tomchentw.github.io/react-google-maps/#/basics/styled-map?_k=5el6q8

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34991638

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档