The German map is a hexagonal

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.