[英]Fontawsome as a custom marker for the react-google-maps/api component?
is there a way to use FA icon for the marker?有没有办法使用 FA 图标作为标记? I use this code sample:我使用此代码示例:
import React, { Component } from 'react';
import { GoogleMap, LoadScript } from '@react-google-maps/api';
const containerStyle = {
width: '400px',
height: '400px'
};
const center = {
lat: -3.745,
lng: -38.523
};
class MyComponents extends Component {
render() {
return (
<LoadScript
googleMapsApiKey="YOUR_API_KEY"
>
<GoogleMap
mapContainerStyle={containerStyle}
center={center}
zoom={10}
>
<Marker
position={center}
icon={'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png'}
/>
</GoogleMap>
</LoadScript>
)
}
}
There is the icon property on the Marker component, but it works like an url, like: Marker 组件上有 icon 属性,但它的作用类似于 url,例如:
<Marker position={center} icon={'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png'} />
I want to use the FA as a custom marker.我想使用 FA 作为自定义标记。
import { IconName } from "react-icons/fa";
Yes, you can use fortaswome icons for marker.是的,您可以使用 fortaswome 图标作为标记。
If want to use react-icons
, here is how you do that:如果想使用react-icons
,你可以这样做:
import { FaBeer } from "react-icons/fa";
...
<Marker
position={{
lat: 18.559024,
lng: -68.388886
}}
icon={{
path: FaBeer().props.children[0].props.d,
fillColor: "#0000ff",
fillOpacity: 1,
strokeWeight: 1,
strokeColor: "#ffffff",
scale: 0.075
}}
/>
Other option is to use @fortawesome/free-solid-svg-icons
.其他选择是使用@fortawesome/free-solid-svg-icons
。 In that case, code will look something like this:在这种情况下,代码将如下所示:
import { faCoffee } from "@fortawesome/free-solid-svg-icons/faCoffee";
...
<Marker
position={{
lat: 18.559024,
lng: -68.388886
}}
icon={{
path: faCoffee.icon[4],
fillColor: "#0000ff",
fillOpacity: 1,
strokeWeight: 1,
strokeColor: "#ffffff",
scale: 0.075
}}
/>
Source: official documentation来源: 官方文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.