gpt4 book ai didi

angular - 如何在编辑和拖动时获取agm多边形的路径?

转载 作者:太空狗 更新时间:2023-10-29 16:58:57 25 4
gpt4 key购买 nike

我试图在编辑和拖动多边形时获取更新的多边形路径。我试着像下面的代码那样做。

在我的 typescript 中:

 @ViewChild(AgmPolygon) polygon: any;
this.polygon.getPaths().then((x: any[]) => {
x.forEach(y => {
console.log('-');
y.forEach(z => console.log(z.lat(), z.lng()));
});
});

我也点击了以下链接 1st link 2nd link .

在我的 html 中:

<agm-map [latitude]="lat" [fullscreenControl]="true" 
(mapClick)="mapClicked($event)" [longitude]="lng" [zoom]="8" [mapTypeControl]="true">

<agm-polygon [fillColor]="item.fillColor" (polyMouseOut)="polyMouseOut($event)"
(polyMouseMove)="polyMouseMove($event)" [fillOpacity]="item.fillOpacity"
*ngFor="let item of zonesPath; let i=index" [editable]="item.ZoneID==ZoneID"
(polyMouseUp)="polyMouseUp(item,$event)" (polyMouseDown)="polyMouseDown($event)"
(polyDblClick)="polyDblClick($event)" (polyDragStart)="polyDragStart($event)"
(polyDragEnd)="polyDragEnd($event,item)" (polyDrag)="polyDrag($event)"
[polyDraggable]="false" [paths]="item.ZonePaths" (polyClick)="polyclick($event)">
</agm-polygon>

<agm-polygon [paths]="paths"></agm-polygon>
</agm-map>

我正在为多边形做 *ngFor。我的 json 数据是:

{
"ZoneID": "594dff0ee10452d8567b23c6",
"strokeColor" : "#038063",
"strokeOpacity" : 0.2,
"strokeWeight" : 2,
"fillColor" : "#038063",
"fillOpacity" : 0.35,
"draggable" : false,
"editable" : false,
"visible" : true,
"ZonePaths": [
{
"lat" : 17.535107299215,
"lng" : 78.2346725463869
},
{
"lat" : 17.541981926489,
"lng" : 78.240509033203
},
{
"lat" : 17.54460076354,
"lng" : 78.249778747559
},
{
"lat" : 17.55082034986,
"lng" : 78.284454345703
}]}

最佳答案

在阅读 ATM agm polygon edit change event 后我不得不克服这个问题,它仍然在 PR 上。

因此,我回归基础并寻找 google map api class v3。

@ViewChild(AgmMap) map: any;
polygon: any;
this.map._mapsWrapper.createPolygon({
paths: this.area,
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.3,
editable: true,
}).then((polygon: any) => {
this.polygon = polygon
});

在此之后,您可以添加事件或使用 getPath() 获取路径更改

console.debug(this.polygon.getPath())

关于angular - 如何在编辑和拖动时获取agm多边形的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47131170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com