首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我的InfoBubble没有加载FusionTablesLayer?

为什么我的InfoBubble没有加载FusionTablesLayer?
EN

Stack Overflow用户
提问于 2013-07-23 16:07:11
回答 1查看 205关注 0票数 0

我正在拉一个包含22个标记的融合表层。(以前,我的映射是从KML层提取的;结果表明,融合表对我的组织会更好)。

在我开始使用InfoBubble创建自定义窗口之前,一切都很顺利。我尽了最大努力重新创建用于定制infoWindows的代码(参见前面的文章:Maps v3:新InfoWindow,带有来自KML的pixelOffset、w/ data。)。

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

(谢谢!)

代码语言:javascript
复制
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错误。地图现在工作,但我的标记仍然没有出现在点击。

代码语言: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);

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-23 17:44:47

因为您的javascript中有语法错误。一旦我修好了这个就行了。

代码语言: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);

工作实例

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17815398

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档