简体   繁体   English

带有标签的 Google Maps Retina 标记

[英]Google Maps Retina Marker with Label

I am handling Google Maps for Retina with this code:我正在使用以下代码处理 Retina 版 Google 地图:

var marker = new google.maps.Marker({
              position: new google.maps.LatLng(lat, lon),
              title: title,
              map: map,
              id: id,
              icon: {
                  url: "http://maps.google.com/mapfiles/kml/paddle/orange-blank.png",
                  size: new google.maps.Size(64, 64),
                  scaledSize: new google.maps.Size(40, 40),
                  origin: new google.maps.Point(0, 0),
                  anchor: new google.maps.Point(0, 0)
              },
              label: level + ""
          });

It works that the Icon itself is scaled that it is sharp on retina display.它的工作原理是图标本身被缩放到它在视网膜显示上很清晰。 But as you can see on this Image the Label is not in the center of the Marker anymore.但是正如您在此图像上所看到的,标签不再位于标记的中心。 How to handle that?怎么处理? I already tried with origin and anchor without success.我已经尝试过 origin 和 anchor 没有成功。 (The red marker is google original marker, unfortunately google doesn't have a Method to change the color of the standard marker or is there sth available?) (红色标记是谷歌原始标记,不幸的是谷歌没有改变标准标记颜色的方法,或者有什么可用的?)

在此处输入图片说明

在此处输入图片说明

  • It is scaled to 40px x 40px.它被缩放到 40px x 40px。
  • Its anchor should be at [20,40] (20 px right, in the center, 40 px down from the top left corner of the scaled image,at the bottom).它的锚点应该在 [20,40](右 20 像素,在中心,从缩放图像的左上角向下 40 像素,在底部)。
  • The labelAnchor should be at [20, 12] (20 px right, in the center, 12 px down from the top). labelAnchor应该在 [20, 12](右 20 px,在中心,从顶部向下 12 px)。
var marker = new google.maps.Marker({
  position: new google.maps.LatLng(lat, lon),
  title: title,
  map: map,
  id: id,
  icon: {
    url: "http://maps.google.com/mapfiles/kml/paddle/orange-blank.png",
    size: new google.maps.Size(64, 64),
    scaledSize: new google.maps.Size(40, 40),
    origin: new google.maps.Point(0, 0),
    anchor: new google.maps.Point(20, 40),
    labelOrigin: new google.maps.Point(20,12)
  },
  label: level + ""
});

带标签的自定义标记图片

  • If you want to open an infowindow on a custom marker, you also need to set the anchorPoint option of the marker.如果要在自定义标记上打开信息窗口,还需要设置标记的anchorPoint选项。

带有标签和信息窗口的自定义标记图片

code snippet:代码片段:

 function initialize() { var map = new google.maps.Map( document.getElementById("map_canvas"), { center: new google.maps.LatLng(37.4419, -122.1419), zoom: 13, mapTypeId: google.maps.MapTypeId.ROADMAP }); var title = "title"; var id = "id"; var level = 2; var lat = map.getCenter().lat(); var lon = map.getCenter().lng(); var marker = new google.maps.Marker({ position: new google.maps.LatLng(lat, lon), title: title, map: map, id: id, icon: { url: "http://maps.google.com/mapfiles/kml/paddle/orange-blank.png", size: new google.maps.Size(64, 64), scaledSize: new google.maps.Size(40, 40), origin: new google.maps.Point(0, 0), anchor: new google.maps.Point(20, 40), labelOrigin: new google.maps.Point(20, 12) }, label: level + "", anchorPoint: new google.maps.Point(0, -40) }); var infowindow = new google.maps.InfoWindow(); infowindow.setContent(marker.getPosition().toUrlValue(6)); infowindow.open(map, marker); } google.maps.event.addDomListener(window, "load", initialize);
 html, body, #map_canvas { height: 100%; width: 100%; margin: 0px; padding: 0px }
 <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script> <div id="map_canvas"></div>

Fixed with:固定:

icon: {
          url: "http://maps.google.com/mapfiles/kml/paddle/red-blank.png",
          size: new google.maps.Size(32, 42),
          scaledSize: new google.maps.Size(32, 32),
          origin: new google.maps.Point(0, -10),
          anchor: new google.maps.Point(16, 42)
}

And for others using that images there are a lot of colors just try...对于使用该图像的其他人来说,有很多颜色只是尝试......

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

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