Google Mapsを半透明にする

ここでは、Google MAPS APIとstyle sheetを組み合わせて、地図を半透明にする方法を説明したいと思います。

サンプル

以下のサンプルはGoogle MAPS APIを使ったページのソースです。


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Google Maps JavaScript API Example</title>
    <script src="http://maps.google.com/maps?file=api&v=2&key=aaaaa"
        type="text/javascript" charset="utf-8"></script>

    <script type="text/javascript">
    //<![CDATA[

    function onLoad () {
      var map = new GMap2(document.getElementById("map"));
      map.setCenter(new GLatLng(37.441944, -122.141944), 11);
    }

    //]]>
    </script>

  </head>

  <body>

  <div id="map"
     style="width:300px;height:300px; filter:alpha(opacity=80);opacity:0.8;"></div>

  </body>

</html>

上記サンプルでは、Google mapsのDIVに対する透過度を設定しています。 「filter:alpha(opacity=80)」がIE用で、「opacity:0.8」がFirefoxとOpera用です。

opacityを0にすると完全に透明になります。

表示例

表示例です。 解りやすくするために以下の表示例では背景をつけています。



あきみち

Linuxネットワークプログラミングの本を書きました
Linuxネットワークプログラミング

Google Maps API
プログラミング



カスタム検索




はてなRSSに追加
Subscribe with livedoor Reader
Subscribe with Bloglines
Add to goo

外部サイト

プレコ王国
ディスカス魂
金魚タイムズ
YouTubeチャネル
Twitter
mixi(ほぼ未使用)


フィードメーター - Geekなぺーじ にほんブログ村 IT技術ブログへ
Copyright (C) Geekなページ.
All rights reserved. 無断転載や無断コピーなど、私的利用の範囲を逸脱した利用はおやめ下さい.