【问题标题】:Typescript Leaflet marker Custom property打字稿传单标记自定义属性
【发布时间】:2019-04-15 10:15:28
【问题描述】:

我想为每个标记添加一个自定义属性,当我尝试以下解决方案时,我收到此错误:

类型 '(latlng: LatLngExpressio n, options?: 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";

【问题讨论】:

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


【解决方案1】:

这对我有用:

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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-12
    • 1970-01-01
    • 2017-09-14
    • 1970-01-01
    • 1970-01-01
    • 2018-01-18
    相关资源
    最近更新 更多