gpt4 book ai didi

javascript - 在 AngularUI 谷歌地图上动态设置圆的半径

转载 作者:行者123 更新时间:2023-11-28 02:49:54 24 4
gpt4 key购买 nike

如标题所示,我想动态更改我的 ui-gmap-google-map 元素上的圆的半径,我尝试在文本框上使用 onChange 函数来请求像这样的半径:

HTML

<label for="distance" style="white-space: nowrap;">Enter a radius</label>
<input type="text" required class="form-control" placeholder="Kilometers" ng-change="setRadius()" name="distance" ng-model="map.marker.circle.radius" />

在我的 Controller 中

$scope.setRadius = function() {
$scope.circles.radius = $scope.map.marker.circle.radius * 1000;
}

我也试过在“circles”数组中直接更改它,但还是没有结果。

圆形数组

$scope.circles = [
{
id: 1,
center: {
latitude: $scope.map.center.latitude,
longitude: $scope.map.center.longitude
},
radius: $scope.circleRadius,
stroke: {
color: '#08B21F',
weight: 2,
opacity: 1
},
fill: {
color: '#08B21F',
opacity: 0.5
},
geodesic: true, // optional: defaults to false
draggable: false, // optional: defaults to false
clickable: false, // optional: defaults to true
editable: false, // optional: defaults to false
visible: true, // optional: defaults to true
control: {}
}
];

改变半径的函数

$scope.setRadius = function() {
$scope.circleRadius = $scope.map.marker.circle.radius * 1000;
}

map 的 HTML

<ui-gmap-google-map center="map.center" zoom="map.zoom">
<ui-gmap-window show="map.window.show" coords="map.window.model" options="map.window.options" closeclick="map.window.closeClick()">

</ui-gmap-window>

<ui-gmap-circle ng-repeat="c in circles track by c.id" center="c.center" stroke="c.stroke" fill="c.fill" radius="c.radius" visible="c.visible" geodesic="c.geodesic" editable="c.editable" draggable="c.draggable" clickable="c.clickable" control="c.control"></ui-gmap-circle>

最佳答案

我通过直接在圆数组中设置半径来简单地解决了这个问题(我不觉得这是最好的做法,但它有效。

澄清一下:当距离发生变化时,我调用 setRadius() 函数并通过调用 $scope.circles[0].radius 简单地设置半径,它设置半径。

不需要别的

关于javascript - 在 AngularUI 谷歌地图上动态设置圆的半径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39792264/

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