单击地图时,如何在React传单中添加自定义字体效果图标标记?

时间:2019-07-02 07:08:15

标签: reactjs dictionary react-leaflet

我使用react-leaflet软件包,并且当用户单击地图上的点时(例如,当地方是地铁,图标变成地铁图标等)时,我需要添加自定义字体。 我的意思是用户点击地图时选择图标,或者点击地图时添加图标。

1 个答案:

答案 0 :(得分:0)

也许尝试这样的事情?

import { Marker } from "react-leaflet";
import { divIcon } from "leaflet";
import { renderToStaticMarkup } from "react-dom/server";

class MyCustomMarker extends React.Component {

  generateMarkerContent = fontAwesomeConfig => {
    const { fontAwesomeConfig } = this.props;
    return (
      <div className="my-custom-icon-content">
        {/* Render based on the font awesome config here */}
      </div>
    );
  };

  render(){
    const icon = divIcon({
      className: "my-custom-icon",
      iconSize:[24, 24],
      html: return renderToStaticMarkup(this.generateMarkerContent(t))
    });

    return (
      <Marker {...this.props} icon={icon} />
    )
  }
}