angular - 如何在@angular/google-maps 模块中用自定义图标替换谷歌地图标记图标

标签 angular angular-material

组件.html:

  <google-map (mapClick)="click($event)" 
  [center]="center" [options]="options" height="500px" width="100%"
    [zoom]="zoom">

    <map-marker (mapClick)="openInfoWindow(marker)" [clickable]="true"
  
    *ngFor="let marker of markers" [position]="marker.position" [label]="marker.label"
      [title]="marker.title" [options]="marker.options">
    </map-marker>
    <map-info-window>Info Window content</map-info-window>
  </google-map>
组件.ts:
options: google.maps.MapOptions = {
    zoomControl: true,
    scrollwheel: false,
    disableDoubleClickZoom: true,
    maxZoom: 15,
    minZoom: 8,
  }
我尝试在选项中添加带有 url 值的图标属性,在 map 标记中传递输入但没有任何效果
https://github.com/angular/components/tree/master/src/google-maps#readme

最佳答案

至于 Angular 谷歌地图标记 ( https://github.com/angular/components/tree/master/src/google-maps/map-marker ) 文档,选项包括所有 map-marker不是“便利输入”的对象属性:

...this component offers an options input as well as convenience inputs for position, title, label, and clickable, and supports all google.maps.Marker events as outputs.


因此,任何其他不是“方便输入”的属性都必须像这样在 JSON 对象中传递给数组上的每个标记对象:
      const markers =[
      {...},
      {...},
      [{
        position:{
           lat: 24.1  + ((Math.random() - 0.5) * 2) / 100,
           lng: 0.2 + ((Math.random() - 0.5) * 2) / 100,
        },
        visible: true,
        opacity: 0.6,
        label: {
           color: '#333',
           text: 'My Label',
        },
        title: 'My Title',
           options = {
           draggable: false, 
           icon: '../assets/icons/MyMarker.png'
        }
      }],
      {...},
      {...}
    ];
或者,至少,这是在文档完成之前必须推断出来的。
只需在您的组件上通过此代码并用所需数据填充省略号对象,或者只需从您自己的数据中创建一个具有此结构的数组。

关于angular - 如何在@angular/google-maps 模块中用自定义图标替换谷歌地图标记图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62691617/

相关文章:

Angular 2 指令不起作用而降级

javascript - 在 Angular 8 中使用 @viewChild

javascript - 当我使用 Angular Material 和一些自定义代码时如何解决 Angular 应用程序中的 $event 问题

node.js - systemjs - 映射到不同的 URL

javascript - 如何检测 Angular2 中 div 的中间点击?

Angular-Material 日期时间选择器组件?

angular - 如何在 Angular 10 中使用异步管道检索数据后执行一些操作

css - 如何从垫选择下拉输入中删除动画

javascript - Angular Material - 当 md-chips 关闭时,自动完成功能不会显示建议

angular - Material 对话框 : Managing Z-index on click event with multiple Dialog instances