Title: The latitude and longitude coordinates of a known dot [longitude, latitude], drawing a hexagon with a radius of 3 km
Idea: The latitude and longitude coordinates are transformed into planar coordinates, the coordinates of six points are calculated on the plane coordinates, and the plane coordinates are converted to latitude and longitude coordinates.
Implementation: The final unit of calculation is converted into meters accordingly
1. latitude and longitude coordinates converted to meters
#获取当前的 "m/pixel" conversion ratio var per = map.getresolution (point); Get Unit m/pixel
#将经纬度坐标转成 "Pixel" var toPx = Map.lnglattopixel (point, zoom); Convert pixels
#根据像素以及比例 converted to "M" unit var CenterX = per * TOPX.GETX (); Convert pixels to meters var centery = per * Topx.gety (); |
2. Find the coordinates of six flat points according to the center position (the problem of floating point calculation is not considered first)
var pointnum = []; Pointnum.push ({x:centerx, y:centery + radius}, {X:centerx + sin60, Y:centery + COS60}, {X:centerx + sin60, Y:CENTERY-COS60}, {X:centerx, Y:centery-radius}, {x:centerx-sin60, Y:CENTERY-COS60}, {x:centerx-sin60, y:centery + COS60}); |
3. Convert six planar coordinates to latitude and longitude coordinates
#获取当前地图的缩放比例 var zoom = Map.getzoom (); var path = []; Pointnum.map (cur, index) = { #将 "M" Conversion "pixel" units var x = Cur.x/per, y = cur.y/per; #将平面坐标转经纬度坐标 Pointnum[index] = Map.pixeltolnglat (new Amap.pixel (x, y), zoom); #获取转化后的经度, Latitude, and save Path.push ([Pointnum[index].getlng (), Pointnum[index].getlat ()]); }); |
4. Display Hexagon
Let polygon = new Amap.polygon ({ Path:path, Strokecolor: ' Red ', Strokeopacity:1, Strokeweight:3, fillopacity:0.45 }); Polygon.setmap (map); #创建编辑对象 Editor.open (); |
The German map is a hexagonal