function NovgorodMap(element_id, lat, lng, zoom, onload) {
this.map_tileserver='https://osm.novgorod.ru/tiles/{z}/{x}/{y}.png';
this.map_tileattribution='Map data © OpenStreetMap';
this.map=false;
$('head').append( $('').attr('href', 'https://i.novgorod.ru/jquery/leaflet/leaflet.css') );
$('head').append( $('').attr('href', 'https://i.novgorod.ru/jquery/leaflet/leaflet.fullscreen.css') );
var that=this;
$.getScript('https://i.novgorod.ru/jquery/leaflet/leaflet.js', function() {
$.getScript('https://i.novgorod.ru/jquery/leaflet/Leaflet.fullscreen.js', function() {
L.NumberedDivIcon = L.Icon.extend({
options: {
iconUrl: 'https://i.novgorod.ru/map/markers/marker-novgorodru.png',
number: '',
shadowUrl: null,
iconSize: new L.Point(25, 41),
iconAnchor: new L.Point(13, 41),
popupAnchor: new L.Point(0, -33),
className: 'leaflet-div-icon'
},
createIcon: function () {
var div = document.createElement('div');
var img = this._createImg(this.options['iconUrl']);
var numdiv = document.createElement('div');
numdiv.setAttribute ( "class", "number" );
numdiv.innerHTML = this.options['number'] || '';
div.appendChild ( img );
div.appendChild ( numdiv );
this._setIconStyles(div, 'icon');
return div;
},
createShadow: function () {
return null;
}
});
if (typeof(lat) === 'undefined') lat=0;
if (typeof(lng) === 'undefined') lng=0;
if (typeof(zoom) === 'undefined') zoom=0;
if (lat==0) lat=58;
if (lng==0) lng=31;
if (zoom==0) zoom=13;
if ($('#'+element_id).length==0) {
console.log('Map container not found: '+element_id);
return;
}
var southWest = L.latLng(56.73, 27.64), northEast = L.latLng(60.15, 36.27);
var bounds = L.latLngBounds(southWest, northEast);
that.map = L.map(element_id, { zoomControl: false, maxZoom:22, maxBoundsViscosity: 100, maxBounds: bounds});
L.control.zoom({ position:'bottomright'}).addTo(that.map);
that.map.addControl(new L.Control.Fullscreen({position: 'bottomright'}));
that.map.setView(new L.LatLng(lat, lng), zoom);
L.tileLayer(that.map_tileserver, {attribution: that.map_tileattribution, maxZoom:22, maxNativeZoom: 18}).addTo(that.map);
var that1=that;
$('#'+element_id).contextmenu( that.makeDoubleRightClickHandler( function(e) {
that.map.zoomOut();
}));
if (typeof onload === 'function') onload(that.map);
});
});
this.makeDoubleRightClickHandler=function(handler) {
var timeout = 0, clicked = false;
return function(e) {
e.preventDefault();
if( clicked ) {
clearTimeout(timeout);
clicked = false;
return handler.apply( this, arguments );
}
else {
clicked = true;
timeout = setTimeout( function() {
clicked = false;
}, 300 );
}
};
}
this.getMap = function() {
return this.map;
}
}