PageSourceSearch

https://geo13.ru/media/js/leaflet/google.js

js geo13.ru collected 2026-10-02 20:43:04 UTC 5,196 bytes, 176 lines download raw bytes

1/*
2 * Google layer using Google Maps API
3 */
4//(function (google, L) {
5
6L.Google = L.Class.extend({
7    includes: L.Mixin.Events,
8
9    options: {
10        minZoom: 0,
11        maxZoom: 18,
12        tileSize: 256,
13        subdomains: 'abc',
14        errorTileUrl: '',
15        attribution: '',
16        opacity: 1,
17        continuousWorld: false,
18        noWrap: false
19    },
20
21    // Possible types: SATELLITE, ROADMAP, HYBRID, TERRAIN
22    initialize: function(type, options) {
23        L.Util.setOptions(this, options);
24
25        this._ready = google.maps.Map != undefined;
26        if (!this._ready) L.Google.asyncWait.push(this);
27
28        this._type = type || 'SATELLITE';
29    },
30
31    onAdd: function(map, insertAtTheBottom) {
32        this._map = map;
33        this._insertAtTheBottom = insertAtTheBottom;
34
35        // create a container div for tiles
36        this._initContainer();
37        this._initMapObject();
38
39        // set up events
40        map.on('viewreset', this._resetCallback, this);
41
42        this._limitedUpdate = L.Util.limitExecByInterval(this._update, 150, this);
43        map.on('move', this._update, this);
44        //map.on('moveend', this._update, this);
45
46        map._controlCorners['bottomright'].style.marginBottom = "1em";
47
48        this._reset();
49        this._update();
50    },
51
52    onRemove: function(map) {
53        this._map._container.removeChild(this._container);
54        //this._container = null;
55
56        this._map.off('viewreset', this._resetCallback, this);
57
58        this._map.off('move', this._update, this);
59        map._controlCorners['bottomright'].style.marginBottom = "0em";
60        //this._map.off('moveend', this._update, this);
61    },
62
63    getAttribution: function() {
64        return this.options.attribution;
65    },
66
67    setOpacity: function(opacity) {
68        this.options.opacity = opacity;
69        if (opacity < 1) {
70            L.DomUtil.setOpacity(this._container, opacity);
71        }
72    },
73
74    setElementSize: function(e, size) {
75        e.style.width = size.x + "px";
76        e.style.height = size.y + "px";
77    },
78
79    _initContainer: function() {
80        var tilePane = this._map._container,
81            first = tilePane.firstChild;
82
83        if (!this._container) {
84            this._container = L.DomUtil.create('div', 'leaflet-google-layer leaflet-top leaflet-left');
85            this._container.id = "_GMapContainer_" + L.Util.stamp(this);
86            this._container.style.zIndex = "auto";
87        }
88
89        if (true) {
90            tilePane.insertBefore(this._container, first);
91
92            this.setOpacity(this.options.opacity);
93            this.setElementSize(this._container, this._map.getSize());
94        }
95    },
96
97    _initMapObject: function() {
98        if (!this._ready) return;
99        this._google_center = new google.maps.LatLng(0, 0);
100        var map = new google.maps.Map(this._container, {
101            center: this._google_center,
102            zoom: 0,
103            tilt: 0,
104            mapTypeId: google.maps.MapTypeId[this._type],
105            disableDefaultUI: true,
106            keyboardShortcuts: false,
107            draggable: false,
108            disableDoubleClickZoom: true,
109            scrollwheel: false,
110            streetViewControl: false
111        });
112
113        var _this = this;
114        this._reposition = google.maps.event.addListenerOnce(map, "center_changed",
115            function() { _this.onReposition(); });
116
117        map.backgroundColor = '#ff0000';
118        this._google = map;
119    },
120
121    _resetCallback: function(e) {
122        this._reset(e.hard);
123    },
124
125    _reset: function(clearOldContainer) {
126        this._initContainer();
127    },
128
129    _update: function() {
130        if (!this._google) return;
131        this._resize();
132
133        var bounds = this._map.getBounds();
134        var ne = bounds.getNorthEast();
135        var sw = bounds.getSouthWest();
136        var google_bounds = new google.maps.LatLngBounds(
137            new google.maps.LatLng(sw.lat, sw.lng),
138            new google.maps.LatLng(ne.lat, ne.lng)
139        );
140        var center = this._map.getCenter();
141        var _center = new google.maps.LatLng(center.lat, center.lng);
142
143        this._google.setCenter(_center);
144        this._google.setZoom(this._map.getZoom());
145        //this._google.fitBounds(google_bounds);
146    },
147
148    _resize: function() {
149        var size = this._map.getSize();
150        if (this._container.style.width == size.x &&
151            this._container.style.height == size.y)
152            return;
153        this.setElementSize(this._container, size);
154        this.onReposition();
155    },
156
157    onReposition: function() {
158        if (!this._google) return;
159        google.maps.event.trigger(this._google, "resize");
160    }
161});
162
163L.Google.asyncWait = [];
164L.Google.asyncInitialize = function() {
165    var i;
166    for (i = 0; i < L.Google.asyncWait.length; i++) {
167        var o = L.Google.asyncWait[i];
168        o._ready = true;
169        if (o._container) {
170            o._initMapObject();
171            o._update();
172        }
173    }
174    L.Google.asyncWait = [];
175}
176//})(window.google, 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.