Google标记带有反应的标记大小

问题描述 投票:2回答:1

我目前正在使用google-maps-react进行google-maps项​​目,但遇到了问题。我正在使用道具来获取标记(lat,lng,标记图标)的值,但是我无法更改标记的大小。我留下了一个巨大的标记,无法改变这一点。我试图通过大小作为支柱,但没有成功。预先感谢您的帮助。

这是我的代码:

MAPS.JS

render() {
    /*--- initial code that i passed into props*/
     /*var icon = {
     url: "https://loc8tor.co.uk/wp-content/uploads/2015/08/stencil.png", // url
    scaledSize: new this.props.google.maps.Size(90, 42), // scaled size
    */
     }
 return (
      <div className="map-container">
        <Map
          google={this.props.google}
          className={"map"}
          zoom={4}
          initialCenter={this.props.center}
        >
          {this.props.places.map((place, i) => {
              //pass an array of markers as a child to the GoogleMap component and map over them
            return (
              <Marker
                onClick={this.onMarkerClick}
                key={place.id}
                place_={place}
                position={{ lat: place.lat, lng: place.lng }}
                icon={place.url}
                //Size={place.scaledSize} : Not working
              />
            );
          })}
          <InfoWindowEx
            marker={this.state.activeMarker}
            visible={this.state.showingInfoWindow}
          >
            <div>
              <h3>{this.state.selectedPlace.name}</h3>
              <button
                type="button"
                onClick={this.showDetails.bind(this, this.state.selectedPlace)}
              >

                Show details
              </button>
            </div>
          </InfoWindowEx>
        </Map>
      </div>
    );

INDEX.JS

import React from "react";
import ReactDOM from "react-dom";
import Map from "./Map";

import "./styles.css";

const data = [
  {
    name: "Hello",
    title: "Sydney",
    lat: -33.847927,
    lng: 150.6517938,
    id: 1,
    color: "blue",
    url: "https://loc8tor.co.uk/wp-content/uploads/2015/08/stencil.png",
    // scaledSize: Size(90, 42), // scaled size - Not working//
     },
  {
javascript reactjs google-maps
1个回答
0
投票

scaledSize参数必须按照库的icon和Google的url一起与docs参数一起添加到标记的docs属性中。

因此,如果此对象包含两个参数:

var icon = {
  url: "https://loc8tor.co.uk/wp-content/uploads/2015/08/stencil.png",
  scaledSize: new this.props.google.maps.Size(90, 42)
};

将它们都作为对象一起传递到标记的icon属性中,如下所示:

<Marker
  onClick={this.onMarkerClick}
  key={place.id}
  place_={place}
  position={{ lat: place.lat, lng: place.lng }}
  icon={icon}
}

我已经通过上述更改对您的代码进行了测试,并且您的蓝色标记正确显示了指定的大小。因此希望对您有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.