gpt4 book ai didi

google-maps-api-3 - 用不调整大小的Google Maps api3画一个圆

转载 作者:行者123 更新时间:2023-12-02 04:12:03 24 4
gpt4 key购买 nike

大家好,
使用谷歌 map api2,我使用以下代码绘制了一个圆:

var markerPoint = currentMarker.getPoint();

var polyPoints = Array();

var mapNormalProj = G_NORMAL_MAP.getProjection();
var mapZoom = map.getZoom();
var clickedPixel = mapNormalProj.fromLatLngToPixel(markerPoint, mapZoom);

var polySmallRadius = 20;

var polyNumSides = 20;
var polySideLength = 18;

for (var a = 0; a<(polyNumSides+1); a++) {
var aRad = polySideLength*a*(Math.PI/180);
var polyRadius = polySmallRadius;
var pixelX = clickedPixel.x + 5 + polyRadius * Math.cos(aRad);
var pixelY = clickedPixel.y - 10 + polyRadius * Math.sin(aRad);
var polyPixel = new GPoint(pixelX,pixelY);
var polyPoint = mapNormalProj.fromPixelToLatLng(polyPixel,mapZoom);
polyPoints.push(polyPoint);
}
// Using GPolygon(points, strokeColor?, strokeWeight?, strokeOpacity?, fillColor?, fillOpacity?)
highlightCircle = new GPolygon(polyPoints,"#000000",2,0.0,"#FF0000",.5);
map.addOverlay(highlightCircle);

我设法将这段代码转换为api3:
var markerPoint = currentMarker.getPosition();

var polyPoints = Array();


var mapNormalProj = map.getProjection();
var mapZoom = map.getZoom();
var clickedPixel = mapNormalProj.fromLatLngToPoint(markerPoint);

var polyRadius = 20;

var polyNumSides = 20;
var polySideLength = 18;

for (var a = 0; a<(polyNumSides+1); a++) {
var aRad = polySideLength*a*(Math.PI/180);
var pixelX = clickedPixel.x + 5 + (polyRadius * Math.cos(aRad));
var pixelY = clickedPixel.y - 10 + (polyRadius * Math.sin(aRad));
var polyPixel = new google.maps.Point(pixelX,pixelY);
var polyPoint = mapNormalProj.fromPointToLatLng(polyPixel);
polyPoints.push(polyPoint);
}

highlightCircle = new google.maps.Polygon({
paths: polyPoints,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FF0000",
fillOpacity: 0.35
});

highlightCircle.setMap(map);

如果您仔细看一下api3示例,则不会在任何地方使用mapZoom变量...

在api2中,代码在我的标记周围生成了一个小圆圈-半径约为35px。当我放大 map 时,半径保持在35px。 (因为考虑了缩放)

另一方面,使用api3时,我有一个很大的圆圈-宽度超过200像素,放大时,圆圈变得越来越大。

它的行为与api3中可用的circle对象相同。

我想要的只是标记周围的小圆圈,直径不是100km,而是标记周围只有几个像素。 (此圆圈的行为类似于html中的悬停元素)

有什么想法要实现吗?

最佳答案

使用自定义标记(而不是圆圈)可能会带来更好的运气。请参见此处的文档中的“ vector 图标”:https://developers.google.com/maps/documentation/javascript/overlays#Icons

var marker = new google.maps.Marker({
position: new google.maps.LatLng(-25.363882, 131.044922),
icon: {
path: google.maps.SymbolPath.CIRCLE,
scale: 10
},
draggable: true,
map: map
});

关于google-maps-api-3 - 用不调整大小的Google Maps api3画一个圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4533576/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com