简体   繁体   English

自定义Google Map Marker,例如Trulia地图

[英]Custom Google Map Marker like in Trulia map

How to make Google Map markers like the one used in Trulia map? 如何使Google Map标记像Trulia地图中使用的那样?

  1. The markers have pointer in the bottom 标记的底部有指针
  2. The markers have price labels. 标记带有价格标签。
  3. The markers seems to have variable length depend on the label inside them. 标记的长度似乎可变,具体取决于标记内部的标签。
  4. The markers can change color when it's being hovered (grey color) or it's already clicked (orange color) beside its normal color (green). 当鼠标悬停(灰色)或在其正常颜色(绿色)旁边已经单击(橙色)时,标记可以更改颜色。

Is there a library for this? 有图书馆吗?

Screenshot is below 屏幕截图如下

在此处输入图片说明

UPDATE UPDATE

So far I found a library MarkerWithLabel and I can reproduce the 2, 3, and 4 above. 到目前为止,我找到了一个MarkerWithLabel库,可以复制上面的2、3和4。 See below for the code. 参见下面的代码。 But I can't seem to put a pointer in the bottom of the label. 但是我似乎无法在标签的底部放置一个指针。

See fiddle http://jsfiddle.net/petrabarus/p8YhU/ 参见小提琴http://jsfiddle.net/petrabarus/p8YhU/

var marker = new MarkerWithLabel({
    position: homeLatLng,
    draggable: true,
    raiseOnDrag: true,
    map: map,
    labelContent: "$425K",
    labelAnchor: new google.maps.Point(0, 0),
    labelClass: "labels", // the CSS class for the label
    icon: {},
    isClicked: false
});

google.maps.event.addListener(marker, 'click', function() {
    marker.isClicked = true;
    marker.set('labelClass', 'labels active');
});
google.maps.event.addListener(marker, 'mouseover', function() {
    marker.set('labelClass', 'labels hover');
});
google.maps.event.addListener(marker, 'mouseout', function() {
    if (marker.isClicked){
        marker.set('labelClass', 'labels active');
    } else {
        marker.set('labelClass', 'labels');
    }
});

UPDATE UPDATE

Previous answer was 先前的答案是

But there is another problem. 但是还有另一个问题。 It seems when you display the icon, the pointer of the label doesn't really point to the marker. 似乎当您显示图标时,标签的指针并没有真正指向标记。 see this http://jsfiddle.net/petrabarus/y3M4u/ . 看到这个http://jsfiddle.net/petrabarus/y3M4u/

The MarkerWithLabel does give labelAnchor property to set (see this ). 该MarkerWithLabel确实给labelAnchor属性设置(见 )。 But when the label is too long, the anchor positioning will be broken too. 但是,如果标签太长,锚定位置也会被破坏。

maybe this can help you example 也许这可以帮助你举例

var marker = new MarkerWithLabel({
    position: homeLatLng,
    draggable: true,
    raiseOnDrag: true,
    map: map,
    labelContent: "<div class='arrow'></div><div class='inner'>$425K</div>",
    labelAnchor: new google.maps.Point(0, 0),
    labelClass: "labels", // the CSS class for the label
    icon: {},
    isClicked: false
});

and css 和CSS

.labels {
    margin-top:-3px;
    padding: 5px;
    position: absolute;
    visibility: visible;
    z-index: 1030;
}
.labels .arrow{
    border-top-color: #000000;
    border-right-color: rgba(0,0,0,0);
    border-bottom-color: rgba(0,0,0,0);
    border-left-color: rgba(0,0,0,0);
    border-width: 5px 5px 0;
    bottom: 0;
    left: 50%;
    margin-left: -5px;
    border-style: solid;
    height: 0;
    position: absolute;
    width: 0;
}
.labels .inner{
    background-color: #000000;
    border-radius: 4px;
    color: #FFFFFF;
    max-width: 200px;
    padding: 3px 8px;
    text-align: center;
    text-decoration: none;  
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM