Skip to main content

Utils

A collection of measurement methods for two-dimensional data.

Usage

let Utils = mapmost.Utils;

method

area(data)

Calculate the area of ​​a closed surface data composed of a series of coordinates. The input data is a three-dimensional array of longitude and latitude coordinates and local 2000 coordinates. The return value unit is square meters.

Utils.area([[[120, 31],[122, 31],[122, 30],[120, 30],[120, 31],[122, 31]]])
// or
Utils.area([[[342171, 665836],[342188, 665836],[342188, 665810],[342171, 665810],[342171, 665836]]])

centerOfMass(data)

Calculate the geometric center of a geometric figure. The input data is a three-dimensional array of longitude and latitude coordinates and local 2000 coordinates, and the two-dimensional coordinates are returned.

Utils.centerOfMass([[[120, 31],[122, 31],[122, 30],[120, 30],[120, 31],[122, 31]]])
// or
Utils.centerOfMass([[[342171, 665836],[342188, 665836],[342188, 665810],[342171, 665810],[342171, 665836]]])

distance(data)

Calculate the length of a series of coordinate data. The input data is a two-dimensional array of longitude and latitude coordinates and local 2000 coordinates. The return value unit is meters.

Utils.distance([[120, 31],[122, 32]])
// or
Utils.distance([[342171, 665836],[342188, 665836],[342188, 665810]])

Case

let Utils = mapmost.Utils;
let center = Utils.centerOfMass(coordinates); // Calculate the geometric center of the geometric figure
let area = Utils.area(coordinates)
let area1 = Math.round(area * 100) / 100;
//Custom popup
let div = window.document.createElement('div');
div.innerHTML = area1 + '&nbspm²';
let popup = new mapmost.Popup({closeOnClick: false, className: 'popup'})
.setLngLat(center.geometry.coordinates)
.setDOMContent(div)
.addTo(map);
allPopups.push(popup);

Refer to Example.