0

我正在拉一个有 22 个标记的 Fusion Table 图层。(以前,我的地图是从 KML 图层中提取的;事实证明,Fusion Tables 对我的组织来说会更好)。

一切正常,直到我开始使用 InfoBubble 创建自定义窗口。我尽力重新创建用于制作自定义 infoWindows 的代码(请参阅我之前的帖子:Maps API v3: New InfoWindow, with pixelOffset, w/ data from KML.)。

我知道 infoBubble 不是火箭科学,但我显然做错了什么。如何让这段代码工作,并让它从我的 FusionTables 层中提取信息到 infoBubble 中?

谢谢你!:)

function initialize() {

var styles = [   ]; // Styles removed to simplify code

var styledMap = new google.maps.StyledMapType(styles,
    {name: "HEPAC"});

var mapOptions = { 
    zoom: 7,
    center: new google.maps.LatLng(46.69504, -67.69751),
    panControl: false,
    mapTypeControl: false,
    streetViewControl: false,
    noClear: true,
    zoomControlOptions: {
            position: google.maps.ControlPosition.TOP_RIGHT },
            mapTypeControlOptions: {
            mapTypeIds: ['map_style', google.maps.MapTypeId.ROADMAP]}
    };                

google.maps.visualRefresh = true;  

var map = new google.maps.Map(document.getElementById("map-canvas"),mapOptions);

// Associate the styled map with the MapTypeId and set it to display.
  map.mapTypes.set('map_style', styledMap);
  map.setMapTypeId('map_style');

var opt = { minZoom: 7, maxZoom: 9 }; // Sets minimum & maximum zoom level
map.setOptions(opt);

var layer = new google.maps.FusionTablesLayer({
    query: {
        select: 'Latitude',
        from: '18KH6atJ7EZMZS-xxXpebiRAoVuIa2fXmJCQC5IM',
      },
});

layer.setMap(map);

google.maps.event.addListener(layer, "click", function() {
    showInContentWindow();
});

function showInContentWindow(position, text)
var content= "<div class='networkwindow'>" + text +  "</div>";
var infoBubble = new InfoBubble({
    padding: 20px,
    arrowSize: 10,
    arrowPosition: 10,
    arrowStyle: 2
});
    infoBubble.open(map)

}    
google.maps.event.addDomListener(window, 'load', initialize);

编辑:在 geocodezip 建议查看我的 JavaScript 错误之后,修改了代码。地图现在可以工作了,但我的标记仍然没有出现在点击上。

google.maps.event.addListener(layer, "click", function () {
showInContentWindow();
});

function showInContentWindow(text) {
    var content = "<div class='networkwindow'>" + text +  "</div>";
    var InfoBubble = new InfoBubble({
        content: content,
        padding: '20px',
        arrowSize: 10,
        arrowPosition: 10,
        arrowStyle: 2
    });

InfoBubble.open(map);

}
4

1 回答 1

0

因为您的 javascript 中有语法错误。一旦我修复了这些,这对我有用。

var map = null;

function initialize() {
  var styles = [   ]; // Styles removed to simplify code

  var styledMap = new google.maps.StyledMapType(styles,
    {name: "HEPAC"});

  var mapOptions = { 
    zoom: 7,
    center: new google.maps.LatLng(46.69504, -67.69751),
    panControl: false,
    mapTypeControl: false,
    streetViewControl: false,
    noClear: true,
    zoomControlOptions: {
            position: google.maps.ControlPosition.TOP_RIGHT },
            mapTypeControlOptions: {
            mapTypeIds: ['map_style', google.maps.MapTypeId.ROADMAP]}
    };                

  google.maps.visualRefresh = true;  

  map = new google.maps.Map(document.getElementById("map-canvas"),mapOptions);

  // Associate the styled map with the MapTypeId and set it to display.
  map.mapTypes.set('map_style', styledMap);
  map.setMapTypeId('map_style');

  var opt = { minZoom: 7, maxZoom: 9 }; // Sets minimum & maximum zoom level
  map.setOptions(opt);

  var layer = new google.maps.FusionTablesLayer({
    query: {
        select: 'Latitude',
        from: '18KH6atJ7EZMZS-xxXpebiRAoVuIa2fXmJCQC5IM',
      },
  });

  layer.setMap(map);

  google.maps.event.addListener(layer, "click", function() {
    showInContentWindow();
  });
}
function showInContentWindow(position, text) {
  var content= "<div class='networkwindow'>" + text +  "</div>";
  var infoBubble = new InfoBubble({
    padding: "20px",
    arrowSize: 10,
    arrowPosition: 10,
    arrowStyle: 2
  });
  infoBubble.open(map)
}    
google.maps.event.addDomListener(window, 'load', initialize);

工作示例

于 2013-07-23T17:44:47.343 回答