PageSourceSearch

https://p-on.ru/third-party/leaflet-plugins/layer/tile/Yandex.js

js p-on.ru collected 2026-09-24 10:55:20 UTC 4,202 bytes, 161 lines download raw bytes

1/*
2 * L.TileLayer is used for standard xyz-numbered tile layers.
3 */
4//(function (ymaps, L) {
5
6L.Yandex = L.Class.extend({
7	includes: L.Mixin.Events,
8
9	options: {
10		minZoom: 0,
11		maxZoom: 18,
12		attribution: '',
13		opacity: 1,
14		traffic: false
15	},
16
17	// Possible types: map, satellite, hybrid, publicMap, publicMapHybrid
18	initialize: function(type, options) {
19		L.Util.setOptions(this, options);
20
21		this._type = "yandex#" + (type || 'map');
22	},
23
24	onAdd: function(map, insertAtTheBottom) {
25		this._map = map;
26		this._insertAtTheBottom = insertAtTheBottom;
27
28		// create a container div for tiles
29		this._initContainer();
30		this._initMapObject();
31
32		// set up events
33		map.on('viewreset', this._resetCallback, this);
34
35		this._limitedUpdate = L.Util.limitExecByInterval(this._update, 150, this);
36		map.on('move', this._update, this);
37
38		map._controlCorners['bottomright'].style.marginBottom = "3em";
39
40		this._reset();
41		this._update(true);
42	},
43
44	onRemove: function(map) {
45		this._map._container.removeChild(this._container);
46
47		this._map.off('viewreset', this._resetCallback, this);
48
49		this._map.off('move', this._update, this);
50
51		map._controlCorners['bottomright'].style.marginBottom = "0em";
52	},
53
54	getAttribution: function() {
55		return this.options.attribution;
56	},
57
58	setOpacity: function(opacity) {
59		this.options.opacity = opacity;
60		if (opacity < 1) {
61			L.DomUtil.setOpacity(this._container, opacity);
62		}
63	},
64
65	setElementSize: function(e, size) {
66		e.style.width = size.x + "px";
67		e.style.height = size.y + "px";
68	},
69
70	_initContainer: function() {
71		var tilePane = this._map._container,
72			first = tilePane.firstChild;
73
74		if (!this._container) {
75			this._container = L.DomUtil.create('div', 'leaflet-yandex-layer leaflet-top leaflet-left');
76			this._container.id = "_YMapContainer_" + L.Util.stamp(this);
77			this._container.style.zIndex = "auto";
78		}
79
80		if (this.options.overlay) {
81			first = this._map._container.getElementsByClassName('leaflet-map-pane')[0];
82			first = first.nextSibling;
83			// XXX: Bug with layer order
84			if (L.Browser.opera)
85				this._container.className += " leaflet-objects-pane";
86		}
87		tilePane.insertBefore(this._container, first);
88
89		this.setOpacity(this.options.opacity);
90		this.setElementSize(this._container, this._map.getSize());
91	},
92
93	_initMapObject: function() {
94		if (this._yandex) return;
95
96		// Check that ymaps.Map is ready
97		if (ymaps.Map === undefined) {
98			if (console) {
99				console.debug("L.Yandex: Waiting on ymaps.load('package.map')");
100			}
101			return ymaps.load(["package.map"], this._initMapObject, this);
102		}
103
104		// If traffic layer is requested check if control.TrafficControl is ready
105		if (this.options.traffic)
106			if (ymaps.control === undefined ||
107					ymaps.control.TrafficControl === undefined) {
108				if (console) {
109					console.debug("L.Yandex: loading traffic and controls");
110				}
111				return ymaps.load(["package.traffic", "package.controls"],
112					this._initMapObject, this);
113			}
114
115		var map = new ymaps.Map(this._container, {center: [0,0], zoom: 0, behaviors: []});
116
117		if (this.options.traffic)
118			map.controls.add(new ymaps.control.TrafficControl({shown: true}));
119
120		if (this._type == "yandex#null") {
121			this._type = new ymaps.MapType("null", []);
122			map.container.getElement().style.background = "transparent";
123		}
124		map.setType(this._type);
125
126		this._yandex = map;
127		this._update(true);
128	},
129
130	_resetCallback: function(e) {
131		this._reset(e.hard);
132	},
133
134	_reset: function(clearOldContainer) {
135		this._initContainer();
136	},
137
138	_update: function(force) {
139		if (!this._yandex) return;
140		this._resize(force);
141
142		var center = this._map.getCenter();
143		var _center = [center.lat, center.lng];
144		var zoom = this._map.getZoom();
145
146		if (force || this._yandex.getZoom() != zoom)
147			this._yandex.setZoom(zoom);
148		this._yandex.panTo(_center, {duration: 0, delay: 0});
149	},
150
151	_resize: function(force) {
152		var size = this._map.getSize(), style = this._container.style;
153		if (style.width == size.x + "px" &&
154				style.height == size.y + "px")
155			if (force != true) return;
156		this.setElementSize(this._container, size);
157		var b = this._map.getBounds(), sw = b.getSouthWest(), ne = b.getNorthEast();
158		this._yandex.container.fitToViewport();
159	}
160});
161//})(ymaps, L)

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.