【问题标题】:How to remove landmarks from google map with google map angular component如何使用谷歌地图角度组件从谷歌地图中删除地标
【发布时间】:2020-10-31 19:15:15
【问题描述】:

我正在使用google map angular component,它工作得很好!

但现在我想从地图中删除一些地标以减少拥堵,以便能够更清楚地显示我的标记。

我在下面找到了这些资源,但不知道如何将其应用于我正在使用的 节点包。

  1. Site to create json for hiding landmarks and other features on map
  2. shows how to hide map features from google map dev site
  3. SO link that describes same issue

我在google documentation 中看到它显示了使用 'setMapStyle()' 将样式应用于 'googlemap' 但这不是 angular 包中的方法

下面是我使用谷歌地图的组件(不是所有代码),但它显示了我如何使用地图的所有代码

import {
  MapInfoWindow,
  MapMarker,
  GoogleMap
} from '@angular/google-maps';

export class YogabandEventsComponent implements OnInit {
  colContentRef: ElementRef;
  @ViewChild(GoogleMap, {
    static: false
  }) googleMap: GoogleMap;
  @ViewChild(MapInfoWindow, {
    static: false
  }) infoWindow: MapInfoWindow;

  zoom = 12;
  center: google.maps.LatLngLiteral;
  options: google.maps.MapOptions = {
    mapTypeId: 'roadmap',
    mapTypeControl: false,
    scrollwheel: true,
    maxZoom: 18,
    minZoom: 10,
    streetViewControl: false,
    fullscreenControl: false
  };

  markers: Marker[];
  infoContent = '';

  constructor(...) { ...
  }

  openInfo(marker: MapMarker, content) {
    this.infoContent = content;
    this.infoWindow.open(marker);
  }

  showMarkers() {
    this.markers = [];
    for (const ybEvent of this.yogabandEvents) {
      const marker = new Marker();
      marker.info = ybEvent.name;
      marker.title = ybEvent.name;
      marker.position = {
        lat: ybEvent.latitude,
        lng: ybEvent.longitude
      };
      marker.label = {
        color: '#17a2b8',
        text: ybEvent.yogaType,
        fontWeight: 'bold',
        fontSize: '16px'
      };
      marker.options = {
        icon: {
          // scaledSize: new google.maps.Size(40, 40),
          url: 'assets/images/marker.svg',
          labelOrigin: new google.maps.Point(18, 50)
        }
      };
      this.markers.push(marker);
    }
  }

}
<div class="col flex-fill h-100 px-0 right-col">
  <google-map [options]="options" [zoom]="zoom" [center]="center" class="h-100" height="100%" width="100%">
    <map-marker #markerElem *ngFor="let marker of markers" [position]="marker.position" [label]="marker.label" [title]="marker.title" [options]="marker.options" (mapClick)="openInfo(markerElem, marker.info)">
    </map-marker>
    <map-info-window>{{ infoContent }}</map-info-window>
  </google-map>
</div>

【问题讨论】:

    标签: javascript angular google-maps google-maps-api-3


    【解决方案1】:

    尝试使用MapOptions interfacestyles 属性。 像这样:

    options: google.maps.MapOptions = {
        mapTypeId: 'roadmap',
        mapTypeControl: false,
        scrollwheel: true,
        maxZoom: 18,
        minZoom: 10,
        streetViewControl: false,
        fullscreenControl: false,
        styles: [...]
      };
    

    详细的样式可能会有点烦人。您可以从 Styling Wizard 生成一组样式(它还有一个 Landmarks 幻灯片可以逐渐删除它们,然后只需导出样式数组)。

    【讨论】:

    • 您好,谢谢!这似乎奏效了。我从向导中创建了一些样式,然后将其粘贴到 MapOptions 中的样式属性中。
    • 太棒了!如果解决了您的问题,请帮我投票并将答案标记为正确。如果您需要其他任何东西,请回来;)我知道有时使用地图可能会很痛苦。哈哈
    • 实际上我还有另一个问题,但打算在新线程中发布。我想设置标记标签的背景颜色。我已经用“labelOrigin”设置了位置,并在开发工具中查看标签,我看不到任何可以用来为背景着色的东西。
    • 实际上,我认为为了让事情井井有条(如果规则说明了,IDK 也可以),最好设置一个线程,因为它不是标题所说的。因此,最好创建发布新问题或更新此问题以涵盖这两个项目。
    • 我发了一个新帖子:stackoverflow.com/questions/62845022/…
    猜你喜欢
    • 2018-10-13
    • 2014-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-18
    • 2012-10-17
    • 2019-03-12
    • 2017-10-09
    相关资源
    最近更新 更多