首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用agm-core绘制agm多边形?

如何使用agm-core绘制agm多边形?
EN

Stack Overflow用户
提问于 2019-05-29 23:21:16
回答 1查看 285关注 0票数 0

我可能在某个地方遇到了问题,但在我的地图上使用@agm-core组件绘制多边形是不可能的。

地图显示良好且配置良好。它会显示出来。

我的多边形点数组是(就像在控制台中写的那样):

代码语言:javascript
复制
markers: [{"lat":44.841225,"lng":-0.580036},
{"lat":44.842236,"lng":-0.64696},
{"lat":44.805615,"lng":-0.63084},
{"lat":43.248627,"lng":5.392345},
{"lat":43.249471,"lng":5.404018},
{"lat":43.246595,"lng":5.397924},
{"lat":43.24747,"lng":5.408825}]

在我的模板中我写道:

代码语言:javascript
复制
<agm-map [latitude]="coordinates.latitude" [longitude]="coordinates.longitude" [zoom]="15"
  <agm-polygon [paths]="markers">
  </agm-polygon>
</agm-map>

能告诉我这里发生了什么吗?

我要提前感谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2019-12-13 19:44:33

代码语言:javascript
复制
/// <reference types="@types/googlemaps" />
import { Component, HostListener, OnInit } from '@angular/core'

@Component({
  selector: 'bfx-map',
  templateUrl: './map.component.html',
  styleUrls: ['./map.component.scss'],
})
export class MapComponent implements OnInit {
  mapCenterPosition = {
      lat: 11.3821188,
      lng: 77.89472419999993,
    }
  map: google.maps.Map

  onMapReady(map: google.maps.Map) {
    this.map = map
    this.drawPolygon()
  }

  drawPolygon() {
    const paths = [
        { lat: 12.3175489124641, lng: 78.48798591874993 },
        { lat: 8.210490392434776, lng: 77.38935310624993 },
        { lat: 10.59482777210473, lng: 79.58661873124993 },
      ]
    const polygon = new google.maps.Polygon({
      paths: paths,
      editable: true,
      draggable: true,
    })

    polygon.setMap(this.map)
  }
  }


<agm-map
  [latitude]="mapCenterPosition.lat"
  [longitude]="mapCenterPosition.lng"
  (mapReady)="onMapReady($event)"
>
</agm-map>

需要npm i @types/googlemaps

你可以试着这样做。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56363875

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档