Typescript传单标记自定义属性



我想为每个标记添加一个自定义属性,当我尝试下面的解决方案时,我得到了这个错误:

类型"上不存在属性"myCustomID"(latlng:LatLngExpression、 选项?:MarkerOptions(=>Marker'。

let customMarker = L.marker([item.latitude, item.longitude], {
  //  customId:"010000006148",
  icon: icon({
    iconSize: [ 30, 41 ],
    iconAnchor: [ 13, 41 ],
    iconUrl: 'assets/icons8-street-view-64.png',
    shadowUrl: 'leaflet/marker-shadow.png'
  })
})
customMarker.myCustomID = "010000006148";

这对我有用:

private addMarker(occurrence: Occurrence) {
        const options = {icon: this.icon};
        options['situation'] = occurrence.situation.value;
        this.mapOptions.layers.push(marker([occurrence.latitude, occurrence.longitude], options)
            .bindPopup(() => this.getPopupElement(occurrence)));
    }

尝试将您的自定义属性放在标记的选项对象中,如下所示:options['customProperty'] = customValue

最新更新