简体   繁体   English

谷歌地图简单图案叠加

[英]Google maps simple pattern overlay

I want to completely overlay a google map with a simple repeating semitransparent png image for optical reasons.出于光学原因,我想用简单的重复半透明 png 图像完全覆盖谷歌地图。 I cant find a way in the official documentation.我在官方文档中找不到方法。 The map should remain functional.地图应该保持功能。 Any hints ?任何提示?

Here you go.. Simplest way is to just create a div overlay if you simply want to overlay a repeating transparent-ish background image.给你.. 最简单的方法是创建一个 div 覆盖,如果你只是想覆盖一个重复的透明背景图像。 Just set the background image of the .overlay div to the background image:只需将.overlay div 的背景图像设置为背景图像:

HTML: HTML:

<div class="wrap">
    <div class="overlay"><h1>hey</h1></div>
    <div id="map-canvas"></div>
</div>

CSS: CSS:

html { height: 100% }
.wrap {
    width:100%;
    position:relative;
    width:300px;
    height:300px;
}
h1 {
    font-family:Arial;
}
.overlay {
    background:rgba(255,255,255,0.8);
    position:absolute;
    width:300px;
    z-index:1;
    height:300px;
    top:0; left:0;
}
body { height: 100%; margin: 0; padding: 0 }
#map-canvas { height: 300px; width:300px; }

Alternatively as I have mentioned before, you can go the overlayview route, which is slightly more complicated but gives you more control and integration with Gmaps API events and stuff.或者,正如我之前提到的,您可以使用 overlayview 路线,它稍微复杂一些,但可以让您更好地控制和集成 Gmaps API 事件和其他东西。 http://jsfiddle.net/78p6fb43/1/ http://jsfiddle.net/78p6fb43/1/

Second example with bg image: http://jsfiddle.net/78p6fb43/2/带有 bg 图像的第二个示例: http : //jsfiddle.net/78p6fb43/2/

However, if you still need your user to interact with the underlying map in some way (ie click markers, drag the map etc), the above solution will not work and you should use the OverlayView approach但是,如果您仍然需要您的用户以某种方式与底层地图进行交互(即单击标记、拖动地图等),则上述解决方案将不起作用,您应该使用 OverlayView 方法

nb The screenshot of the map you have posted I believe is MapBox not the Google Maps API - MapBox is based on the Leaflet JS API. nb 您发布的地图截图我相信是 MapBox 而不是 Google Maps API - MapBox 基于 Leaflet JS API。 It is very easy to use and you can customize the design of the map far more ( https://www.mapbox.com/design/ )它非常易于使用,您可以自定义地图的设计更多( https://www.mapbox.com/design/

If you're looking for some styles for Google Maps, check out https://snazzymaps.com/explore如果您正在为 Google 地图寻找一些样式,请查看https://snazzymaps.com/explore

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

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