Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 所有标记上的Google地图标记工具提示,类型错误:投影未定义_Javascript_Jquery_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 所有标记上的Google地图标记工具提示,类型错误:投影未定义

Javascript 所有标记上的Google地图标记工具提示,类型错误:投影未定义,javascript,jquery,google-maps,google-maps-api-3,Javascript,Jquery,Google Maps,Google Maps Api 3,当我在mousehover事件上调用CTOLTIP时,它会工作,但当我在循环内直接调用它时,可以看到第一个工具提示,但在第二个循环错误出现之后 cTooltip.prototype = new google.maps.OverlayView; cTooltip.prototype.draw1 = function(pos, content, margin){ var div = this.div_; div.style.cssText = 'z-index:9999;cursor:po

当我在mousehover事件上调用CTOLTIP时,它会工作,但当我在循环内直接调用它时,可以看到第一个工具提示,但在第二个循环错误出现之后

cTooltip.prototype = new google.maps.OverlayView;

cTooltip.prototype.draw1 = function(pos, content, margin){
  var div = this.div_;
  div.style.cssText = 'z-index:9999;cursor:pointer;visibility:hidden;position:absolute;text-align:center;margin:'+margin;
  if(content){
    div.innerHTML = content;
  }
  if(pos){

    $(markers_sets).each(function () {
       if (this.id == per.markers_set) {
            m_settings = this.settings;
       }
    });

    var markersOffset = (typeof m_settings.markers_offset !== 'undefined' ? parseInt(m_settings.markers_offset) : 7);

    var width = $('.vipul_'+tooltipCount).outerWidth() / 2;
    pin_center = 56 - width;
    var projection = this.getProjection();
    var position = projection.fromLatLngToDivPixel(pos);
    div.style.left = (position.x - 64 + pin_center + markersOffset) + 'px';
    div.style.top = (position.y - 40) + 'px';
    div.style.visibility = 'visible';
  }

tooltipCount++;
}
代码的其余部分

TypeError: projection is undefined

var position = projection.fromLatLngToDivPixel(pos);
功能cMarker(可选){
此.setValues(opt_选项);
var group=this.get('group');
var unique_groups=this.get('unique_groups');
var l=this.get('data');
var descr=this.get('description');
var pos=这个.get('pos');
var tooltip=this.tooltip=this.get('tooltip');
这个r=pos;
var div=this.div=document.createElement('div');
var mb=parseInt(md.markers_top)+40;
div.onmouseover=函数(){
如果(提示内容!=“”){
如果(刀具提示超时!=null){
clearTimeout(刀具提示超时);
工具提示超时=空;
}
if(显示&&!this.hasClass('hideTooltip')){
变量工具提示html='';
工具提示html+='';
工具提示html+='';
工具提示html+=''+提示内容+'';
工具提示html+='';
工具提示html+='';
工具提示html+='';
工具提示html+='';
工具提示超时=设置超时(函数(){
tooltip.draw(新的google.maps.LatLng(parseFloat(l[marker_lat_i])、parseFloat(l[marker_lng_i])、tool_tip_html、'-'+(parseInt(md.markers_top)+6)+“px 0px 0px 0px”);
}, 500);
}
显示提示=false;
}
};
}
我想在所有标记上绘制工具提示,这就是为什么我不需要鼠标悬停,而是需要在加载事件时调用它,或者简单地将它放置在鼠标悬停事件之外,但错误是显示一个工具提示后投影未定义。

不要自己调用
draw
-方法,在以下情况下会自动调用该方法:

  • 将覆盖添加到地图中
  • 地图的视口将更改
  • 使用
    OverlayView
    时的工作流程如下:

  • 调用构造函数(在本例中为
    cMarker
    ),在构造函数中设置覆盖的属性(将通过
    this.setValues(opt_options);
    在代码中完成)
  • 当您设置覆盖的
    map
    -属性时(应该在构造函数内部完成,因为您希望最初绘制覆盖),API将自动调用
    onAdd
    -方法
  • onAdd
    -方法中创建节点(带有所需内容和额外添加的事件侦听器),并将其添加到MapPane
  • draw方法是自动调用的(正如我最初在
    onAdd()之后所说的,或者当视口更改时)。使用此方法仅更新CSS位置(或者当您希望大小取决于地图缩放时,还可以更新CSS大小)
  • 此工作流可确保: 1.当调用
    onAdd()
    时,映射窗格已准备就绪 2.当调用
    draw()
    时,投影可用

    当您想要打破此预定义的执行顺序时,请收听覆盖的“窗格更改”事件,当它触发窗格且投影可用时,您可以将覆盖添加到地图中

    function cMarker(opt_options) {
      this.setValues(opt_options);
      var group = this.get('group');
      var unique_groups = this.get('unique_groups');
      var l = this.get('data');
      var descr = this.get('description');
      var pos = this.get('pos');
      var tooltip = this.tooltip = this.get('tooltip');
      this.r = pos;
      var div = this.div_ = document.createElement('div');
      var mb = parseInt(md.markers_top) + 40;
    
    
    
    
       div.onmouseover = function() {
          if (tip_content != "") {
            if (tool_tip_timeout != null) {
              clearTimeout(tool_tip_timeout);
              tool_tip_timeout = null;
            }
            if (display_tip && !this.hasClass('hideTooltip')) {
            var tool_tip_html ='';
            tool_tip_html += '<div class="maptive-bubble-blue vipul_'+tooltipCount+'">';
            tool_tip_html += '<div class="maptive-bubble-pin-container">';
            tool_tip_html += '<div class="maptive-bubble-text">' + tip_content + '</div>';
            tool_tip_html += '<div class="maptive-bubble-pin"></div>';
            tool_tip_html += '</div>';
            tool_tip_html += '<div class="maptive-bubble-shadow"><img src="/ver4/images/bubble-shadow.png"></div>';
            tool_tip_html += '</div>';
              tool_tip_timeout = setTimeout(function() {
                tooltip.draw(new google.maps.LatLng(parseFloat(l[marker_lat_i]), parseFloat(l[marker_lng_i])), tool_tip_html, '-' + (parseInt(md.markers_top) + 6) + 'px 0px 0px 0px');
              }, 500);
            }
            display_tip=false;
          }
        };
    }
    
    I want to draw tooltip on all markers, that why instead of mousehover I need to call it on load event or by simply by placing it outside that mousehover event but error is projection is undefined after displaying one tooltip.
    

    但是这种自定义实现毫无意义,因为当投影可用时,将自动调用draw方法。

    在哪里调用
    draw1
    ?(这个方法不会被API自动调用)我正在调用它的外部mousehover事件,请检查上面写的mousehover事件。此事件在函数cMarker(){}内调用,其中cMarker是使用类似以下的原型初始化的:cMarker.prototype=new google.maps.OverlayView;它在你编辑之前从未出现过。但是,现在还不清楚工具提示是什么,发布完整的代码是的,请现在检查,我再次编辑了它。
    function cMarker(opt_options) {
      this.setValues(opt_options);
      var group = this.get('group');
      var unique_groups = this.get('unique_groups');
      var l = this.get('data');
      var descr = this.get('description');
      var pos = this.get('pos');
      var tooltip = this.tooltip = this.get('tooltip');
      this.r = pos;
      var div = this.div_ = document.createElement('div');
      var mb = parseInt(md.markers_top) + 40;
    
    
    
    
       div.onmouseover = function() {
          if (tip_content != "") {
            if (tool_tip_timeout != null) {
              clearTimeout(tool_tip_timeout);
              tool_tip_timeout = null;
            }
            if (display_tip && !this.hasClass('hideTooltip')) {
            var tool_tip_html ='';
            tool_tip_html += '<div class="maptive-bubble-blue vipul_'+tooltipCount+'">';
            tool_tip_html += '<div class="maptive-bubble-pin-container">';
            tool_tip_html += '<div class="maptive-bubble-text">' + tip_content + '</div>';
            tool_tip_html += '<div class="maptive-bubble-pin"></div>';
            tool_tip_html += '</div>';
            tool_tip_html += '<div class="maptive-bubble-shadow"><img src="/ver4/images/bubble-shadow.png"></div>';
            tool_tip_html += '</div>';
              tool_tip_timeout = setTimeout(function() {
                tooltip.draw(new google.maps.LatLng(parseFloat(l[marker_lat_i]), parseFloat(l[marker_lng_i])), tool_tip_html, '-' + (parseInt(md.markers_top) + 6) + 'px 0px 0px 0px');
              }, 500);
            }
            display_tip=false;
          }
        };
    }
    
    I want to draw tooltip on all markers, that why instead of mousehover I need to call it on load event or by simply by placing it outside that mousehover event but error is projection is undefined after displaying one tooltip.
    
      google.maps.event.addListenerOnce(yourOverlayInstance,'panes_changed',
       function(){/*create node with content and events , 
                    add it to a pane ,
                    set position and optinally the size*/});