util.calculateArea
module allows to calculate the area of polygons, rectangles and circles.
Note that plugin works only with geodesic geometries.
-
Load both Yandex Maps JS API 2.1 and module source code by adding following code into <head> section of your page
<script src="http://api-maps.yandex.ru/2.1/?lang=ru_RU" type="text/javascript"></script> <!-- Change my.cdn.tld to your CDN host name --> <script src="https://yastatic.net/s3/mapsapi-jslibs/area/0.0.1/util.calculateArea.min.js" type="text/javascript"></script>
-
Wait for both API and module loaded
ymaps.ready(['util.calculateArea']).then(function () { var myPolygon = new ymaps.Polygon(someCoordinates); // You can calculate area of any type of ymaps.GeoObject. var area = ymaps.util.calculateArea(myPolygon); // Or you can calculate area of GeoJson feature. var areaFromJson = ymaps.util.calculateArea({ type: 'Feature', geometry: { type: 'Rectangle', coordinates: someRectangleCoordinates } }); });
Note: module definition uses standard Yandex Maps API namespace 'ymaps'. If you are using custom namespace, you need to fork and rebuild module for your needs.
geoObject descibed using one of following formats:
- ymaps.GeoObject
- ymaps.Polygon
- ymaps.Rectangle
- ymaps.Circle
- GeoJson Polygon
- GeoJson Rectangle
- GeoJson Circle
Returns geoObject area in square meters.
If you want to make a pull-request, run tests and check code style first.
```js
npm install
npm run-script lint
npm test
```
The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of OpenLayers Contributors.