Skip to content
Extraits de code Groupes Projets
Valider d170596d rédigé par Gregor Aisch's avatar Gregor Aisch
Parcourir les fichiers

update

parent 6e372137
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Le fichier a été supprimé par une entrée .gitattributes, ou son encodage n'est pas pris en charge.
...@@ -10,6 +10,21 @@ UserCountryMap.run = function(config) { ...@@ -10,6 +10,21 @@ UserCountryMap.run = function(config) {
window.__userCountryMap = map; window.__userCountryMap = map;
/*
* updateState
*/
function updateState(id) {
$('#userCountryMapSelectCountry').val(id);
if (id.length == 3) {
renderCountryMap(id);
} else {
renderWorldMap(id);
}
}
/*
* updateMap is called by renderCountryMap() and renderWorldMap()
*/
function updateMap(svgUrl, callback) { function updateMap(svgUrl, callback) {
map.loadMap(config.svgBasePath + svgUrl, function() { map.loadMap(config.svgBasePath + svgUrl, function() {
var ratio, w, h; var ratio, w, h;
...@@ -123,12 +138,13 @@ UserCountryMap.run = function(config) { ...@@ -123,12 +138,13 @@ UserCountryMap.run = function(config) {
}}); }});
map.onLayerEvent('click', function(path) { map.onLayerEvent('click', function(path) {
var tgt;
if (UserCountryMap.lastSelected != 'world' || UserCountryMap.countriesByIso[path.iso] === undefined) { if (UserCountryMap.lastSelected != 'world' || UserCountryMap.countriesByIso[path.iso] === undefined) {
renderCountryMap(path.iso); tgt = path.iso;
} else { } else {
// zoom to continent first tgt = UserCountryMap.ISO3toCONT[path.iso];
renderWorldMap(UserCountryMap.ISO3toCONT[path.iso]);
} }
updateState(tgt);
}, 'countries'); }, 'countries');
// add tooltips // add tooltips
...@@ -145,12 +161,13 @@ UserCountryMap.run = function(config) { ...@@ -145,12 +161,13 @@ UserCountryMap.run = function(config) {
}); });
} }
// now load the metrics for all countries
$.getJSON(config.countryDataUrl, function(report) { $.getJSON(config.countryDataUrl, function(report) {
var metrics = $('#userCountryMapSelectMetrics option'); var metrics = $('#userCountryMapSelectMetrics option');
var countryData = [], countrySelect = $('#userCountryMapSelectCountry'), var countryData = [], countrySelect = $('#userCountryMapSelectCountry'),
countriesByIso = {}; countriesByIso = {};
// read api result to countryData and countriesByISo
$.each(report.reportData, function(i, data) { $.each(report.reportData, function(i, data) {
var meta = report.reportMetadata[i], var meta = report.reportMetadata[i],
country = { country = {
...@@ -165,53 +182,40 @@ UserCountryMap.run = function(config) { ...@@ -165,53 +182,40 @@ UserCountryMap.run = function(config) {
countryData.push(country); countryData.push(country);
countriesByIso[country.iso] = country; countriesByIso[country.iso] = country;
}); });
// sort countries by name
countryData.sort(function(a,b) { return a.name > b.name ? 1 : -1; }); countryData.sort(function(a,b) { return a.name > b.name ? 1 : -1; });
function update(target) { // store country data globally
if (t.length == 3) {
renderCountryMap(target);
} else {
renderWorldMap(ttarget);
}
}
UserCountryMap.countryData = countryData; UserCountryMap.countryData = countryData;
UserCountryMap.countriesByIso = countriesByIso; UserCountryMap.countriesByIso = countriesByIso;
map.loadStyles(config.mapCssPath, function() { map.loadStyles(config.mapCssPath, function() {
// map stylesheets are loaded
// hide loading indicator
$('#UserCountryMap_content .loadingPiwik').hide(); $('#UserCountryMap_content .loadingPiwik').hide();
renderWorldMap('world');
function updateState(id) { // start with default view (or saved state??)
$('#userCountryMapSelectCountry').val(id); renderWorldMap('world');
if (id.length == 3) {
renderCountryMap(id);
} else {
renderWorldMap(id);
}
}
// populate country select // populate country select
$.each(countryData, function(i, country) { $.each(countryData, function(i, country) {
countrySelect.append('<option value="'+country.iso+'">'+country.name+'</option>'); countrySelect.append('<option value="'+country.iso+'">'+country.name+'</option>');
}); });
// react to changes of country select
countrySelect.change(function() { countrySelect.change(function() {
updateState(countrySelect.val()); updateState(countrySelect.val());
}); });
// enable zoom-out // enable zoom-out
$('#UserCountryMap-btn-zoom').click(function() { $('#UserCountryMap-btn-zoom').click(function() {
var t = UserCountryMap.lastSelected; var t = UserCountryMap.lastSelected,
if (t.length == 2) renderWorldMap('world'); tgt = 'world'; // zoom out to world per default..
else if (t.length == 3) { if (t.length == 3 && UserCountryMap.ISO3toCONT[t] !== undefined) {
if (UserCountryMap.ISO3toCONT[t] !== undefined) { tgt = UserCountryMap.ISO3toCONT[t]; // ..but zoom to continent if we know it
renderWorldMap(UserCountryMap.ISO3toCONT[t]);
} else {
renderWorldMap('world');
}
} }
updateState(tgt);
}); });
// enable mertic changes // enable mertic changes
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<div class="tableIconsGroup"> <div class="tableIconsGroup">
<span class="tableAllColumnsSwitch"> <span class="tableAllColumnsSwitch">
<a id="UserCountryMap-btn-zoom" format="table" class="tableIcon activeIcon"><img src="{$piwikUrl}plugins/UserCountryMap/img/zoom-out.png" title="Zoom to world"></a> <a id="UserCountryMap-btn-zoom" format="table" class="tableIcon"><img src="" data-src-disabled="{$piwikUrl}plugins/UserCountryMap/img/zoom-out-disabled.png" data-src-enabled="{$piwikUrl}plugins/UserCountryMap/img/zoom-out.png" title="Zoom to world"></a>
</span> </span>
</div> </div>
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter