修复了 Google 地图混搭中的图例
我有一个包含 Google 地图混搭的页面,其中的图钉按日期(周一、周二等)进行颜色编码。包含地图的 IFrame 是动态调整大小的,因此当浏览器窗口调整大小时,它也会调整大小。
我想在地图窗口的一角放置一个图例,告诉用户每种颜色的含义。 Google Maps API 包含 GScreenOverlay 类具有我想要的行为,但它只允许您指定要用作叠加层的图像,并且我更喜欢使用其中包含文本的 DIV。 将 DIV 放置在地图窗口(例如)左下角的最简单方法是什么,当调整浏览器窗口大小时,该 DIV 会自动保持在相对于角的同一位置?
I have a page with a Google Maps mashup that has pushpins that are color-coded by day (Monday, Tuesday, etc.) The IFrame containing the map is dynamically sized, so it gets resized when the browser window is resized.
I'd like to put a legend in the corner of the map window that tells the user what each color means. The Google Maps API includes a GScreenOverlay
class that has the behavior that I want, but it only lets you specify an image to use as an overlay, and I'd prefer to use a DIV with text in it. What's the easiest way to position a DIV over the map window in (for example) the lower left corner that'll automatically stay in the same place relative to the corner when the browser window is resized?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以添加自己的自定义控件并将其用作图例。
此代码将添加一个 150w x 100h 的框(灰色边框/白色背景)以及其中的单词“Hello World”。 您可以将图例中的文本替换为您想要的任何 HTML。 这将保持锚定在地图的右上角 (G_ANCHOR_TOP_RIGHT) 下方 10 像素和上方 50 像素处。
You can add your own Custom Control and use it as a legend.
This code will add a box 150w x 100h (Gray Border/ with White Background) and the words "Hello World" inside of it. You swap out the text for any HTML you would like in the legend. This will stay Anchored to the Top Right (G_ANCHOR_TOP_RIGHT) 10px down and 50px over of the map.
我将使用如下所示的 HTML:
然后您可以设置此样式以将图例保留在右下角:
position:relative
将导致任何包含的元素相对于#wrapper
定位code> 容器,并且position:absolute
将导致#legend
div 被“拉”出流程并位于地图上方,使其右下边缘保持在#wrapper
的底部并根据需要进行拉伸以包含标记描述。I would use HTML like the following:
You can then style this to keep the legend in the bottom right:
position: relative
will cause any contained elements to be positioned relative to the#wrapper
container, andposition: absolute
will cause the#legend
div to be "pulled" out of the flow and sit above the map, keeping it's bottom right edge at the bottom of the#wrapper
and stretching as required to contain the marker descriptions.