angular - 使用 @angular/google-maps 将自定义样式添加到 Angular map

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

我正在使用 Angular 11 和 @angular/google-maps,我希望创建一个与其父级宽度相同的 map ,但我只能获得一个方形 map (如图所示) Actual map display

我正在使用我的 API key 调用 index.html 中的 google-maps api 脚本

<script async defer src="https://maps.googleapis.com/maps/api/js?key=MY_API_KEY"
  type="text/javascript"></script>

并在我的overview.component.ts中生成 map

    <div id='map'>
      <google-map [center]='center'></google-map>
    </div>

overview.component.scss中为其指定以下样式

.main-container {
  width: 100%;
  height: 100%;
}

#map {
  padding: 1% 1% 1% 1%;
  width: 100% !important;
  height: 400px !important;
}

我也尝试过使用 google-map 标签本身,但没有任何运气

最佳答案

您需要在 google-map 标记中设置宽度。

<google-map width="100%"></google-map>

您可以在文档 here 中找到更多信息

这是一个 stackblitz 示例 here

关于angular - 使用 @angular/google-maps 将自定义样式添加到 Angular map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65783399/

相关文章:

android - 开发人员知道用户将预装 Google map 的优势

javascript - 当这些 javascript 函数触发时,我是否正确地使用了 setTimeout() ?

javascript - 类型错误 : Unable to get property 'ngMetadataName' of undefined or null reference on IE 10

javascript - 如何将 Angular 中的日期作为时间戳保存到 Firestore?

javascript - 我想根据使用 Angular 调整窗口大小来动态更改父级和子级 div 的高度

PHP、MySQL、谷歌地图问题

html - 谷歌地图标记不拖动

angular - 如何使用primeng将电话号码附加到 Angular 5的国家代码

Android map - 限制在 180 度

google-maps-api-3 - 隐藏折线的正确方法?