gpt4 book ai didi

javascript - Ng-map-show all marker on map-如何计算缩放级别和中心位置

转载 作者:行者123 更新时间:2023-11-30 15:57:49 25 4
gpt4 key购买 nike

我使用 ng-map 加载 map 并显示标记如下代码。

<ng-map center="[{{userpos.coords.latitude}},{{userpos.coords.longitude}}]" zoom="12" default-style="false">
<div ng-repeat="p in points">
<marker title="{{p.title}}" icon="{{getMarker(p.warning)}}" position="{{p.latitude}}, {{p.longitude}}" ></marker>
</div>
</ng-map>

我的问题是所有标记都无法在 map 中显示。要显示所有内容,我必须设置合适的缩放和居中指令。如何找到它们

最佳答案

为此,在 ngMap (1.10.0) 中引入了 zoom-to-include-markers 属性。

该示例演示了如何居中/缩放 map 以覆盖所有可见标记

angular.module('ngMap').controller('MyCtrl', function($scope) {
$scope.points =[
{title: '', latitude: 40.71, longitude: -74.21},
{title: '', latitude: 41.72, longitude: -73.20},
{title: '', latitude: 42.73, longitude: -72.19},
{title: '', latitude: 43.74, longitude: -71.18},
{title: '', latitude: 44.75, longitude: -70.17},
{title: '', latitude: 45.76, longitude: -69.16},
{title: '', latitude: 46.77, longitude: -68.15}
];

});
<script type="text/javascript" src="https://maps.google.com/maps/api/js"></script>
<script type="text/javascript" src="https://code.angularjs.org/1.3.15/angular.js"></script>
<script type="text/javascript" src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>

<div ng-app="ngMap" ng-controller="MyCtrl">
<ng-map
zoom-to-include-markers="true">

<div ng-repeat="p in points">
<marker title="{{p.title}}" position="{{p.latitude}}, {{p.longitude}}" ></marker>
</div>
</ng-map>
</div>

JSFiddle

More examples来自 ng-map 存储库

关于javascript - Ng-map-show all marker on map-如何计算缩放级别和中心位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38220115/

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