2GIS Map API
Polyline geometry example
by Trufi
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>2GIS Map API</title>
<meta name="description" content="Polyline geometry example">
</head>
<body>
<div id="container"></div>
<script src="https://mapgl.2gis.com/api/js"></script>
</body>
</html>
CSS
html,
body,
#container {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
}
JavaScript
// API key can be used on jsfiddle.net only!
// You can get more info on https://docs.2gis.com/
const center = [55.31878, 25.23584];
const map = new mapgl.Map('container', {
center,
zoom: 13,
key: 'bfd8bbca-8abf-11ea-b033-5fa57aae2de7',
});
const coordinates = [];
for (let i = 0; i < 10000; i++) {
coordinates.push([center[0] + (0.5 - Math.random() * 2), center[1] + (0.5 - Math.random())]);
}
const polyline = new mapgl.Polyline(map, {
coordinates,
width: 3,
color: '#00b7ff',
});
polyline.on('click', () => {
alert('Polyline click');
});