简体   繁体   English

Google地图:在主视口的子边界框内缩放和平移

[英]Google Maps: Zoom and pan inside a sub bounding box in the main viewport

I am creating a google map with some specific requirements. 我正在创建一些特定要求的谷歌地图。 The map is lets say 800x600 pixels wide. 地图可以说是800x600像素宽。

I need all the markers to show in an area of 400x600px on the left hand side of the map. 我需要所有标记在地图左侧的400x600px区域中显示。 The other half is covered with navigation panels (but the map must be visible in the margins behind the panels). 另一半覆盖有导航面板(但地图必须在面板后面的空白处可见)。

I've been able to set the zoom level according to all the markers using LatLngBounds and fitBounds, but that still fills the entire area. 我已经能够使用LatLngBounds和fitBounds根据所有标记设置缩放级别,但是仍然可以填充整个区域。

How do I create a sub bounding area inside the viewport to contain all the markers and adjust zoom accordingly. 如何在视口内创建子边界区域以包含所有标记并相应地调整缩放。 I show only markers for a specific city. 我只显示特定城市的标记。

This is what I need to achieve visually: 这是我需要在视觉上实现的:

+------------------------------------------------+ + ------------------------------------------------ +
|..+-----+..+-------+.....+---------------------+| | .. + ----- + .. + ------- + ..... + --------------------- + |
|..|.nav.|....|..nav..|......|...marker area......|| | .. | .nav。| .... | ..nav .. | ...... | ...标记区域... ||
|..+-----+...+------+.....+---------------------+| | .. + ----- + ... + ------ + ..... + --------------------- + |
+------------------------------------------------+ + ------------------------------------------------ +

The outer block represents the google map, and the spaces between the sub blocks show the map panes. 外部的块代表Google地图,子块之间的空间显示地图窗格。 So I need a sub-viewport inside the main viewport somehow. 因此,我需要以某种方式在主视口内创建一个子视口。

Any ideas? 有任何想法吗? (suggestions to enhance the question are welcome as well, use comments for that pls.) (也欢迎提出改善问题的建议,请在评论中使用注释。)

Interesting problem. 有趣的问题。

My suggestion: 我的建议:

  1. Start with your bounds 从界限开始
  2. Using the Projection, find out what coordinates would extend the bounds to the left by 400px. 使用“投影”,找出哪些坐标会将边界向左扩展400px。
  3. Call fitBounds with these new coordinates. 使用这些新坐标调用fitBounds。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM