0

我尝试制作具有许多标记并且每个标记都有自己的信息窗口的地图。我想要 infowidow 显示 onload 并且由于有很多标记,所以原始 infowindow 会阻止其他标记,所以我想要带有 http://hadeerfolio.com/map/ref.php 中顶部样式的infowindow但是当我尝试要做到这一点,它就会变成这样http://hadeerfolio.com/map/每个信息窗口都有相同的内容。请指教 谢谢

这是第一个链接的代码

<!DOCTYPE html>
<html>
<head>
    <style>
        img[src*="iws3.png"] {
            display: none;
        }
        .infobox-wrapper {
            display:none;
        }
        #infobox{
            border:2px solid black;
            margin-top: 8px;
            background:#fff;
            color:#111;
            font-family:Arial, Helvetica, sans-serif;
            font-size:12px;
            font-weight : bold;
            padding: .5em 1em;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            border-radius: 2px;
            text-shadow:0 -1px #000000;
            -webkit-box-shadow: 0 0  8px #000;
            box-shadow: 0 0 8px #000;
        }

        </style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js"></script>
<script type="text/javascript">
function initialize() {
    var loc, map, marker, infobox;

    loc = new google.maps.LatLng(-33.890542, 151.274856);

    map = new google.maps.Map(document.getElementById("map"), {
         zoom: 12,
         center: loc,
         mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    marker = new google.maps.Marker({
        map: map,
        position: loc,
        visible: true
    });

    infobox = new InfoBox({
         content: document.getElementById("infobox"),
         disableAutoPan: false,
         maxWidth: 80,
         pixelOffset: new google.maps.Size(-40, -70),
         zIndex: null,
         boxStyle: {
            background: "url('http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/examples/tipbox.gif') no-repeat",
            opacity: 0.5,
            width: "80px"
        },
        closeBoxMargin: "12px 4px 2px 2px",
        closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif",
        infoBoxClearance: new google.maps.Size(1, 1)
    });

    google.maps.event.addListener(marker, 'click', function() {
        infobox.open(map, this);
        map.panTo(loc);
    });
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<title>Creating and Using an InfoBox</title>
</head>

<body>
<div id="map" style="width: 100%; height: 300px"></div>
<br>

InfoBox as an easily customizable replacement for an InfoWindow. Click on the marker to see the infobox generated with custom html &amp; css.
<div class="infobox-wrapper">
    <div class='infobox' id='infobox'>
        contents.
    </div>
</div>

  <!--script src="http://maps.google.com/maps/api/js?sensor=false" 
          type="text/javascript"></script-->
          <style>

            /*div{
width:150px;
height:100px;
}*/
            </style>
  <div id="map1" style="width: 1000px; height: 1000px;"></div>

  <script type="text/javascript">
    var locations = [
      ['Bondi Beach', -33.890542, 151.274856, 4],
      ['Coogee Beach', -33.923036, 151.259052, 1],
      ['Cronulla Beach', -34.028249, 151.157507, 3],
      ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
      ['Maroubra Beach', -33.950198, 151.259302, 5]
    ];

    var map = new google.maps.Map(document.getElementById('map1'), {
      zoom: 10,
      //center: new google.maps.LatLng(-33.92, 151.25),
      center: new google.maps.LatLng(-33.950198, 151.259302),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var infowindow = new google.maps.InfoWindow();

    var marker, i;

    for (i = 0; i < locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
      });

      /*google.maps.event.addListener(marker, 'click', (function(marker, i) {  //incase you want to show onclick event remove comment  
        return function() {
        */

        var infowindow = new google.maps.InfoWindow({ maxWidth: 200 }); // and comment this line
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        /*}
      })

      (marker, i));
       */
    }

  </script>
</body>
</html>

这个是第二个链接

    <!DOCTYPE html>
<html>
<head>
    <style>
        img[src*="iws3.png"] {
            display: none;
        }
        .infobox-wrapper {
            display:none;
        }
        .infobox{
            border:2px solid black;
            margin-top: 8px;
            background:#fff;
            color:#111;
            font-family:Arial, Helvetica, sans-serif;
            font-size:12px;
            font-weight : bold;
            padding: .5em 1em;
            -webkit-border-radius: 2px;
            -moz-border-radius: 2px;
            border-radius: 2px;
            text-shadow:0 -1px #000000;
            -webkit-box-shadow: 0 0  8px #000;
            box-shadow: 0 0 8px #000;
        }

        </style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js"></script>
<script type="text/javascript">
function initialize() {
    var loc, map, marker, infobox;

    loc = new google.maps.LatLng(-33.890542, 151.274856);

    map = new google.maps.Map(document.getElementById("map"), {
         zoom: 12,
         center: loc,
         mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    marker = new google.maps.Marker({
        map: map,
        position: loc,
        visible: true
    });

    infobox = new InfoBox({
         content: document.getElementById("infobox"),
         disableAutoPan: false,
         maxWidth: 80,
         pixelOffset: new google.maps.Size(-40, -70),
         zIndex: null,
         boxStyle: {
            background: "url('http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/examples/tipbox.gif') no-repeat",
            opacity: 0.5,
            width: "80px"
        },
        closeBoxMargin: "12px 4px 2px 2px",
        closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif",
        infoBoxClearance: new google.maps.Size(1, 1)
    });

    google.maps.event.addListener(marker, 'click', function() {
        infobox.open(map, this);
        map.panTo(loc);
    });
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<title>Creating and Using an InfoBox</title>
</head>

<body>
<div id="map" style="width: 100%; height: 300px"></div>
<br>

InfoBox as an easily customizable replacement for an InfoWindow. Click on the marker to see the infobox generated with custom html &amp; css.
<div class="infobox-wrapper">
    <div class='infobox' id='infobox'>
        content
    </div>
    <div class='infobox' id='infobox0'>
        content1
    </div>
    <div class='infobox' id='infobox1'>
        content2
    </div>
    <div class='infobox' id='infobox2'>
        content3
    </div>
    <div class='infobox' id='infobox3'>
        content4
    </div>
    <div class='infobox' id='infobox4'>
        content5
    </div>
</div>

  <!--script src="http://maps.google.com/maps/api/js?sensor=false" 
          type="text/javascript"></script-->
          <style>

            /*div{
width:150px;
height:100px;
}*/
            </style>
  <div id="map1" style="width: 1000px; height: 1000px;"></div>

  <script type="text/javascript">
    var locations = [
      ['Bondi Beach', -33.890542, 151.274856, 4],
      ['Coogee Beach', -33.923036, 151.259052, 1],
      ['Cronulla Beach', -34.028249, 151.157507, 3],
      ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
      ['Maroubra Beach', -33.950198, 151.259302, 5]
    ];

    var map = new google.maps.Map(document.getElementById('map1'), {
      zoom: 10,
      //center: new google.maps.LatLng(-33.92, 151.25),
      center: new google.maps.LatLng(-33.950198, 151.259302),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var infowindow = new google.maps.InfoWindow();

    var marker, i;

    for (i = 0; i < locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
      });

      /*google.maps.event.addListener(marker, 'click', (function(marker, i) {  //incase you want to show onclick event remove comment  
        return function() {
        */

       infobox = new InfoBox({
         content: document.getElementById("infobox"+i),
         disableAutoPan: false,
         maxWidth: 80,
         pixelOffset: new google.maps.Size(-40, -70),
         zIndex: null,
         boxStyle: {
            background: "url('http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/examples/tipbox.gif') no-repeat",
            opacity: 0.75,
            width: "80px"
        },
        closeBoxMargin: "12px 4px 2px 2px",
        closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif",
        infoBoxClearance: new google.maps.Size(1, 1)
    });

    google.maps.event.addListener(marker, 'click', function() {
        infobox.open(map, this);
        map.panTo(center);
    });
     infowindow.open(map, marker);
    }

  </script>
</body>
</html>
4

0 回答 0