polymer - Vaadin 14 聚合物元素 this.dispatchEvent 不是函数
问题描述
我正在尝试在传单和传单绘制之上编写一个聚合物包装器。我已经设法创建了地图和绘图工具栏,但是我无法使用 dispatchEvent 方法将事件发送到服务器,因为我正在获取Uncaught TypeError: this.dispatchEvent is not a function
. 我的课看起来像这样:
import { html, PolymerElement } from "@polymer/polymer/polymer-element.js";
import { ThemableMixin } from "@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js";
import * as L from "leaflet/dist/leaflet-src.js";
import * as LDraw from "leaflet-draw/dist/leaflet.draw-src.js";
import { LeafletTypeConverter } from "./leaflet-type-converter.js";
class LeafletMap extends ThemableMixin(PolymerElement) {
static get template() {
return html`
<div
id="map"
style="position: relative; width: 100%; height: 100%;"
></div>
`;
}
static get is() {
return "leaflet-map";
}
ready() {
super.ready();
console.info("LeafletMap - ready() leaflet map is ready.");
console.log("LeafletMap - ready() mapOptions: {}", this.mapOptions);
this.leafletConverter = new LeafletTypeConverter();
console.log("LeafletMap - ready() using converter", this.leafletConverter);
// init leaflet map
let map = this.toLeafletMap(this.mapOptions);
console.log('going to add draw items');
try {
var drawnItems = new L.FeatureGroup();
map.addLayer(drawnItems);
var drawControl = new L.Control.Draw({
edit: {
featureGroup: drawnItems
}
});
map.addControl(drawControl);
drawnItems.addTo(map);
} catch (e) {
console.log(e);
}
map.on(L.Draw.Event.CREATED, function (e) {
console.log('ON MAP CREATED, draw element');
console.log(e);
var type = e.layerType,
layer = e.layer;
if (type === 'marker') {
// Do marker specific actions
}
this.dispatchEvent(new CustomEvent('draw-end', {detail: {type: type}}));
map.addLayer(layer);
});
this.map = map;
}
我希望当在地图上绘制一个元素时,dispatchEvent 方法会在服务器上向我发回有关它的信息,因为 map.on() 回调上的前 2 个 console.logs 正在正确显示。
我在这里几乎是在黑暗中工作,因为我对使用聚合物元件的经验很少,所以欢迎任何帮助。
解决方案
推荐阅读
- javascript - 如何修复登录检查?
- javascript - Extjs6中change事件后执行clearicontap怎么办?
- java - LocalDate 正在默默地纠正错误的日期?
- html - 我如何创建一个包含 5 个 PARAGRAPH 元素的 DIV,每个元素包含一个带有 CSS 类属性的 SPAN 和另一个带有 CSS 类值的 SPAN
- wpf - 如何修改 AvalonDock NavigatorWindow
- php - 控制器方法中的参数顺序
- vue.js - 在更新了一定限制的行后隐藏行
- python-3.x - 尝试在 tkinter(python3)的选项菜单中获取选定值时出现问题
- python - 查找散景主题的有效属性
- javascript - 如何将正则表达式模式从 Javascript 转换为 Python?