打字稿传单标记自定义属性

时间:2018-11-12 16:36:54

标签: angular typescript leaflet angular-leaflet-directive leaflet.markercluster

当我尝试以下解决方案时,我想向每个标记添加自定义属性,但出现此错误:

  

类型'('latlng:LatLngExpressio'中不存在属性'myCustomID'   n,选项?:MarkerOptions)=>标记'。

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";

1 个答案:

答案 0 :(得分:0)

对我有用:

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对象中,如下所示: options['customProperty'] = customValue;