【发布时间】:2020-03-06 11:17:29
【问题描述】:
我想在 NextJS(typescript) 中使用 Leaflet。
但 Leaflet 不支持 SSR。所以,我使用react-leaflet-univarsal。
然后,我自定义了 Leaflet 的 Marker 组件。所以,我想使用Leaflet.Icon。
我尝试了 2 件事。
if(process.browser){}
找不到window。
- 对
next/dynamic使用动态导入
let iconPerson: any;
const DynamicComponent = dynamic(
() =>
import('leaflet').then(L => {
iconPerson = (L as any).Icon.extend({
options: {
iconUrl: '/images/icon1.jpg',
iconRetinaUrl: '/images/icon1.jpg',
iconSize: new (L as any).Point(60, 75),
className: 'leaflet-div-icon',
},
});
}) as any,
{ ssr: false },
);
....
<Marker icon={iconPerson}>
这是打印出来的。 > 无法读取未定义的属性“createIcon”
NextJS 使用L.icon 的方式吗?
【问题讨论】:
标签: reactjs typescript leaflet next.js