目录

Calculating the Area

This section describes how to calculate the area of a geometric shape.

Procedure

  1. Create an HWPolygon object through HWMapJsSDK.
  2. Call the getPolygonArea method through HWMapJsSDK.HWGeometryUtil, and pass the created HWPolygon object.
  3. View the return value, which is the area of a polygon, in square meters.

Sample Code

var map;
var mapOptions = {};
mapOptions.zoom = 15;
map = new HWMapJsSDK.HWMap(document.getElementById('map'), mapOptions);
var polygon = new HWMapJsSDK.HWPolygon({
  map: map,
  paths: [
    [
      {lat: 49, lng: 2},
      {lat: 48.5, lng: 2.5},
      {lat: 48, lng: 1.5}
    ],
  ],
  fillColor: '#333',
  strokeColor: '#488',
  strokeWeight: 5,
  strokeLineDash: [20, 10]
});
var HWGeometryUtil = HWMapJsSDK.HWGeometryUtil;
var polygonArea = HWGeometryUtil.getPolygonArea(polygon);