Store maps (layers) settings in DB + display only project-relevant layers

This commit is contained in:
2020-08-18 23:12:40 +02:00
parent 4c4f83b6a2
commit b0b283cf0f
4 changed files with 80 additions and 18 deletions

View File

@@ -0,0 +1,38 @@
CREATE TABLE `maps` (
`id_map` int(10) UNSIGNED auto_increment,
`codename` VARCHAR(100),
`geo_name` VARCHAR(100),
`min_zoom` TINYINT UNSIGNED,
`max_zoom` TINYINT UNSIGNED,
`attribution` VARCHAR(100),
`led` TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id_map`));
CREATE TABLE `mappings` (
`id_mapping` int(10) UNSIGNED auto_increment,
`id_map` int(10) UNSIGNED,
`id_project` int(10) UNSIGNED,
`led` TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id_mapping`));
ALTER TABLE mappings ADD INDEX(`id_map`);
ALTER TABLE mappings ADD FOREIGN KEY (`id_map`) REFERENCES maps(`id_map`);
ALTER TABLE mappings ADD INDEX(`id_project`);
ALTER TABLE mappings ADD FOREIGN KEY (`id_project`) REFERENCES projects(`id_project`);
INSERT INTO maps(codename, geo_name, min_zoom, max_zoom, attribution) VALUES
/*1*/('satellite', 'mapbox.satellite-streets', 0, 19, ''),
/*2*/('otm', 'opentopomap', 2, 19, ''),
/*3*/('ign_france', 'ign.fr', 2, 19, ''),
/*4*/('ign_spain', 'ign.es', 1, 20, ''),
/*5*/('linz', 'linz', 0, 17, 'Sourced from LINZ. CC BY 4.0'),
/*6*/('usgs', 'usgs', 1, 16, ''),
/*7*/('natgeo', 'natgeo.pct', 5, 14, '');
INSERT INTO mappings(id_map, id_project) VALUES
(1, NULL),
(2, NULL),
(3, 2),
(4, 2),
(5, 1),
(6, 3);

View File

@@ -168,6 +168,16 @@ class Project extends PhpObject {
return $iLastUpdate;
}
public function getMaps() {
$sQuery =
"SELECT codename, geo_name, min_zoom, max_zoom, attribution ".
"FROM ".Spot::MAPPING_TABLE." ".
"LEFT JOIN ".Spot::MAP_TABLE." USING(".Db::getId(Spot::MAP_TABLE).") ".
"WHERE ".Db::getId(self::PROJ_TABLE)." = ".$this->getProjectId()." ".
"OR ".Db::getId(self::PROJ_TABLE)." IS NULL ";
return $this->oDb->getArrayQuery($sQuery, true);
}
private function setProjectInfo() {
if($this->getProjectId() > 0) {
$asProject = $this->getProject();

View File

@@ -18,6 +18,8 @@ class Spot extends Main
{
//Database
const POST_TABLE = 'posts';
const MAP_TABLE = 'maps';
const MAPPING_TABLE = 'mappings';
const FEED_CHUNK_SIZE = 15;
const MAIL_CHUNK_SIZE = 5;
@@ -81,7 +83,9 @@ class Spot extends Main
Project::PROJ_TABLE => array('name', 'codename', 'active_from', 'active_to', 'timezone'),
self::POST_TABLE => array(Db::getId(Project::PROJ_TABLE), Db::getId(User::USER_TABLE), 'name', 'content', 'site_time'),
Media::MEDIA_TABLE => array(Db::getId(Project::PROJ_TABLE), 'filename', 'type', 'taken_on', 'posted_on', 'rotate', 'comment'),
User::USER_TABLE => array('name', 'email', 'language', 'timezone', 'active')
User::USER_TABLE => array('name', 'email', 'language', 'timezone', 'active'),
self::MAP_TABLE => array('codename', 'geo_name', 'min_zoom', 'max_zoom', 'attribution'),
self::MAPPING_TABLE => array(Db::getId(self::MAP_TABLE) , Db::getId(Project::PROJ_TABLE))
),
'types' => array
(
@@ -112,7 +116,11 @@ class Spot extends Main
'taken_on' => "TIMESTAMP DEFAULT 0",
'timezone' => "CHAR(64)", //see mysql.time_zone_name
'type' => "VARCHAR(20)",
'unix_time' => "INT"
'unix_time' => "INT",
'geo_name' => "VARCHAR(100)",
'min_zoom' => "TINYINT UNSIGNED",
'max_zoom' => "TINYINT UNSIGNED",
'attribution' => "VARCHAR(100)"
),
'constraints' => array
(
@@ -255,7 +263,10 @@ class Spot extends Main
$asLastUpdate = array();
$this->addTimeStamp($asLastUpdate, $this->oProject->getLastUpdate());
return self::getJsonResult($bSuccess, $sDesc, array('messages' => $asMessages, 'last_update'=>$asLastUpdate));
return self::getJsonResult($bSuccess, $sDesc, array(
'messages' => $asMessages,
'maps' => $this->oProject->getMaps(),
'last_update' => $asLastUpdate));
}
public function subscribe($sEmail) {

View File

@@ -228,8 +228,10 @@ function initProject(sProjectCodeName, oFocusPost){
mimeType: 'application/json'
})
).done(function(aoMessages, aoTracks) {
initSpotMessages(aoMessages[0]['data']['messages'] || [], aoTracks[0], aoMessages[0]['desc']=='No Data');
updateSettingsPanel(aoMessages[0]['data']['last_update']);
var asData = aoMessages[0]['data'];
setMapLayers(asData['maps']);
initSpotMessages(asData['messages'] || [], aoTracks[0], aoMessages[0]['desc']=='No Data');
updateSettingsPanel(asData['last_update']);
});
//Show/Hide Poster Panel
@@ -353,21 +355,22 @@ function getElevWidth() {
return iPageWidth - iFeedPanelWidth - iSettingsPanelWidth - iLegendWidth - oElevRightMarging;
}
function setMapLayers(asLayers) {
oSpot.tmp('layers', {});
$.each(asLayers, function(iKey, asLayer) {
oSpot.tmp('layers')[oSpot.lang('map_'+asLayer.codename)] = L.tileLayer(self.tmp('tile_api'), {
id: asLayer.geo_name,
minZoom: parseInt(asLayer.min_zoom),
maxZoom: parseInt(asLayer.max_zoom),
attribution: asLayer.attribution
});
});
}
function initSpotMessages(aoMessages, aoTracks, bNoFeed) {
//Tile layers
aoLayers = {};
aoLayers[oSpot.lang('map_satellite')] = L.tileLayer(self.tmp('tile_api'), {id: 'mapbox.satellite-streets', minZoom: 0, maxZoom: 19});
aoLayers[oSpot.lang('map_otm')] = L.tileLayer(self.tmp('tile_api'), {id: 'opentopomap', minZoom: 2, maxZoom: 19});
aoLayers[oSpot.lang('map_ign_france')] = L.tileLayer(self.tmp('tile_api'), {id: 'ign.fr', minZoom: 0, maxZoom: 18, tileSize: 256});
aoLayers[oSpot.lang('map_ign_spain')] = L.tileLayer(self.tmp('tile_api'), {id: 'ign.es', minZoom: 1, maxZoom: 20});
aoLayers[oSpot.lang('map_linz')] = L.tileLayer(self.tmp('tile_api'), {id: 'linz', maxZoom: 17, continuousWorld: true, attribution: 'Sourced from LINZ. CC BY 4.0'});
aoLayers[oSpot.lang('map_usgs')] = L.tileLayer(self.tmp('tile_api'), {id: 'usgs', minZoom: 1, maxZoom: 16});
//aoLayers[oSpot.lang('map_natgeo')] = L.tileLayer(self.tmp('tile_api'), {id: 'natgeo.pct', minZoom: 5, maxZoom: 14});
//Map
var oMap = L.map(self.tmp('$Map')[0], {
layers: [aoLayers[oSpot.lang('map_satellite')]],
layers: [oSpot.tmp('layers')[oSpot.lang('map_satellite')]],
attributionControl: false,
zoomControl: false
});
@@ -465,7 +468,7 @@ function initSpotMessages(aoMessages, aoTracks, bNoFeed) {
}
//Controls: Tiles (layers): Add & Move to Settings Panel
L.control.layers(aoLayers, null, {position: 'topleft'}).addTo(oMap);
L.control.layers(oSpot.tmp('layers'), null, {position: 'topleft'}).addTo(oMap);
$('#layers').empty().append($('.leaflet-control-layers-list .leaflet-control-layers-base'));
//Actual Tracks: Track with corresponding colors