【发布时间】:2018-05-23 06:10:49
【问题描述】:
我尝试了我在网络上找到的所有东西,Stackoverflow 和 Github,但仍然无法成功。
我想使用自定义图标制作自定义标记,但使用下面的代码时,我总是遇到错误:'TypeError: options.icon.createIcon is not a function'
这是我的代码(文件夹路径没有错误,一切都在 src/js 或 src/img 中)
图标.js
import L from 'leaflet';
const iconPerson = L.Icon.extend({
options: {
iconUrl: require('../img/marker-pin-person.svg'),
iconRetinaUrl: require('../img/marker-pin-person.svg'),
iconAnchor: null,
popupAnchor: null,
shadowUrl: null,
shadowSize: null,
shadowAnchor: null,
iconSize: new L.Point(60, 75),
className: 'leaflet-div-icon'
}
});
export { iconPerson };
MarkerPinPerson
import React from 'react';
import { Marker } from 'react-leaflet';
import { iconPerson } from './Icons';
export default class MarkerPinPerson extends React.Component {
render() {
return (
<Marker
position={this.props.markerPosition}
icon={ iconPerson }
>
</Marker>
);
}
}
真的在寻求您的帮助!
【问题讨论】:
标签: icons maps leaflet marker react-leaflet