导入扩展类的模块 [英] Importing module that extends a class

查看:144
本文介绍了导入扩展类的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

leaflet.js 中寻找一种旋转标记的方法时,我发现了模块

While looking for a way to rotate markers in leaflet.js, I found the module leaflet-rotatedmarker. I installed it via npm, but now I don't know how to actually use it.

根据自述文件,它仅扩展了现有的Marker类.据我了解,我现在应该可以只调用Marker.setRotationAngle(),但是该功能不存在.从leaflet-rotatedmarker导入Marker也不起作用.

As per the readme, it only extends the existing Marker class. To my understanding, I should be able to just call Marker.setRotationAngle() now, but that function does not exist. Importing Marker from leaflet-rotatedmarker does not work either.

如何正确导入扩展类或如何使用模块中的功能/属性扩展现有的传单类?谢谢.

How do I properly import the extended class or how do I extend the existing leaflet class with the functions/attributes in the module? Thanks.

我正在谈论import { XYZ } from 'leaflet-rotatedmarker'声明.

如果我尝试在构造函数中设置rotationAngle,它也将不起作用:

It also does not work if I try to set the rotationAngle in the constructor:

const marker = L.marker([tmpAgv.Pos.X, tmpAgv.Pos.Y], { alt: tmpAgv.Id }, {rotationAngle: 180}).addTo(this.mapObject);

标记仍未旋转.

推荐答案

我安装了与您相同的软件包:

I installed the same package you have:

npm install leaflet-rotatedmarker

并导入它:

import 'leaflet-rotatedmarker';

这就是我的用法:

let m = L.marker([lat,lng]).addTo(this.map);
m.setRotationAngle(180);

结果前后:

之后:

这篇关于导入扩展类的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆