本文介绍了在Google Maps V3中将MapLabel放置在Polygon的顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Google Maps V3中将MapLabel放置在Polygon的顶部。我试图将MapLabel zIndex设置为2,将Polygon zIndex设置为1,但没有任何运气。这是不可能的,因为Polygon并不真正遵循zIndex?



我为你们创建了一个jsFiddle来检查:



解决方案: strong>在 maplabel.js 更改:

  mapPane.appendChild(canvas ); 

到:

  floatPane.appendChild(画布); 

原因是因为 floatPane 高于一切地图图层(面板6)

解决方案

如果你不想使用 floatPane

这可能是后期发现的,但希望有人会发现这有用。 / code>(John的解决方案),因为这将始终处于最佳状态,并且想要提供自定义zIndex。编辑 maplabel.js 。在 MapLabel.prototype.onAdd = function(){

 结束之前添加以下行if(canvas.parentNode!= null){
canvas.parentNode.style.zIndex = style.zIndex;

现在您可以传递 zIndex maplabel

  var mapLabel = new MapLabel({
text :abc,
位置:center,
map:map,
fontSize:8,
align:'left',
zIndex:15
});


I'm trying to place a MapLabel on top of a Polygon in Google Maps V3. I've tried to set the MapLabel zIndex to 2 and the Polygon zIndex to 1 without any luck. Isn't this possible since the Polygon doesn't really follow zIndex?

I've created a jsFiddle for you guys to check out: http://jsfiddle.net/7wLWe/1/

Solution: In maplabel.js change:

mapPane.appendChild(canvas);

to:

floatPane.appendChild(canvas);

The reason is because floatPane is above all map layers (pane 6)

http://code.google.com/apis/maps/documentation/javascript/reference.html#OverlayView

解决方案

This is probably a late find.. but hope someone would find this useful.

If you don't want to use floatPane (John's Solution) as this will be always on top of everything, and want to give a custom zIndex.. Edit the maplabel.js. Add the following line just before the end of MapLabel.prototype.onAdd = function() {

if (canvas.parentNode != null) {
    canvas.parentNode.style.zIndex = style.zIndex;
}

Now you can pass zIndex while creating a maplabel:

var mapLabel = new MapLabel({
    text: "abc",
    position: center,
    map: map,
    fontSize: 8,
    align: 'left',
    zIndex: 15
});

这篇关于在Google Maps V3中将MapLabel放置在Polygon的顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 23:49