Creating and deleting
The main component of the API is a map that can be placed in any block HTML element and always has a rectangular shape.
To create a map, use the Map class. In the constructor, specify the center, the zoom level, and the HTML element the map will be placed in.
index.html
mapbasics.js
<!DOCTYPE html>
<html>
<head>
<meta
http-equiv="Content-Type"
content="text/html; charset=UTF-8"
/>
<title>Examples. Putting the map on a page.</title>
<!--
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="mapbasics.js" type="text/javascript"></script>
<style>
body,
html {
padding: 0;
margin: 0;
width: 100%;
height: 100%;
}
#map {
width: 100%;
height: 90%;
}
</style>
</head>
<body>
<div id="map"></div>
<input type="button" id="destroyButton" value="Delete map" />
</body>
</html>
var myMap;
// Waiting for the API to load and DOM to be ready.
ymaps.ready(init);
function init() {
/**
* Creating an instance of the map and binding it to the container
* with the specified ID ("map").
*/
myMap = new ymaps.Map(
"map",
{
/**
* When initializing the map, you must specify
* its center and the zoom factor.
*/
center: [55.76, 37.64], // Moscow
zoom: 10,
},
{
searchControlProvider: "yandex#search",
}
);
document.getElementById("destroyButton").onclick = function () {
// To destroy it, the "destroy" method is used.
myMap.destroy();
};
}