-
-
Save crofty/2197042 to your computer and use it in GitHub Desktop.
/* | |
* L.TileLayer is used for standard xyz-numbered tile layers. | |
*/ | |
L.Google = L.Class.extend({ | |
includes: L.Mixin.Events, | |
options: { | |
minZoom: 0, | |
maxZoom: 18, | |
tileSize: 256, | |
subdomains: 'abc', | |
errorTileUrl: '', | |
attribution: '', | |
opacity: 1, | |
continuousWorld: false, | |
noWrap: false, | |
}, | |
// Possible types: SATELLITE, ROADMAP, HYBRID | |
initialize: function(type, options) { | |
L.Util.setOptions(this, options); | |
this._type = google.maps.MapTypeId[type || 'SATELLITE']; | |
}, | |
onAdd: function(map, insertAtTheBottom) { | |
this._map = map; | |
this._insertAtTheBottom = insertAtTheBottom; | |
// create a container div for tiles | |
this._initContainer(); | |
this._initMapObject(); | |
// set up events | |
map.on('viewreset', this._resetCallback, this); | |
this._limitedUpdate = L.Util.limitExecByInterval(this._update, 150, this); | |
map.on('move', this._update, this); | |
//map.on('moveend', this._update, this); | |
this._reset(); | |
this._update(); | |
}, | |
onRemove: function(map) { | |
this._map._container.removeChild(this._container); | |
//this._container = null; | |
this._map.off('viewreset', this._resetCallback, this); | |
this._map.off('move', this._update, this); | |
//this._map.off('moveend', this._update, this); | |
}, | |
getAttribution: function() { | |
return this.options.attribution; | |
}, | |
setOpacity: function(opacity) { | |
this.options.opacity = opacity; | |
if (opacity < 1) { | |
L.DomUtil.setOpacity(this._container, opacity); | |
} | |
}, | |
_initContainer: function() { | |
var tilePane = this._map._container | |
first = tilePane.firstChild; | |
if (!this._container) { | |
this._container = L.DomUtil.create('div', 'leaflet-google-layer leaflet-top leaflet-left'); | |
this._container.id = "_GMapContainer"; | |
} | |
if (true) { | |
tilePane.insertBefore(this._container, first); | |
this.setOpacity(this.options.opacity); | |
var size = this._map.getSize(); | |
this._container.style.width = size.x + 'px'; | |
this._container.style.height = size.y + 'px'; | |
} | |
}, | |
_initMapObject: function() { | |
this._google_center = new google.maps.LatLng(0, 0); | |
var map = new google.maps.Map(this._container, { | |
center: this._google_center, | |
zoom: 0, | |
mapTypeId: this._type, | |
disableDefaultUI: true, | |
keyboardShortcuts: false, | |
draggable: false, | |
disableDoubleClickZoom: true, | |
scrollwheel: false, | |
streetViewControl: false | |
}); | |
var _this = this; | |
this._reposition = google.maps.event.addListenerOnce(map, "center_changed", | |
function() { _this.onReposition(); }); | |
map.backgroundColor = '#ff0000'; | |
this._google = map; | |
}, | |
_resetCallback: function(e) { | |
this._reset(e.hard); | |
}, | |
_reset: function(clearOldContainer) { | |
this._initContainer(); | |
}, | |
_update: function() { | |
this._resize(); | |
var bounds = this._map.getBounds(); | |
var ne = bounds.getNorthEast(); | |
var sw = bounds.getSouthWest(); | |
var google_bounds = new google.maps.LatLngBounds( | |
new google.maps.LatLng(sw.lat, sw.lng), | |
new google.maps.LatLng(ne.lat, ne.lng) | |
); | |
var center = this._map.getCenter(); | |
var _center = new google.maps.LatLng(center.lat, center.lng); | |
this._google.setCenter(_center); | |
this._google.setZoom(this._map.getZoom()); | |
//this._google.fitBounds(google_bounds); | |
}, | |
_resize: function() { | |
var size = this._map.getSize(); | |
if (this._container.style.width == size.x && | |
this._container.style.height == size.y) | |
return; | |
this._container.style.width = size.x + 'px'; | |
this._container.style.height = size.y + 'px'; | |
google.maps.event.trigger(this._google, "resize"); | |
}, | |
onReposition: function() { | |
//google.maps.event.trigger(this._google, "resize"); | |
} | |
}); |
What version does this code apply to? Not the current one.
Unfortunately I can't get this to work with https://github.com/consbio/Leaflet.Basemaps
Very laggy.
anybody get this work with leaflet 1.0.2 ?
Please fix the URL, correct one should be http://www.matchingnotes.com/using-google-map-tiles-with-leaflet.html
Your returns 404
Also user HTTPS please.
Also this is not working anymore.
I want use google direction
Does anyone have a working jsfiddle with pegman dragable? I have him visible but nothing happens when I click . Leafelt 1.2.0 GridLayer.GoogleMutant 0.6.4 thanks in advance.
License Status
Note on the license status of this file.
As indicated on (the archive page) https://web.archive.org/web/20180728014324/http://matchingnotes.com/using-google-map-tiles-with-leaflet @crofty has started with https://web.archive.org/web/20180728014324/http://psha.org.ru/leaflet/Google.js which got imported into
https://raw.githubusercontent.com/shramov/leaflet-plugins/ on 2019-04-18.
The difference to the initially imported file from @shramov shows that @crofty has only made a very small change
which very likely is not copyrightable, see the change:
curl
https://raw.githubusercontent.com/shramov/leaflet-plugins/6b13ac67aacbb3d46df5e78905f836cacb31b86a/layer/tile/Google.js
-o Google-20120418shramov.js
curl -O
https://gist.githubusercontent.com/crofty/2197042/raw/235e1842856de77035cfc69e8abb42cd7e3793d2/leaflet-google.js
leaflet-google-2012crofty.js
diff -U0 Google-20120418shramov.js leaflet-google-2012crofty.js
--- Google-20120418shramov.js 2019-08-26 11:38:37.062456529 +0200
+++ leaflet-google-2012crofty.js 2019-08-26 11:00:35.545241651 +0200
@@ -4 +3,0 @@
-
@@ -81,2 +80,2 @@
- this._container.style.width = size.x;
- this._container.style.height = size.y;
+ this._container.style.width = size.x + 'px';
+ this._container.style.height = size.y + 'px';
@@ -139,2 +138,2 @@
- this._container.style.width = size.x;
- this._container.style.height = size.y;
+ this._container.style.width = size.x + 'px';
+ this._container.style.height = size.y + 'px';
Thus we can conclude that the 99% of the file the rights will be with @shramov.
He placed the files in the github repository under MIT on 2012-07-31 (see shramov/leaflet-plugins@39cd5da#diff-9879d6db96fd29134fc802214163b95a) , which included an improved Google.js file, which still is quite similar. If we assume that this clarification in July 2012 was meant for earlier versions of the file as well, then this file is most likely copyright @shramov under MIT.
Thx for pointing. Yes, that's based on my script. Later it was dropped from leaflet-plugins since there is better version: shramov/leaflet-plugins#250
@shramov thanks for the clarification!
Note that the problem with the new "version" is that it is not properly licensed so far, see https://gitlab.com/IvanSanchez/Leaflet.GridLayer.GoogleMutant/issues/102
Licence for this script is really minor issue compared to debatable status of whole plugin - is it legal to use Google maps this way or not :)
@shramov unfortunately those are two different questions, which are both important.
- As we are using Free Software in a commercial setting, the current Leaflet.GridLayer.GoogleMutant will not pass any serious licensing clearing house (precisely there is no permission to use it, because the license of you and Bergot is violated).
- When using the Google Maps API with a key, a number of people evaluated this as acceptable. But this is a matter between different parties: google and the organisation that bought the api key from them. Maybe this should or is discussed in more depth somewhere else?
Is there a final agreement on whether using the google maps API tiles without showing/using the shell is legal?
@S767, thank you very much!