【发布时间】:2016-09-08 20:22:55
【问题描述】:
伙计们,我对来自 Angular 谷歌地图的 InfoWindows 有疑问。 从this fiddle 可以看到(来自this 问题):
- 信息窗口确实出现在标记的底部 --> 非常难看,它应该出现在顶部(与普通的谷歌地图信息窗口相同)
- 我想要动态的“标题”,所以每个信息窗口都应该有基于标记的不同内容 --> 标记的当前地址,以后可能会更多。
我已经用谷歌搜索了几个小时,但很遗憾我无法解决这个问题。任何帮助都非常感谢(因为我认为其他人也有这个问题):)。
var myApp = angular.module('app', ['uiGmapgoogle-maps']);
myApp.config(function (uiGmapGoogleMapApiProvider) {
uiGmapGoogleMapApiProvider.configure({
key: '',
v: '3',
libraries: 'weather,geometry,visualization'
});
});
myApp.controller('MainCtrl', function ($scope, uiGmapGoogleMapApi, uiGmapIsReady) {
uiGmapGoogleMapApi.then(function (maps) {
$scope.googlemap = {};
$scope.map = {
center: {
latitude: 37.78,
longitude: -122.41
},
zoom: 14,
pan: 1,
options: $scope.mapOptions,
control: {},
events: {
tilesloaded: function (maps, eventName, args) {},
dragend: function (maps, eventName, args) {},
zoom_changed: function (maps, eventName, args) {}
}
};
});
$scope.windowOptions = {
show: false
};
$scope.onClick = function (data) {
$scope.windowOptions.show = !$scope.windowOptions.show;
console.log('$scope.windowOptions.show: ', $scope.windowOptions.show);
console.log('This is a ' + data);
//alert('This is a ' + data);
};
$scope.closeClick = function () {
$scope.windowOptions.show = false;
};
$scope.title = "Window Title!";
uiGmapIsReady.promise() // if no value is put in promise() it defaults to promise(1)
.then(function (instances) {
console.log(instances[0].map); // get the current map
})
.then(function () {
$scope.addMarkerClickFunction($scope.markers);
});
$scope.markers = [{
id: 0,
coords: {
latitude: 37.7749295,
longitude: -122.4194155
},
data: 'restaurant'
}, {
id: 1,
coords: {
latitude: 37.79,
longitude: -122.42
},
data: 'house'
}, {
id: 2,
coords: {
latitude: 37.77,
longitude: -122.41
},
data: 'hotel'
}];
$scope.addMarkerClickFunction = function (markersArray) {
angular.forEach(markersArray, function (value, key) {
value.onClick = function () {
$scope.onClick(value.data);
$scope.MapOptions.markers.selected = value;
};
});
};
$scope.MapOptions = {
minZoom: 3,
zoomControl: false,
draggable: true,
navigationControl: false,
mapTypeControl: false,
scaleControl: false,
streetViewControl: false,
disableDoubleClickZoom: false,
keyboardShortcuts: true,
markers: {
selected: {}
},
styles: [{
featureType: "poi",
elementType: "labels",
stylers: [{
visibility: "off"
}]
}, {
featureType: "transit",
elementType: "all",
stylers: [{
visibility: "off"
}]
}],
};
});
【问题讨论】:
-
如果您解决了问题,请告诉我。
标签: javascript angularjs google-maps