在我的角度应用程序中,我使用ngMap进行谷歌地图并显示具有特定尺寸的div(宽度:400px和高度:300px)。现在,在某些情况下,我需要全屏显示地图。有没有办法为此添加双击或按钮或其他内容?
<div id="map"></div>
<script>
var lokacije = [];
id_maps = [];
for (key in data.smart_es) {
lokacije.push({
lat: data.smart_es[key].lat,
lng: data.smart_es[key].lng
});
}
$scope.lokacije = lokacije;
var mapOptions = {
zoom: 6,
center: new google.maps.LatLng(44.7007672, 15.4823411),
//mapTypeId: google.maps.MapTypeId.TERRAIN
styles: [{"featureType": "administrative", "elementType": "labels.text.fill", "stylers": [{"color": "#444444"}]}, {"featureType": "landscape", "elementType": "all", "stylers": [{"color": "#f2f2f2"}]}, {"featureType": "poi", "elementType": "all", "stylers": [{"visibility": "off"}]}, {"featureType": "poi.business", "elementType": "geometry.fill", "stylers": [{"visibility": "on"}]}, {"featureType": "road", "elementType": "all", "stylers": [{"saturation": -100}, {"lightness": 45}]}, {"featureType": "road.highway", "elementType": "all", "stylers": [{"visibility": "simplified"}]}, {"featureType": "road.arterial", "elementType": "labels.icon", "stylers": [{"visibility": "off"}]}, {"featureType": "transit", "elementType": "all", "stylers": [{"visibility": "on"}]}, {"featureType": "transit", "elementType": "labels", "stylers": [{"visibility": "off"}]}, {"featureType": "water", "elementType": "all", "stylers": [{"color": "#b2d0e3"}, {"visibility": "on"}]}]
};
$scope.map = new google.maps.Map(document.getElementById('map'), mapOptions);
//marker cluster
//kraj marker cluster
var infoWindow = new google.maps.InfoWindow();
$scope.markers = [];
var infoWindow = new google.maps.InfoWindow();
var getSmartnchIcon = function (smartnch) {
if (smartnch.type == 'urban') {
return 'assets/img/marker_urban.png';
} else {
return 'assets/img/marker_standard.png';
}
};
var createMarker = function (info) {
selectednches = info;
var nchTypeIconUrl = getSmartnchIcon(info);
if(info.lat !== null && info.lng !== null){
$scope.latitude = info.lat;
$scope.longitude = info.lng;
var marker = new google.maps.Marker({
map: $scope.map,
position: new google.maps.LatLng($scope.latitude, $scope.longitude),
optimized: false,
title: info.city,
icon: ypeIconUrl,
id: info.id
});
}else{
$scope.latitude = 43.5450037;
$scope.longitude = 16.4615604;
var marker = new google.maps.Marker({
map: $scope.map,
position: new google.maps.LatLng($scope.latitude, $scope.longitude),
optimized: false,
title: info.city,
icon: ypeIconUrl,
id: info.id
});
}
marker.content = '<div class="info-box-wrap">'
+
'<img src="" ng-click="openLightboxModal($index)"/>'
+
'<div class="info-box-text-wrap">'
+
'<h6 class="address">'
+
info.id + ' - ' + info.type
+
'</h6>'
+
'<p class="price">'
+
info.desc + '<br>'
+
info.last_report + '<br>'
+
'</p>'
+
'</div>'
+
'<div class="action-btns">'
+
'</div>'
+
'</div>'
+
'</div>' + marker.content;
google.maps.event.addListener(marker, 'click', function () {
infoWindow.setContent('<div class="iw-title" style="color: #000;">' + '</div>' + marker.content);
infoWindow.open($scope.map, marker);
});
$scope.markers.push(marker);
};
for (i = 0; i < lokacije.length; i++) {
createMarker(lokacije[i]);
}
$scope.openInfoWindow = function (e, selectedMarker) {
e.preventDefault();
google.maps.event.trigger(selectedMarker, 'click');
};
//marker clusterer
var options = {
imagePath: 'assets/img/i',
gridSize: 50,
maxZoom: 10
};
var markerCluster = new MarkerClusterer($scope.map, $scope.markers, options);
$scope.clearMarkers = function () {
for (var i = 0; i < $scope.markers.length; i++) {
$scope.markers[i].setMap(null);
}
$scope.markers.length = 0;
};
</script>
答案 0 :(得分:2)
您可以使用全屏api,请参阅Fullscreen API
function toggleFullScreen() {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen();
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
}
} }
答案 1 :(得分:1)
Google地图可以显示全屏按钮,查看documentation about controls。
全屏控件提供以全屏模式打开地图的选项。默认情况下,此控件在移动设备上启用,默认情况下在桌面上禁用。注意:iOS不支持全屏功能。因此,全屏控件在iOS设备上不可见。
因此,在您的代码中,您必须这样做:
var mapOptions = {
zoom: 6,
center: new google.maps.LatLng(44.7007672, 15.4823411),
//mapTypeId: google.maps.MapTypeId.TERRAIN
styles: [{"featureType": "administrative", "elementType": "labels.text.fill", "stylers": [{"color": "#444444"}]}, {"featureType": "landscape", "elementType": "all", "stylers": [{"color": "#f2f2f2"}]}, {"featureType": "poi", "elementType": "all", "stylers": [{"visibility": "off"}]}, {"featureType": "poi.business", "elementType": "geometry.fill", "stylers": [{"visibility": "on"}]}, {"featureType": "road", "elementType": "all", "stylers": [{"saturation": -100}, {"lightness": 45}]}, {"featureType": "road.highway", "elementType": "all", "stylers": [{"visibility": "simplified"}]}, {"featureType": "road.arterial", "elementType": "labels.icon", "stylers": [{"visibility": "off"}]}, {"featureType": "transit", "elementType": "all", "stylers": [{"visibility": "on"}]}, {"featureType": "transit", "elementType": "labels", "stylers": [{"visibility": "off"}]}, {"featureType": "water", "elementType": "all", "stylers": [{"color": "#b2d0e3"}, {"visibility": "on"}]}],
fullscreenControl:true
};