[QRB Calc] Some fixed to get this working, since map is not global.

这个提交包含在:
Andreas 2022-02-15 20:29:25 +01:00
父节点 c27bc1243a
当前提交 831708ffc2

查看文件

@ -21,9 +21,9 @@ L.MaidenheadQrb = L.LayerGroup.extend({
onAdd: function (map) { onAdd: function (map) {
this._map = map; this._map = map;
var grid = this.redraw(); var grid = this.redraw(map);
this._map.on('viewreset '+ this.options.redraw, function () { this._map.on('viewreset '+ this.options.redraw, function () {
grid.redraw(); grid.redraw(map);
}); });
this.eachLayer(map.addLayer, map); this.eachLayer(map.addLayer, map);
@ -35,7 +35,7 @@ L.MaidenheadQrb = L.LayerGroup.extend({
this.eachLayer(this.removeLayer, this); this.eachLayer(this.removeLayer, this);
}, },
redraw: function () { redraw: function (map) {
var d3 = new Array(20, 10, 10, 1, 1, 1, 1, 1, 1, 1, 1 / 24, 1 / 24, 1 / 24, 1 / 24, 1 / 24, 1 / 240, 1 / 240, 1 / 240, 1 / 240, 1 / 240 / 24, 1 / 240 / 24); var d3 = new Array(20, 10, 10, 1, 1, 1, 1, 1, 1, 1, 1 / 24, 1 / 24, 1 / 24, 1 / 24, 1 / 24, 1 / 240, 1 / 240, 1 / 240, 1 / 240, 1 / 240 / 24, 1 / 240 / 24);
var lat_cor = new Array(0, 8, 8, 8, 8, 1.7, 6, 8, 8, 8, 1.4, 2.5, 3, 3.5, 4, 4, 3.5, 3.5, 3, 1.8, 1.6); var lat_cor = new Array(0, 8, 8, 8, 8, 1.7, 6, 8, 8, 8, 1.4, 2.5, 3, 3.5, 4, 4, 3.5, 3.5, 3, 1.8, 1.6);
var bounds = map.getBounds(); var bounds = map.getBounds();
@ -60,7 +60,7 @@ L.MaidenheadQrb = L.LayerGroup.extend({
var bounds = [[lat,lon],[lat+unit,lon+(unit*2)]]; var bounds = [[lat,lon],[lat+unit,lon+(unit*2)]];
if (zoom < 2 || zoom > 4) { if (zoom < 2 || zoom > 4) {
this.addLayer(this._getLabel(lon+unit-(unit/lcor),lat+(unit/2)+(unit/lcor*c))); this.addLayer(this._getLabel(lon+unit-(unit/lcor),lat+(unit/2)+(unit/lcor*c), map));
} }
if (zoom < 3 ) { if (zoom < 3 ) {
this.addLayer(L.rectangle(bounds, {className: 'grid-rectangle', color: this.options.color, weight: 1, fill:false, interactive: false})); this.addLayer(L.rectangle(bounds, {className: 'grid-rectangle', color: this.options.color, weight: 1, fill:false, interactive: false}));
@ -70,7 +70,7 @@ L.MaidenheadQrb = L.LayerGroup.extend({
} }
if (zoom < 3 || zoom > 5) { if (zoom < 3 || zoom > 5) {
this.addLayer(this._getLabel(lon+unit-(unit/lcor),lat+(unit/2)+(unit/lcor*c))); this.addLayer(this._getLabel(lon+unit-(unit/lcor),lat+(unit/2)+(unit/lcor*c), map));
} }
} }
@ -93,24 +93,24 @@ L.MaidenheadQrb = L.LayerGroup.extend({
fill: false, fill: false,
interactive: false interactive: false
})); }));
this.addLayer(this._getLabel2(lon + unit - (unit / lcor), lat + (unit / 2) + (unit / lcor * c))); this.addLayer(this._getLabel2(lon + unit - (unit / lcor), lat + (unit / 2) + (unit / lcor * c), map));
} }
} }
} }
return this; return this;
}, },
_getLabel: function(lon,lat) { _getLabel: function(lon,lat, map) {
var title_size = new Array(0, 10, 14, 16, 6, 13, 14, 16, 24, 36, 12, 14, 20, 36, 60, 12, 20, 36, 60, 12, 24); var title_size = new Array(0, 10, 14, 16, 6, 13, 14, 16, 24, 36, 12, 14, 20, 36, 60, 12, 20, 36, 60, 12, 24);
var zoom = map.getZoom(); var zoom = map.getZoom();
var size = title_size[zoom]+'px'; var size = title_size[zoom]+'px';
var title = '<span class="grid-text" style="cursor: default;"><font style="color:'+this.options.color+'; font-size:'+size+'; font-weight: 900; ">' + this._getLocator(lon,lat) + '</font></span>'; var title = '<span class="grid-text" style="cursor: default;"><font style="color:'+this.options.color+'; font-size:'+size+'; font-weight: 900; ">' + this._getLocator(lon,lat, map) + '</font></span>';
var myIcon = L.divIcon({className: 'my-div-icon', html: title}); var myIcon = L.divIcon({className: 'my-div-icon', html: title});
var marker = L.marker([lat,lon], {icon: myIcon}, clickable=false); var marker = L.marker([lat,lon], {icon: myIcon}, clickable=false);
return marker; return marker;
}, },
_getLocator: function(lon,lat) { _getLocator: function(lon,lat, map) {
var ydiv_arr=new Array(10, 1, 1/24, 1/240, 1/240/24); var ydiv_arr=new Array(10, 1, 1/24, 1/240, 1/240/24);
var d1 = "ABCDEFGHIJKLMNOPQR".split(""); var d1 = "ABCDEFGHIJKLMNOPQR".split("");
var d2 = "ABCDEFGHIJKLMNOPQRSTUVWX".split(""); var d2 = "ABCDEFGHIJKLMNOPQRSTUVWX".split("");
@ -141,11 +141,11 @@ L.MaidenheadQrb = L.LayerGroup.extend({
/* /*
Need this for the field printing, while showing worked/confirmed grids Need this for the field printing, while showing worked/confirmed grids
*/ */
_getLabel2: function(lon,lat) { _getLabel2: function(lon,lat, map) {
var title_size = new Array(0, 10, 12, 16, 20, 26, 26, 16, 24, 36, 12, 14, 20, 36, 60, 12, 20, 36, 60, 12, 24); var title_size = new Array(0, 10, 12, 16, 20, 26, 26, 16, 24, 36, 12, 14, 20, 36, 60, 12, 20, 36, 60, 12, 24);
var zoom = map.getZoom(); var zoom = map.getZoom();
var size = title_size[zoom]+'px'; var size = title_size[zoom]+'px';
var title = '<span class="grid-text" style="cursor: default;"><font style="color:'+this.options.color+'; font-size:'+size+'; font-weight: 900; ">' + this._getLocator2(lon,lat) + '</font></span>'; var title = '<span class="grid-text" style="cursor: default;"><font style="color:'+this.options.color+'; font-size:'+size+'; font-weight: 900; ">' + this._getLocator2(lon,lat, map) + '</font></span>';
var myIcon = L.divIcon({className: 'my-div-icon', html: title}); var myIcon = L.divIcon({className: 'my-div-icon', html: title});
var marker = L.marker([lat,lon], {icon: myIcon}, clickable=false); var marker = L.marker([lat,lon], {icon: myIcon}, clickable=false);
return marker; return marker;
@ -154,7 +154,7 @@ L.MaidenheadQrb = L.LayerGroup.extend({
/* /*
Need this for the field printing, while showing worked/confirmed grids Need this for the field printing, while showing worked/confirmed grids
*/ */
_getLocator2: function(lon,lat) { _getLocator2: function(lon,lat, map) {
var ydiv_arr=new Array(10, 1, 1/24, 1/240, 1/240/24); var ydiv_arr=new Array(10, 1, 1/24, 1/240, 1/240/24);
var d1 = "ABCDEFGHIJKLMNOPQR".split(""); var d1 = "ABCDEFGHIJKLMNOPQR".split("");
var d2 = "ABCDEFGHIJKLMNOPQRSTUVWX".split(""); var d2 = "ABCDEFGHIJKLMNOPQRSTUVWX".split("");