/*
* nmt-mapserver.js
* poging wat van onze mapscripts te centraliseren en generaliseren
*/
nmt = window.nmt || {};
nmt.mapserver = nmt.mapserver || [];
/* queries mapserver for timestamp of latest tile-version
sets global RAND parameter added to tile-requests
optionally refreshes the viewport
*/
nmt.mapserver.check_tile_lastupdate = function() {
jQuery.ajax( {
dataType : 'json',
url : '/ref2016/ref2016-last-update.json',
data : 'v='+ Math.ceil(Date.now() / 10000),
success : function (json) {
nmt.mapserver.CURRENT_TILE_VERSION = nmt.mapserver.TILE_VERSION;
nmt.mapserver.TILE_VERSION = json.RAND;
if (nmt.mapserver.TILE_VERSION != nmt.mapserver.CURRENT_TILE_VERSION)
{
console.log('updating viewport');
nmt.mapserver.TILE_VERSION = nmt.mapserver.TILE_VERSION;
wmsSource.updateParams({
'LAYERS': actieveLaag,
'RAND': nmt.mapserver.TILE_VERSION
});
}
},
error: function() { console.log("error"); }
});
}
nmt.mapserver.create_buttons = function() {
nmt.mapserver.knoppen.forEach( function ( item ) {
Object.keys(item).forEach ( function(key) {
row = '';
if (! item[key].depends) {
row = '
';
classes = 'head knop';
} else {
classes = 'knop';
if (item[key].extra_class) {classes += ' '+item[key].extra_class;}
if (item[key].hidden) { classes += ' hidden';}
}
row += '
' +item[key].label+ '';
if (! item[key].depends) {
row += '
';
jQuery('#knoppenbord').append(row);
}
else {
jQuery('#'+item[key].depends+'_knop').append(row);
}
});
});
}
nmt.mapserver.map_response = function (json) {
clickResult = json;
console.log(clickResult);
data = json.Uitslagen;
kopMaken();
if (clickResult.Grootste != "") {
uitslagGrafiek(data);
var grafiek = document.createElement('div');
} else {
console.log(clickResult.Grootste);
}
};
nmt.mapserver.layout_buttons = function() {
console.log('adding layout');
jQuery(".hidden").css("display","none");
jQuery(".init").css("display","inline-block");
jQuery(".head").click(function() {
jQuery(".row").children("a").css("background", "#646363");
jQuery(".hidden").css("display","none");
jQuery(this).parent(".row").children("a").css("background", "#646363");
jQuery(this).parent(".row").children(".hidden").css("display", "inline-block");
});
jQuery(".knop").hover(function() {
jQuery(this).css("background", "#D30910");
},function(){
jQuery(".row").children("a").css("background", "#646363");
});
}
nmt.mapserver.layout_grafiekkop = function() {
jQuery('#knopToelichting').hide();
jQuery('#knopTabelBladerMin').hide();
jQuery('#knopTabelBladerPlus').hide();
}
jQuery(document).ready( function() {
nmt.mapserver.create_buttons();
nmt.mapserver.layout_buttons();
nmt.mapserver.layout_grafiekkop();
jQuery("#wissen").click(function(event){
event.preventDefault();
jQuery("#address").val("").focus();
});
});
// haal de timestamp van de laatste uitslag die we hebben ontvangen
nmt.mapserver.check_tile_lastupdate();
setInterval(nmt.mapserver.check_tile_lastupdate, 20000);