Polygon
YMapsML is a language for describing geographical objects.
In YMapsML, each geographical object is associated with a geometric shape and a geo object that is used for displaying this shape on the map. The shape definitions and their anchors to geographical coordinates are set in corresponding YMapsML elements. The gml:Polygon element is designated for the "polygon" shape. It contains the gml:exterior element, which lists the coordinates of the vertexes of the polygon's exterior contour. A polygon may also contain interior contours. Their vertexes are set in the gml:interior element.
The geoXml.load function is used for loading YMapsML data. After data loads, the function converts it to GeoObjectCollection and passes it to the handler function as a parameter. A GeoObjectCollection can be displayed on the map.
<!DOCTYPE html>
<html>
<head>
<title>YMapsML examples. Adding placemarks to the map.</title>
<meta
http-equiv="Content-Type"
content="text/html; charset=UTF-8"
/>
<!--
Set your own API-key. Testing key is not valid for other web-sites and services.
Get your API-key on the Developer Dashboard: https://developer.tech.yandex.ru/keys/
-->
<script
src="https://api-maps.yandex.ru/2.1/?lang=en_RU&apikey=<your API-key>"
type="text/javascript"
></script>
<script src="ymapsml_polygon.js" type="text/javascript"></script>
<style>
html,
body,
#map {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<div id="map"></div>
</body>
</html>
ymaps.ready(init);
function init() {
// Creating an instance of the map.
var myMap = new ymaps.Map(
"map",
{
center: [61.766513, 34.344165],
zoom: 12,
},
{
searchControlProvider: "yandex#search",
}
);
// Loading a YMapsML file.
ymaps.geoXml.load("data.xml").then(
function (res) {
// Adding geo objects to the map.
myMap.geoObjects.add(res.geoObjects);
// Called if loading the YMapsML file was unsuccessful.
},
function (error) {
alert("Error: " + error);
}
);
}