z-Index overlay in google maps version 3

前端 未结 6 2008
死守一世寂寞
死守一世寂寞 2020-12-08 20:30

I\'m trying to get an overlay in google maps api v3 to appear above all markers. But it seems that the google api always put my overlay with lowest z-index priority. Only so

6条回答
  •  一向
    一向 (楼主)
    2020-12-08 21:29

    In order to be able to play around with the paneType of the mapLabel class, I added a paneType property to the MapLabel class from google utility library (https://code.google.com/p/google-maps-utility-library-v3/source/browse/trunk/maplabel/src/maplabel.js?r=303).

    This is usefull to make the label not to be hidden by a polyline.

    Please find the code additions to the mapLabel.js file.

    MapLabel.prototype.onAdd = function() {
      var canvas = this.canvas_ = document.createElement('canvas');
      var style = canvas.style;
      style.position = 'absolute';
    
      var ctx = canvas.getContext('2d');
      ctx.lineJoin = 'round';
      ctx.textBaseline = 'top';
    
      this.drawCanvas_();
    
      var panes = this.getPanes();
      if (panes) {
        // OLD: panes.mapPane.appendChild(canvas)
        var paneType = this.get('paneType');
        panes[paneType].appendChild(canvas);
      }
    };
    
    MapLabel = function (opt_options) {
      this.set('fontFamily', 'sans-serif');
      this.set('fontSize', 12);
      this.set('fontColor', '#000000');
      this.set('strokeWeight', 4);
      this.set('strokeColor', '#ffffff');
      this.set('align', 'center');
    
      this.set('zIndex', 1e3);
      this.set('paneType', 'floatPane');
    
      this.setValues(opt_options);
    }
    

    Sample code using the paneType:

        var mapLabel = new MapLabel({
          text: segDoc.curr_value.toFixed(0),
          position: new google.maps.LatLng(lblLat, lblLng),
          map: map.instance,
          fontSize: 12,
          align: 'center',
          zIndex: 10000,
          paneType: 'floatPane',
        });
    

    Thanks!

提交回复
热议问题