简体   繁体   English

将具有KML的相同地图放置在具有不同中心和缩放的页面上两次

[英]Placing same map w/KML twice on page with different center and zoom

I'm trying to place two maps with a KMLLayer side-by-side. 我正在尝试并排放置两张带KMLLayer的地图。 I have been able to get the maps to appear but they both use the same center lat/long ie the lat/long is not being honored for the second map. 我已经能够显示地图,但它们都使用相同的中心纬度/长度,即纬度/长度不适合第二张地图。 I want to zoom in to the lower left of the first map 35.04, -120.56 to display more detail. 我想放大第一个地图35.04的左下角,-120.56以显示更多细节。 How can I center/zoom the second map? 如何居中/缩放第二张地图?

I'm new to Fiddle - hopefully works: http://jsfiddle.net/BobH_SLOAPCD/d427zc46/4/ 我是小提琴的新手 - 希望有效: http//jsfiddle.net/BobH_SLOAPCD/d427zc46/4/

Map script 地图脚本

function initialize() {
  var myLatlng = new google.maps.LatLng(35.3, -120.3);

  var mapOptions = {
    maxZoom: 12,
    minZoom: 7,
    center: myLatlng,
    preserveViewport: true
  };

  var map = new google.maps.Map(document.getElementById('map-canvas'),
  mapOptions);

  var kmlLayer = new google.maps.KmlLayer({
    url: 'http://www.slocleanair.org/air/AQI_III/AQI_2015_yy_yy.kml',
    suppressInfoWindows: true,
    map: map
  });

  var myLatlng2 = new google.maps.LatLng(34.9, -120.5);

  var mapOptions2 = {
    maxZoom: 18,
    minZoom: 8,
    zoom: 9,
    center: myLatlng2,
    preserveViewport: true
  };

  var map2 = new google.maps.Map(document.getElementById('map-canvas2'),
  mapOptions2);

  var kmlLayer2 = new google.maps.KmlLayer({
    url: 'http://www.slocleanair.org/air/AQI_III/AQI_2015_yy_yy.kml',
    suppressInfoWindows: true,
    map: map2
  });
}
initialize();

HTML: HTML:

 <script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
 <p>Test KML Layers</p>
 <div id="map-canvas"></div>
 <div id="map-canvas2"></div>

CSS CSS

#map-canvas {
  width: 260px;
  height: 180px;
  padding: 10px;
  border: 2px solid #999;
  float:left;
}
#map-canvas2 {
  width: 260px;
  height: 180px;
  padding: 10px;
  border: 2px solid #999;

The preserveViewport option is a KmlLayers option, not a google.maps.Map option . preserveViewport选项是KmlLayers选项,而不是google.maps.Map选项 Note that if you use preserveViewport for both of the KmlLayers, you need to set the two mandatory options for the map (zoom and center). 请注意,如果您对两个 KmlLayers 使用preserveViewport,则需要为地图设置两个必填选项(缩放和居中)。

working fiddle 工作小提琴

working code snippet: 工作代码片段:

 function initialize() { var myLatlng = new google.maps.LatLng(35.3, -120.3); var mapOptions = { maxZoom: 12, minZoom: 7, center: myLatlng }; var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); var kmlLayer = new google.maps.KmlLayer({ url: 'http://www.slocleanair.org/air/AQI_III/AQI_2015_yy_yy.kml', suppressInfoWindows: true, map: map, // preserveViewport: true }); var myLatlng2 = new google.maps.LatLng(34.9, -120.5); var mapOptions2 = { maxZoom: 18, minZoom: 8, zoom: 9, center: myLatlng2 }; var map2 = new google.maps.Map(document.getElementById('map-canvas2'), mapOptions2); var kmlLayer2 = new google.maps.KmlLayer({ url: 'http://www.slocleanair.org/air/AQI_III/AQI_2015_yy_yy.kml', suppressInfoWindows: true, map: map2, preserveViewport: true }); } initialize(); 
 #map-canvas { width: 260px; height: 180px; padding: 10px; border: 2px solid #999; float:left; } #map-canvas2 { width: 260px; height: 180px; padding: 10px; border: 2px solid #999; } 
 <script src="http://maps.googleapis.com/maps/api/js"></script> <p>Test KML Layers</p> <div id="map-canvas"></div> <div id="map-canvas2"></div> <p>Big Map</p> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在一页上渲染两次相同的Google Map - Rendering same Google Map twice on one page 即使缩放比例不同,Openlayer也会以相同的缩放率在比例尺上重复缩放比例线两次 - Openlayers map scale line same zoom rate repeated twice in metric even-though the zoom differs 将多个d3图表放在同一页面上,但应用不同的样式 - placing multiple d3 charts on the same page but applying different styling 谷歌地图缩放和中心挑战 - google map zoom & center challenge 在复选框上保留Google地图缩放到kml图层的复选框 - Preserving Google map zoom to kml layer on checkbox click 如何在同一页面中使用不同的表格两次使用相同的javascript过滤器? - How to use same javascript filter twice in the same page with different tables? 在同一页面上放置2个JavaScript副本 - Placing 2 copies of javascript on same page 在 html 加载时缩放文本并在同一页面的不同位置淡出 - Zoom text on html load and fade out at different location on same page 谷歌地图 API 使用缩放级别和中心 position 从本地存储值调整 map 页面加载 - Google Maps API use zoom level and center position from local storage values to adjust map on page load 角度小叶指令可缩放到地图中心的标记 - Angular leaflet directive zoom to marker on the center of the map
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM