function generateMap(id, zoom, coordinations) {
var options = {
zoom: zoom,
};
if (coordinations != undefined) {
if (checkValidCoordinations(coordinations)) {
options.center = coordinations;
}
}
map = L.map(id, options);
L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
maxZoom: maxZoom,
attribution: "© OpenStreetMap",
}).addTo(map);
}
function setCoords() {
if (coordinations.length > 0) {
coordinations.forEach(function (coord) {
if (checkValidCoordinations(coord)) {
var bounds = L.latLngBounds(coordinations);
map.fitBounds(bounds);
}
});
} else {
map.panTo([centerLatPosition, centerLngPosition]);
}
}
function getDefaultIconOptions() {
return {
iconSize: globalIconSize,
iconAnchor: iconAnchor,
popupAnchor: popupAnchor,
tooltipAnchor: tooltipAnchor,
iconUrl: iconUrl[5],
};
}
function setMarker(name, options) {
if (checkValidCoordinations(options.coordinations)) {
var marker;
if (options.sourceMap) {
marker = L.marker(options.coordinations, options).addTo(
options.sourceMap
);
} else {
marker = L.marker(options.coordinations, options).addTo(map);
}
if (options.popup) {
marker.bindPopup(options.popupContent);
}
if (options.tooltip) {
marker.bindTooltip(options.tooltipContent);
}
markers[name] = marker;
}
}
function markerOpenTooltip(name) {
markers[name].openTooltip();
}
function markerOpenPopup(name) {
markers[name].openPopup();
}
function polygonOpenPopup(name) {
polygons[name].openPopup();
}
function setIcon(options) {
return L.icon(options);
}
function setDivIcon(options) {
return L.divIcon(options);
}
function setMarkerClickEvent(name, iconOptions, callback, args) {
markers[name].on("click", function () {
markers[name].setIcon(setIcon(iconOptions));
if (callback) {
callback(args);
}
});
}
function setPolygon(name, options) {
var polygon = L.polygon(
options.coordinations,
options.polygonOptions
).addTo(map);
if (options.popup) {
polygon.bindPopup(options.popupContent);
}
polygons[name] = polygon;
}
function setPolyline(name, options) {
var polyline = L.polyline(
options.coordinations,
options.polylineOptions
).addTo(map);
polylines[name] = polyline;
}
function setPolylineClickEvent(name, callback, args) {
polylines[name].on("click", function () {
if (callback) {
callback(args);
}
});
}
function addCoordinations(latitude, longitude) {
coordinations.push(Array.of(parseFloat(latitude), parseFloat(longitude)));
}
function changeMarkerColor(sensor, options) {
var marker = markers[sensor];
if (marker.getTooltip()._content.length) {
options.tooltip = true;
options.tooltipContent = marker.getTooltip()._content;
}
options.sourceMap = marker._map;
setMarker(sensor, options);
}
function setMapClickEvent(callback) {
map.on("click", function (e) {
if (callback) {
callback(e);
}
});
}
function clearMap() {
var index = 0;
for (var id in map._layers) {
if (index > 0) {
map.removeLayer(map._layers[id]);
}
index++;
}
}
function deleteMap() {
map.off();
map.remove();
}
function enableGeocoder() {
var geocoder = L.Control.Geocoder.nominatim();
L.Control.geocoder({
placeholder: "Hledat na mapÄ›...",
geocoder: geocoder,
}).addTo(map);
}
function setCircle(name, options) {
var circle = L.circle(options.coordinations, options.circleOptions).addTo(
map
);
circles[name] = circle;
}
function setRouting(name, options) {
var route = L.Routing.control(options).addTo(map);
routes[name] = route;
}
function generateOtherMap(id, zoom, coordinations) {
var options = {
zoom: zoom,
};
if (coordinations != undefined) {
if (checkValidCoordinations(coordinations)) {
options.center = coordinations;
}
}
var map = L.map(id, options);
L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
maxZoom: maxZoom,
attribution: "© OpenStreetMap",
}).addTo(map);
return map;
}
function setCoordsByMap(map, coordinations) {
if (coordinations.length > 0) {
coordinations.forEach(function (coord) {
if (checkValidCoordinations(coord)) {
var bounds = L.latLngBounds(coordinations);
map.fitBounds(bounds);
}
});
} else {
map.panTo([centerLatPosition, centerLngPosition]);
}
}