JavaScript-获取区域地图形状的坐标

JavaScript - Get coordinates of Area Map shapes

本文关键字:坐标 图形 地图 获取 区域 JavaScript-      更新时间:2023-09-26

我的HTML元素:

 <img src ="planets.gif" width="145" height="126" alt="Planets"
usemap="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun">
<area shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury">
<area shape="circle" coords="124,58,8" href="venus.htm" alt="Venus">
</map> 

如何使用Javascript获取map元素中包含的每个区域形状的coords

您可以尝试这样的方法。。。

实时演示

var coords = [];
[].forEach.call(document.querySelectorAll("area"), function (value, index, array) {
    coords.push(value.getAttribute("coords").split(","));
});