2018-11-25 22:21:12 +08:00
var map ;
var plotlayers = [ ] ;
2023-12-01 01:11:22 +08:00
var iconsList = { 'qso' : { 'color' : '#FF0000' , 'icon' : 'fas fa-dot-circle' } } ;
2018-11-25 22:21:12 +08:00
2023-12-01 01:11:22 +08:00
var stationIcon = L . divIcon ( { className : 'cspot_station' } ) ;
var qsoIcon = L . divIcon ( { className : 'cspot_qso' } ) ; //default (fas fa-dot-circle red)
var qsoconfirmIcon = L . divIcon ( { className : 'cspot_qsoconfirm' } ) ;
var redIconImg = L . icon ( { iconUrl : icon _dot _url , iconSize : [ 10 , 10 ] } ) ; // old //
2020-06-15 23:59:27 +08:00
2022-09-23 05:33:32 +08:00
var osmUrl = $ ( '#leafembed' ) . attr ( "tileUrl" ) ;
2023-12-13 14:10:10 +08:00
// function to initialise map (can called alone, without plot) //
2023-12-01 01:11:22 +08:00
function initmap ( ShowGrid = 'No' , MapTag = 'map' , options = { } ) {
2018-11-25 22:21:12 +08:00
// set up the map
2022-03-10 02:01:04 +08:00
map = new L . Map ( MapTag ) ;
2018-11-25 22:21:12 +08:00
// create the tile layer with correct attribution
var osmAttrib = 'Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors' ;
2023-08-18 16:40:09 +08:00
var osm = new L . TileLayer ( osmUrl , { minZoom : 1 , maxZoom : 12 , attribution : osmAttrib } ) ;
2018-11-25 22:21:12 +08:00
2022-02-04 22:09:51 +08:00
var printer = L . easyPrint ( {
tileLayer : osm ,
sizeModes : [ 'Current' ] ,
filename : 'myMap' ,
exportOnly : true ,
hideControlContainer : true
} ) . addTo ( map ) ;
2023-12-01 01:11:22 +08:00
// new synthaxe, use array by function argument //
if ( typeof options . q _lat !== "undefined" ) { _q _lat = options . q _lat ; } else { if ( typeof q _lat !== "undefined" ) { _q _lat = q _lat ; } else { _q _lat = 0 ; } }
if ( typeof options . q _lng !== "undefined" ) { _q _lng = options . q _lng ; } else { if ( typeof q _lng !== "undefined" ) { _q _lng = q _lng ; } else { _q _lng = 0 ; } }
if ( typeof options . q _zoom !== "undefined" ) { _q _zoom = options . q _zoom ; } else { if ( typeof q _zoom !== "undefined" ) { _q _zoom = q _zoom ; } else { _q _zoom = 1 ; } }
if ( typeof options . url _qso !== "undefined" ) { _url _qso = options . url _qso ; } else { if ( typeof qso _loc !== "undefined" ) { _url _qso = qso _loc ; } else { _url _qso = '' ; console . log ( '[ERROR] url with qso location not defined.' ) ; } }
options . map _id = '#' + MapTag ;
2018-11-25 22:21:12 +08:00
2023-12-01 01:11:22 +08:00
// start the map in center of word, it nothing is defined
map . setView ( new L . LatLng ( _q _lat , _q _lng ) , _q _zoom ) ;
map . addLayer ( osm ) ;
//map.on('moveend', onMapMove); // all data load directecty, without interest in recharging during a movement
var layerControl = new L . Control . Layers ( null , { 'Gridsquares' : maidenhead = L . maidenhead ( ) } ) . addTo ( map ) ;
if ( ShowGrid == "Yes" ) { maidenhead . addTo ( map ) ; }
2023-12-13 14:10:10 +08:00
if ( ( typeof options . initmap _only == "undefined" ) || ( options . initmap _only != true ) ) { initplot ( _url _qso , options ) ; }
}
// function to initialise plot on map - Don't forget the "map_id" arg on options, if call alone //
function initplot ( _url _qso , options = { } ) {
2023-12-01 17:13:11 +08:00
//console.log(_url_qso);
2023-12-01 01:11:22 +08:00
// get map custon infos //
2023-12-13 14:10:10 +08:00
if ( _url _qso != '' ) {
var _visitor = ( typeof visitor === "undefined" ) ? false : visitor ;
if ( _visitor ) {
askForPlots ( _url _qso , options ) ;
} else {
$ . ajax ( {
url : base _url + 'index.php/user_options/get_map_custom' , type : 'GET' , dataType : 'json' ,
error : function ( ) { askForPlots ( _url _qso , options ) ; console . log ( '[ERROR] ajax get_map_custom() function return error.' ) ; } ,
success : function ( json _mapinfo ) {
if ( typeof json _mapinfo . qso !== "undefined" ) { iconsList = json _mapinfo ; }
if ( json _mapinfo . gridsquare _show == "1" ) { maidenhead . addTo ( map ) ; }
askForPlots ( _url _qso , options ) ;
}
} ) ;
}
2023-12-01 17:13:11 +08:00
}
2018-11-25 22:21:12 +08:00
}
2023-12-01 01:11:22 +08:00
function askForPlots ( _url _qso , options = { } ) {
removeMarkers ( ) ;
2023-12-12 14:40:12 +08:00
if ( typeof options . dataPost !== "undefined" ) { _dataPost = options . dataPost ; } else { _dataPost = { } ; }
2023-12-01 01:11:22 +08:00
$ . ajax ( {
2023-12-12 14:40:12 +08:00
url : _url _qso , type : 'POST' , dataType : 'json' , data : _dataPost ,
2023-12-01 01:11:22 +08:00
error : function ( ) { console . log ( '[ERROR] ajax askForPlots() function return error.' ) ; } ,
success : function ( plotjson ) {
if ( ( typeof plotjson [ 'markers' ] !== "undefined" ) && ( plotjson [ 'markers' ] . length > 0 ) ) {
for ( i = 0 ; i < plotjson [ 'markers' ] . length ; i ++ ) { createPlots ( plotjson [ 'markers' ] [ i ] ) ; }
}
if ( ( typeof plotjson [ 'station' ] !== "undefined" ) && ( plotjson [ 'station' ] . icon != "0" ) ) {
createPlots ( plotjson [ 'station' ] ) ;
}
$ . each ( iconsList , function ( icon , data ) {
$ ( options . map _id + ' .cspot_' + icon ) . addClass ( data . icon ) . css ( "color" , data . color ) ;
} ) ;
}
} ) ;
2018-11-25 22:21:12 +08:00
}
2023-12-01 01:11:22 +08:00
function createPlots ( _plot ) {
var plotll = new L . LatLng ( _plot . lat , _plot . lng , true ) ;
if ( typeof _plot . icon === "undefined" ) { _plot . icon = 'qsoIcon' ; }
if ( ( typeof iconsList . qsoconfirm !== "undefined" ) && ( typeof iconsList . qsoconfirm . icon !== "undefined" ) && ( iconsList . qsoconfirm . icon != "0" ) && ( typeof _plot . confirmed !== "undefined" ) && ( _plot . confirmed == 'Y' ) ) { _plot . icon = 'qsoconfirmIcon' ; }
eval ( 'var plotmark = new L.Marker(plotll, {icon: ' + _plot . icon + ' })' ) ;
plotmark . data = _plot ;
map . addLayer ( plotmark ) ;
if ( ( typeof _plot . label !== "undefined" ) && ( typeof _plot . html !== "undefined" ) ) {
2024-06-11 18:57:02 +08:00
_plot . label = ( _plot . label != "" ) ? ( "<h3>" + _plot . flag + _plot . label + "</h3>" ) : "" ;
2023-12-01 01:11:22 +08:00
if ( ( _plot . label + _plot . html ) != "" ) { plotmark . bindPopup ( _plot . label + _plot . html ) ; }
2018-11-25 22:21:12 +08:00
}
2023-12-01 01:11:22 +08:00
plotlayers . push ( plotmark ) ;
2018-11-25 22:21:12 +08:00
}
function removeMarkers ( ) {
for ( i = 0 ; i < plotlayers . length ; i ++ ) {
map . removeLayer ( plotlayers [ i ] ) ;
}
plotlayers = [ ] ;
2023-12-01 01:11:22 +08:00
}