google-map-react 自定义皮肤

caf*_*ipt 4 javascript google-maps reactjs

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

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

时髦的地图提供了

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
Run Code Online (Sandbox Code Playgroud)

小智 6

对于 google-map-react 在选项中放置样式:

<GoogleMap
    options={{
        styles: [{ stylers: [{ 'saturation': 50 }, { 'gamma': 0.5 }] }]
    }}>
</GoogleMap>
Run Code Online (Sandbox Code Playgroud)


app*_*hat 4

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

<GoogleMap
    // other map attributes like defaultCenter and defaultZoom
    defaultOptions={{
        styles: require(`../../constants/fancyMapStyles.json`),
    }}>
</GoogleMap>
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参阅此处: http://tomchentw.github.io/react-google-maps/#/basics/styled-map ?_k=5el6q8