Javascript 使用ngmap在标记之间创建一条线
我使用ngmap和angular js在地图上毫无问题地显示一组标记。我需要画一条线连接这些标记 我的代码: 鉴于:Javascript 使用ngmap在标记之间创建一条线,javascript,angularjs,ng-map,Javascript,Angularjs,Ng Map,我使用ngmap和angular js在地图上毫无问题地显示一组标记。我需要画一条线连接这些标记 我的代码: 鉴于: 为此,您可以使用shape指令,例如: <shape name="polyline" path="{{path}}" geodesic="true" stroke-color="#FF0000" stroke-opacity="1.0" stroke-weight="2"></shape> 工作示例 var-app=angular.module('a
为此,您可以使用
shape
指令,例如:
<shape name="polyline" path="{{path}}" geodesic="true" stroke-color="#FF0000" stroke-opacity="1.0" stroke-weight="2"></shape>
工作示例
var-app=angular.module('appMaps',['ngMap']);
应用程序控制器('mainCtrl',函数($scope){
$scope.markers=[{id:1,lat:37.772323,lng:-122.214897},{id:2,lat:21.291982,lng:-157.821856},{id:3,lat:-27.46758,lng:153.027892}];
$scope.path=$scope.markers.map(函数(标记){
返回[marker.lat,marker.lng];
});
});代码>
为此,您可以使用shape
指令,例如:
<shape name="polyline" path="{{path}}" geodesic="true" stroke-color="#FF0000" stroke-opacity="1.0" stroke-weight="2"></shape>
工作示例
var-app=angular.module('appMaps',['ngMap']);
应用程序控制器('mainCtrl',函数($scope){
$scope.markers=[{id:1,lat:37.772323,lng:-122.214897},{id:2,lat:21.291982,lng:-157.821856},{id:3,lat:-27.46758,lng:153.027892}];
$scope.path=$scope.markers.map(函数(标记){
返回[marker.lat,marker.lng];
});
});代码>
对于希望在标记之间显示行驶方向并自定义每个标记之间线条外观的用户:
工作示例:
在控制器中:
$scope.directions = [
{
origin:"Salt Lake City, Utah",
destination:"West Valley City, Utah",
panelName:"p1",
renderingOptions: {
polylineOptions: {
strokeColor: 'red'
}
},
wayPoints: [
{
location: {lat:40.6812675, lng: -111.9622787},
stopover: true
},
{
location: {lat:40.6812675, lng: -110.9622787},
stopover: true
},
]
},
{
origin:"West Valley City, Utah",
destination:"West Jordan, Utah",
panelName:"p1",
renderingOptions: {
polylineOptions: {
strokeColor: 'blue'
}
},
wayPoints: [
{
location: {lat:40.6812675, lng: -111.9622787},
stopover: true
},
{
location: {lat:40.6812675, lng: -109.9622787},
stopover: true
},
]
},
{
origin:"West Jordan, Utah",
destination:"Salt Lake City, Utah",
panelName:"p2",
renderingOptions: {
polylineOptions: {
strokeColor: 'green'
}
},
wayPoints: [
{
location: {lat:40.6812675, lng: -111.9622787},
stopover: true
},
{
location: {lat:40.6812675, lng: -108.9622787},
stopover: true
},
]
}
];
HTML:
传递窗体的对象:
renderingOptions:{polylineOptions:{strokeColor:'red'}}
进入
元素的选项属性
<div style="width: 100%; float:left; height:70%" >
<ng-map zoom="3" center="current-location" default-style="false" style="height: 450px; display:block; ">
<directions ng-repeat="dir in directions"
draggable="true"
options="{{dir.renderingOptions}}"
travel-mode="DRIVING"
waypoints="{{dir.wayPoints}}"
panel="{{dir.panelName}}"
origin="{{dir.origin}}"
destination="{{dir.destination}}">
</directions>
</ng-map>
</div>
对于希望在标记之间显示行驶方向并自定义每个标记之间线条外观的用户:
工作示例:
在控制器中:
$scope.directions = [
{
origin:"Salt Lake City, Utah",
destination:"West Valley City, Utah",
panelName:"p1",
renderingOptions: {
polylineOptions: {
strokeColor: 'red'
}
},
wayPoints: [
{
location: {lat:40.6812675, lng: -111.9622787},
stopover: true
},
{
location: {lat:40.6812675, lng: -110.9622787},
stopover: true
},
]
},
{
origin:"West Valley City, Utah",
destination:"West Jordan, Utah",
panelName:"p1",
renderingOptions: {
polylineOptions: {
strokeColor: 'blue'
}
},
wayPoints: [
{
location: {lat:40.6812675, lng: -111.9622787},
stopover: true
},
{
location: {lat:40.6812675, lng: -109.9622787},
stopover: true
},
]
},
{
origin:"West Jordan, Utah",
destination:"Salt Lake City, Utah",
panelName:"p2",
renderingOptions: {
polylineOptions: {
strokeColor: 'green'
}
},
wayPoints: [
{
location: {lat:40.6812675, lng: -111.9622787},
stopover: true
},
{
location: {lat:40.6812675, lng: -108.9622787},
stopover: true
},
]
}
];
HTML:
传递窗体的对象:
renderingOptions:{polylineOptions:{strokeColor:'red'}}
进入
元素的选项属性
<div style="width: 100%; float:left; height:70%" >
<ng-map zoom="3" center="current-location" default-style="false" style="height: 450px; display:block; ">
<directions ng-repeat="dir in directions"
draggable="true"
options="{{dir.renderingOptions}}"
travel-mode="DRIVING"
waypoints="{{dir.wayPoints}}"
panel="{{dir.panelName}}"
origin="{{dir.origin}}"
destination="{{dir.destination}}">
</directions>
</ng-map>
</div>