谷歌地图自动设置位置:相对于#map div

The*_*zel 1 javascript css google-maps

我有一个奇怪的问题,或者至少对我来说有点奇怪。当我设置#map div 的样式并设置 position:fixed(因为我需要它作为背景)时,它会自动将位置设置为相对位置并覆盖我的设置。我不知道在哪里改变这种行为。

父类:

.wrapper {
  margin: 0;
  padding: 0;
  height: 100vh;
  z-index: 1;
  display: flex;
}
Run Code Online (Sandbox Code Playgroud)

和#map

 #map {
      height: 100%;
      width: 100vw;
      overflow: hidden;
      z-index: 0;
      top: 0;
      left: 0;
      position: fixed;
Run Code Online (Sandbox Code Playgroud)

代码很简单:

<div class="wrapper">
       <div id="map"></div>
        <div class="entries container">
            {% with 940 as width %}{% placeholder content %}{% endwith %}
            </p>
        </div>
    </div>
Run Code Online (Sandbox Code Playgroud)

现在,当我进入页面时,它首先呈现得很好,经过一毫秒的 js 应用,我假设 #map div 添加了这些行

element.style {
    position: relative;
    overflow: hidden;
}
Run Code Online (Sandbox Code Playgroud)

好吧,如果我手动更改它,它完全符合我的要求,但我无法禁用此覆盖。有没有其他人经历过这样的事情?我有点卡住了。

我使用 Chrome。

在此先感谢您的时间!问候

JS文件:

var map; 
function initialize() {
    var v = {lat: 4.00, lng: 7.00};

    var marker = new google.maps.Marker({
        position: v,
        map: map,
        title: 'V!'
    });

    var styleArray = [
        {
            "featureType": "all",
            "elementType": "all",
            "stylers": [
                {
                    "hue": "#ff0000"
                },
                {
                    "saturation": -100
                },
                {
                    "lightness": -30
                }
            ]
        },
        {
            "featureType": "all",
            "elementType": "labels.text.fill",
            "stylers": [
                {
                    "color": "#ffffff"
                }
            ]
        },
        {
            "featureType": "all",
            "elementType": "labels.text.stroke",
            "stylers": [
                {
                    "color": "#353535"
                }
            ]
        },
        {
            "featureType": "landscape",
            "elementType": "geometry",
            "stylers": [
                {
                    "color": "#656565"
                }
            ]
        },
        {
            "featureType": "poi",
            "elementType": "geometry.fill",
            "stylers": [
                {
                    "color": "#505050"
                }
            ]
        },
        {
            "featureType": "poi",
            "elementType": "geometry.stroke",
            "stylers": [
                {
                    "color": "#808080"
                }
            ]
        },
        {
            "featureType": "road",
            "elementType": "geometry",
            "stylers": [
                {
                    "color": "#454545"
                }
            ]
        }
    ];
    var mapOptions = {
        center: new google.maps.LatLng(47.295065, 7.937821),
        zoom: 14,
        zoomControl: true,
        zoomControlOptions: {
            style: google.maps.ZoomControlStyle.SMALL,
        },
        disableDoubleClickZoom: false,
        mapTypeControl: false,
        scaleControl: false,
        scrollwheel: false,
        panControl: false,
        streetViewControl: false,
        draggable: false,
        overviewMapControl: false,
        overviewMapControlOptions: {
            opened: false,
        },
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        styles: styleArray
    };
    map = new google.maps.Map(document.getElementById("map"),
        mapOptions);

    var locations = [
        ['V', 'undefined', 'undefined', 'undefined', 'undefined', 4.0, 7.0, 'https://mapbuildr.com/assets/img/markers/hollow-pin-red.png']
    ];
    for (i = 0; i < locations.length; i++) {
        if (locations[i][1] == 'undefined') {
            description = '';
        } else {
            description = locations[i][1];
        }
        if (locations[i][2] == 'undefined') {
            telephone = '';
        } else {
            telephone = locations[i][2];
        }
        if (locations[i][3] == 'undefined') {
            email = '';
        } else {
            email = locations[i][3];
        }
        if (locations[i][4] == 'undefined') {
            web = '';
        } else {
            web = locations[i][4];
        }
        if (locations[i][7] == 'undefined') {
            markericon = '';
        } else {
            markericon = locations[i][7];
        }
        marker = new google.maps.Marker({
            icon: markericon,
            position: new google.maps.LatLng(locations[i][5], locations[i][6]),
            map: map,
            title: locations[i][0],
            desc: description,
            tel: telephone,
            email: email,
            web: web
        });
        link = '';
    }

    map.panBy(0, 200);

}

google.maps.event.addDomListener(window, 'load', initialize);
google.maps.event.addDomListener(window, "resize", function () {
    var center = map.getCenter();
    google.maps.event.trigger(map, "resize");
    map.setCenter(center);

});
Run Code Online (Sandbox Code Playgroud)

小智 5

在使用 Google Map API 并使用 jQuery 显示地图时,我的情况也发生了同样的情况。在我的情况下,我使用 CSS 修复如下:

#map
{
    position: fixed !important; 
    height: 100% !important;
    width: 100% !important;
}
Run Code Online (Sandbox Code Playgroud)

显示地图的div元素如下:

<div id="map"></div>
Run Code Online (Sandbox Code Playgroud)