Коэффициент масштабирования по умолчанию отображения карты Google на моем веб-сайте не отвечает (в JavaScript) - PullRequest
0 голосов
/ 25 мая 2018

Newbee in js here ... Я пытаюсь отобразить мою карту Google в увеличенном масштабе на моем веб-сайте.Изменение числа увеличения в

 zoom: 15, 

не имеет никакого эффекта.Что здесь не так?Пожалуйста помоги.Смотрите проблему в jsfiddle .

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
	zoom: 15,
	center: {lat: 52.132633, lng: 5.291266}
  });
  var georssLayer = new google.maps.KmlLayer({
    url: 'https://www.tso-assistent.nl/js/TSO-ASSISTENT.kmz',
  });  
  georssLayer.setMap(map);
}
// https://developers.google.com/maps/documentation/javascript/examples/icon-simple
// Loop through the results array and place a marker for each
// set of coordinates.
window.eqfeed_callback = function(results) {
  for (var i = 0; i < results.features.length; i++) {
    var coords = results.features[i].geometry.coordinates;
    var latLng = new google.maps.LatLng(coords[1],coords[0]);
    var marker = new google.maps.Marker({
      position: latLng,
      map: map
    });
  }
}
/* Always set the map height explicitly to define the size of the div
 * element that contains the map. */
#map {
  height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}
<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
        <script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBqjPjdmeqpVPBJqQ2QxOvk6g8uHRTou9k&callback=initMap"></script>

1 Ответ

0 голосов
/ 25 мая 2018

Ваш слой KML имеет приоритет над значением масштаба.

Чтобы сохранить масштаб, вы должны использовать preserveViewport: true

Вы должны использовать вот так

var georssLayer = new google.maps.KmlLayer({
    url: 'https://www.tso-assistent.nl/js/TSO-ASSISTENT.kmz',
    preserveViewport: true
  });

Обновлено скрипка

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
	zoom: 7,
	center: {lat: 52.132633, lng: 5.291266}
  });
  var georssLayer = new google.maps.KmlLayer({
    url: 'https://www.tso-assistent.nl/js/TSO-ASSISTENT.kmz',
    preserveViewport: true
  });  
  georssLayer.setMap(map);
}
// https://developers.google.com/maps/documentation/javascript/examples/icon-simple
// Loop through the results array and place a marker for each
// set of coordinates.
window.eqfeed_callback = function(results) {
  for (var i = 0; i < results.features.length; i++) {
    var coords = results.features[i].geometry.coordinates;
    var latLng = new google.maps.LatLng(coords[1],coords[0]);
    var marker = new google.maps.Marker({
      position: latLng,
      map: map
    });
  }
}
/* Always set the map height explicitly to define the size of the div
 * element that contains the map. */
#map {
  height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}
<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
        <script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBqjPjdmeqpVPBJqQ2QxOvk6g8uHRTou9k&callback=initMap"></script>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...