Google maps api 3 谷歌地图api v3:MarkerClusterer图标上的文本位置

Google maps api 3 谷歌地图api v3:MarkerClusterer图标上的文本位置,google-maps-api-3,markerclusterer,Google Maps Api 3,Markerclusterer,当计算器功能运行时,我试图为显示在MarkerClusterer图标中的文本设置一个不同的位置。是否可以将文本移动到图标的顶部多一点 我怎么能这么做 谢谢 我假设您正在使用我认为您正在使用的代码,Google markercluster。。在这种情况下,您需要以markerclusterer.js代码为例,直接修改它 在该代码中有一个名为ClusterIcon.prototype.createCss()…的方法,它基本上为每个集群元素设置样式(实际上它们只是div)。。如果不想将数字文本更改为显

当计算器功能运行时,我试图为显示在MarkerClusterer图标中的文本设置一个不同的位置。是否可以将文本移动到图标的顶部多一点

我怎么能这么做


谢谢

我假设您正在使用我认为您正在使用的代码,Google markercluster。。在这种情况下,您需要以markerclusterer.js代码为例,直接修改它

在该代码中有一个名为
ClusterIcon.prototype.createCss()…
的方法,它基本上为每个集群元素设置样式(实际上它们只是div)。。如果不想将数字文本更改为显示在靠近顶部的位置,例如,可以修改
行高
属性

以下是一个例子:

/**
 * Create the css text based on the position of the icon.
 *
 * @param {google.maps.Point} pos The position.
 * @return {string} The css style text.
 */
ClusterIcon.prototype.createCss = function(pos) {

  var style = [];
  style.push('background-image:url(' + this.url_ + ');');
  var backgroundPosition = this.backgroundPosition_ ? this.backgroundPosition_ : '0 0';
  style.push('background-position:' + backgroundPosition + ';');

  if (typeof this.anchor_ === 'object') {
    if (typeof this.anchor_[0] === 'number' && this.anchor_[0] > 0 &&
        this.anchor_[0] < this.height_) {
      style.push('height:' + (this.height_ - this.anchor_[0]) +
          'px; padding-top:' + this.anchor_[0] + 'px;');
    } else {

      //
      // See the (this.height_ - 10) for line-height
      //

      style.push('height:' + this.height_ + 'px; line-height:' + (this.height_ - 10) +
          'px;');
    }
    if (typeof this.anchor_[1] === 'number' && this.anchor_[1] > 0 &&
        this.anchor_[1] < this.width_) {
      style.push('width:' + (this.width_ - this.anchor_[1]) +
          'px; padding-left:' + this.anchor_[1] + 'px;');
    } else {
      style.push('width:' + this.width_ + 'px; text-align:center;');
    }
  } else {

    //
    // See the (this.height_ - 10) for line-height
    //

    style.push('height:' + this.height_ + 'px; line-height:' +
        (this.height_ - 10) + 'px; width:' + this.width_ + 'px; text-align:center;');
  }

  var txtColor = this.textColor_ ? this.textColor_ : 'black';
  var txtSize = this.textSize_ ? this.textSize_ : 11;

  style.push('cursor:pointer; top:' + pos.y + 'px; left:' +
      pos.x + 'px; color:' + txtColor + '; position:absolute; font-size:' +
      txtSize + 'px; font-family:Arial,sans-serif; font-weight:bold');

  return style.join('');
};
。。。并对其进行修改,以将更多HTML放置到实际的div元素中,然后您可以使用各种选项根据需要对其进行调优


下面是所有这些的工作示例:

让我们看看您正在尝试什么。。。什么是“计算器功能”?你太棒了!!通过我的小小解释,你解决了我的问题。更改“线高度:”属性我已经能够移动MarkerClusterer标签。非常感谢你!
<div style="background-image: url(http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/images/m1.png); height: 53px; line-height: 43px; width: 53px; text-align: center; cursor: pointer; top: 173.68359152317203px; left: 273.60742400000004px; color: black; position: absolute; font-size: 11px; font-family: Arial, sans-serif; font-weight: bold; background-position: 0px 0px;">2</div>
/**
 * Adding the cluster icon to the dom.
 * @ignore
 */
ClusterIcon.prototype.onAdd = function() {
  this.div_ = document.createElement('DIV');
  if (this.visible_) {
    var pos = this.getPosFromLatLng_(this.center_);
    this.div_.style.cssText = this.createCss(pos);

    // For debugging purposes so you know what you are doing
    // console.log(this.div_);

    // The interesting part here is the this.div_.innerHTML    
    // You could for example add more elements inside this.div_, 
    // now it just adds the number

    this.div_.innerHTML = this.sums_.text;
  }

  var panes = this.getPanes();
  panes.overlayMouseTarget.appendChild(this.div_);

  var that = this;
  google.maps.event.addDomListener(this.div_, 'click', function() {
    that.triggerClusterClick();
  });
};