1

I'm quite new to Google Fusion, but keen to learn. I've created a map, customized the infowindow and embedded the map onto my site using FusionTablesLayer Wizard to create a script to be hosted on the same domain. Doing it that way, I thougt it would be possible using target=_parent for my links in the infowindow in stead of the ever annoying target=_blank command. Since then I've found out, that due to security, you have to add a click listener to be able to get trget=_parent working, and this is where my abilities come to a stop. Can anyone help me enable the listener, configure the infowindow and most important of all, get target=_parent working.

Here's some code, I hope you can use.

Infowindow:

<div class='googft-info-window' style='font-family:Georgia, sans-serif' "width: 250px;" >
<base target="_parent" />
<b><a href="{info-URL} " ">{Skole}</a></b></b><br>
<i>Åbner i ny fane/nyt vindue</i><br><br>
{Adresse}<br><br>
<b>Elevtal:</b> {Elevtal}<br>
<b>Rang 2010/2011:</b> {Rangering til kort}/107<br><br>
<b>Gennemsnit 2010/2011</b><br>
<b>Dansk:</b> {Dansk total}<br>
<b>Engelsk:</b> {Engelsk total}<br>
<b>Fysik/kemi:</b> {Fysik/kemi total}<br>
<b>Matematik:</b> {Matematik total}<br><br>
<b>Samlet gennemsnit:</b> {Skolegennemsnit}<br><br>
{NOTE}<br><br>
<a href="{Skole-URL}" target=_blank>Hjemmeside</a>
</div>

FusionTablesLayer Wizard code

<!DOCTYPE html>
<html>
  <head>
<base target="_parent" />
  <style>
    #map-canvas { width:700px; height:400px; }
  </style>
  <script type="text/javascript"
    src="http://maps.google.com/maps/api/js?sensor=false">
  </script>
  <script type="text/javascript">
    var map;
    var layerl0;
    function initialize() {
      map = new google.maps.Map(document.getElementById('map-canvas'), {
        center: new google.maps.LatLng(57.17199198214385, 9.771527295703208),
        zoom: 8
      });
      var style = [
        {
          featureType: 'all',
          elementType: 'all',
          stylers: [
            { saturation: 9 }
          ]
        }
      ];
      var styledMapType = new google.maps.StyledMapType(style, {
        map: map,
        name: 'Styled Map'
      });
      map.mapTypes.set('map-style', styledMapType);
      map.setMapTypeId('map-style');
      layerl0 = new google.maps.FusionTablesLayer({
        query: {
          select: "'col2'",
          from: 'table-id'
        },
        map: map,
        styleId: -1,
        templateId: 1
      });
    }
    google.maps.event.addDomListener(window, 'load', initialize);
  </script>
  </head>
  <body>
    <div id="map-canvas"></div>
  </body>
</html>

The map is online at www.skoleguide.net right now and the inspiration to add a click listener, I got from here

I really hope, someone out there can help me

Jens Skriver Steffensen

4

1 回答 1

1

要将“target=_parent”添加到 FusionTables 中的预先存在的内容中,应该可以这样:

var newContent = e.infoWindowHtml.replace("/<a /<a target='_parent' /g");

您使用google.maps.addListener方法添加点击收听您的 FusionTable

像这样的东西应该工作:

  //add a click listener to the layer
  google.maps.event.addListener(layer10, 'click', function(e) {
    //update the content of the InfoWindow
    var newContent = e.infoWindowHtml.replace("/<a /<a target='_parent' /g");
    infowindow.setOptions({
       content: newContent,
   pixelOffset: e.pixelOffset,
   position: e.latLng
   });
    infowindow.open(map);
  });      

请务必通过在 FusionTablesLayer 构造函数中添加“suppressInfoWindows: true”选项来禁用默认信息窗口。

工作示例

于 2012-11-15T21:04:28.680 回答