Skip to content

Commit

Permalink
Merge branch 'fix-google-map-offsets-in-china' into fix-google-map-of…
Browse files Browse the repository at this point in the history
…fsets-in-china
  • Loading branch information
johnd0e authored Jan 17, 2019
2 parents ad23110 + b07f133 commit 555f025
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
6 changes: 4 additions & 2 deletions external/Leaflet.GoogleMutant.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,13 @@ L.GridLayer.GoogleMutant = L.GridLayer.extend({
this._initContainer();
},

_update: function () {
_update: function (center) {
// zoom level check needs to happen before super's implementation (tile addition/creation)
// otherwise tiles may be missed if maxNativeZoom is not yet correctly determined
if (this._mutant) {
var center = this._map.getCenter();
if (center === undefined) {
var center = this._map.getCenter();
}

This comment has been minimized.

Copy link
@johnd0e

johnd0e Jan 17, 2019

Contributor

This commit changed external source file which can lead to troubles when we decide to update this external dependency.

So we should avoid this if we can.
Better approach is to extend.
Or monkey-patch in runtime (as a last resort).

If we still need to patch dependency then we have to document it thoroughly.

This comment has been minimized.

Copy link
@johnd0e
var _center = new google.maps.LatLng(center.lat, center.lng);

this._mutant.setCenter(_center);
Expand Down
22 changes: 14 additions & 8 deletions plugins/fix-googlemap-china-offset.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,16 @@ var PRCoords = window.plugin.fixChinaOffset.PRCoords = (function () {
};
})();

// ///////// end WGS84 to GCJ-02 obfuscator /////////
///////// end WGS84 to GCJ-02 obfuscator /////////

// ///////// begin overwrited L.GridLayer /////////
///////// begin overwrited L.GridLayer /////////

L.GridLayer.prototype._getTiledPixelBounds = (function () {
return function (center) {
// >> edited here
return function (center) {
///// modified here ///
center = window.plugin.fixChinaOffset.getLatLng(center, this.options.type);
//
var map = this._map,
///////////////////////
var map = this._map,
mapZoom = map._animatingZoom ? Math.max(map._animateToZoom, map.getZoom()) : map.getZoom(),
scale = map.getZoomScale(mapZoom, this._tileZoom),
pixelCenter = map.project(center, this._tileZoom).floor(),
Expand All @@ -260,11 +260,17 @@ L.GridLayer.prototype._getTiledPixelBounds = (function () {
L.GridLayer.prototype._setZoomTransform = (function (original) {
return function (level, center, zoom) {
center = window.plugin.fixChinaOffset.getLatLng(center, this.options.type);
original.apply(this, arguments);
original.apply(this, [level, center, zoom]);
};
})(L.GridLayer.prototype._setZoomTransform);

// ///////// end overwrited L.GridLayer /////////
L.GridLayer.GoogleMutant.prototype._update = (function (original) {
return function () {
var center = this._map.getCenter();
center = window.plugin.fixChinaOffset.getLatLng(center, this.options.type);
original.apply(this, [center]);
}
})(L.GridLayer.GoogleMutant.prototype._update);

window.plugin.fixChinaOffset.getLatLng = function (pos, type) {
// No offsets in satellite and hybrid maps
Expand Down

1 comment on commit 555f025

@johnd0e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment here

Please sign in to comment.