Skip to content

Instantly share code, notes, and snippets.

@seyfro
Created February 13, 2015 20:31
Show Gist options
  • Save seyfro/5a469a4652a60f414696 to your computer and use it in GitHub Desktop.
Save seyfro/5a469a4652a60f414696 to your computer and use it in GitHub Desktop.
leaflet / google maps addon
"enabled" == mapsmarkerjspro.google_maps_api_status && (google.load("maps", "3", {
other_params: "sensor=false" + mapsmarkerjspro.googlemaps_language + mapsmarkerjspro.googlemaps_base_domain + mapsmarkerjspro.googlemaps_libraries
}), L.Google = L.Class.extend({
includes: L.Mixin.Events,
options: {
minZoom: 0,
maxZoom: mapsmarkerjspro.maxzoom,
maxNativeZoom: 21,
tileSize: 256,
subdomains: "abc",
errorTileUrl: "",
attribution: "",
opacity: 1,
continuousWorld: !1,
noWrap: !1,
mapOptions: {
backgroundColor: "#F6F6F6"
}
},
initialize: function(a, b) {
L.Util.setOptions(this, b), this._ready = void 0 != google.maps.Map, this._ready || L.Google.asyncWait.push(this), this._type = a || "SATELLITE"
},
onAdd: function(a, b) {
this._map = a, this._insertAtTheBottom = b, this._initContainer(), this._initMapObject(), "enabled" == mapsmarkerjspro.google_adsense_status && this._initAdSense(), a.on("viewreset", this._resetCallback, this), this._limitedUpdate = L.Util.limitExecByInterval(this._update, 150, this), a.on("move", this._update, this), a.on("zoomanim", this._handleZoomAnim, this), a._controlCorners.bottomright.style.marginBottom = "15px", a._controlCorners.bottomleft.style.marginBottom = "21px", this._reset(), this._update()
},
onRemove: function(a) {
a._container.removeChild(this._container), a.off("viewreset", this._resetCallback, this), a.off("move", this._update, this), a.off("zoomanim", this._handleZoomAnim, this), a._controlCorners.bottomright.style.marginBottom = "0em"
},
getAttribution: function() {
return this.options.attribution
},
setOpacity: function(a) {
this.options.opacity = a, 1 > a && L.DomUtil.setOpacity(this._container, a)
},
setElementSize: function(a, b) {
a.style.width = b.x + "px", a.style.height = b.y + "px"
},
_initContainer: function() {
var a = this._map._container,
b = a.firstChild;
this._container || (this._container = L.DomUtil.create("div", "leaflet-google-layer leaflet-top leaflet-left"), this._container.id = "_GMapContainer_" + L.Util.stamp(this), this._container.style.zIndex = "auto"), a.insertBefore(this._container, b), this.setOpacity(this.options.opacity), this.setElementSize(this._container, this._map.getSize())
},
_initMapObject: function() {
if (this._ready) {
this._google_center = new google.maps.LatLng(0, 0);
var map = new google.maps.Map(this._container, {
center: this._google_center,
zoom: 0,
tilt: 0,
mapTypeId: google.maps.MapTypeId[this._type],
disableDefaultUI: !0,
keyboardShortcuts: !1,
draggable: !1,
disableDoubleClickZoom: !0,
scrollwheel: !1,
streetViewControl: !1,
backgroundColor: this.options.mapOptions.backgroundColor
});
if ("disabled" != mapsmarkerjspro.google_styling_json) {
var styles = eval(mapsmarkerjspro.google_styling_json);
map.setOptions({
styles: styles
})
}
var _this = this;
this._reposition = google.maps.event.addListenerOnce(map, "center_changed", function() {
_this.onReposition()
}), this._google = map, google.maps.event.addListenerOnce(map, "idle", function() {
_this._checkZoomLevels()
}), google.maps.event.addListenerOnce(map, "tilesloaded", function() {
_this.fire("load")
}), this.fire("MapObjectInitialized", {
mapObject: map
})
}
},
_checkZoomLevels: function() {
this._google.getZoom() !== this._map.getZoom() && this._map.setZoom(this._google.getZoom())
},
_resetCallback: function(a) {
this._reset(a.hard)
},
_handleZoomAnim: function(a) {
var b = a.center,
c = new google.maps.LatLng(b.lat, b.lng);
this._google.setCenter(c), this._google.setZoom(Math.round(a.zoom))
},
_reset: function() {
this._initContainer()
},
_update: function() {
if (this._google) {
this._resize();
var b = this._map.getCenter(),
c = new google.maps.LatLng(b.lat, b.lng);
this._google.setCenter(c), this._google.setZoom(Math.round(this._map.getZoom())), this._checkZoomLevels(), this._google.getZoom() != this._map.getZoom() && this._map.setZoom(this._google.getZoom())
}
},
_resize: function() {
var a = this._map.getSize();
(this._container.style.width != a.x || this._container.style.height != a.y) && (this.setElementSize(this._container, a), this.onReposition())
},
onReposition: function() {
this._google && google.maps.event.trigger(this._google, "resize")
},
_initAdSense: function() {
var a = document.createElement("div");
a.className = "leaflet-control", a.style.margin = "0", a.style.clear = "none";
var b = new String;
b.format = google.maps.adsense.AdFormat[mapsmarkerjspro.google_adsense_format], b.position = google.maps.ControlPosition[mapsmarkerjspro.google_adsense_position], b.cposition = mapsmarkerjspro.google_adsense_position, b.backgroundColor = mapsmarkerjspro.google_adsense_backgroundColor, b.borderColor = mapsmarkerjspro.google_adsense_borderColor, b.titleColor = mapsmarkerjspro.google_adsense_titleColor, b.textColor = mapsmarkerjspro.google_adsense_textColor, b.urlColor = mapsmarkerjspro.google_adsense_urlColor, b.channelNumber = mapsmarkerjspro.google_adsense_channelNumber, b.publisherID = mapsmarkerjspro.google_adsense_publisherId;
var c = {
format: b.format,
position: b.position,
backgroundColor: b.backgroundColor,
borderColor: b.borderColor,
titleColor: b.titleColor,
textColor: b.textColor,
urlColor: b.urlColor,
map: this._google,
visible: !0,
channelNumber: b.channelNumber,
publisherId: b.publisherID
},
d = this._map.getSize();
d.x > 150 && (this._adUnit = new google.maps.adsense.AdUnit(a, c))
}
}), L.Google.asyncWait = [], L.Google.asyncInitialize = function() {
var a;
for (a = 0; a < L.Google.asyncWait.length; a++) {
var b = L.Google.asyncWait[a];
b._ready = !0, b._container && (b._initMapObject(), "enabled" == mapsmarkerjspro.google_adsense_status && b._initAdSense(), b._update())
}
L.Google.asyncWait = []
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment