836 |
jpm |
1 |
/*+--------------------------------------------------------------------------------------------------------+*/
|
|
|
2 |
// PARAMÊTRES et CONSTANTES
|
|
|
3 |
var pointImageUrl = 'http://chart.apis.google.com/chart?cht=mm&chs=24x32&chco=FFFFFF,008CFF,000000&ext=.png';
|
|
|
4 |
var pointsOrigine = null;
|
|
|
5 |
var boundsOrigine = null;
|
|
|
6 |
var markerClusterer = null;
|
|
|
7 |
var map = null;
|
|
|
8 |
var infoBulle = new google.maps.InfoWindow();
|
|
|
9 |
var pointClique = null;
|
|
|
10 |
var carteCentre = new google.maps.LatLng(46.4, 3.10);
|
|
|
11 |
var carteOptions = {
|
|
|
12 |
zoom: 6,
|
|
|
13 |
mapTypeId: google.maps.MapTypeId.ROADMAP,
|
|
|
14 |
mapTypeControlOptions: {
|
|
|
15 |
mapTypeIds: ['OSM',
|
|
|
16 |
google.maps.MapTypeId.ROADMAP,
|
|
|
17 |
google.maps.MapTypeId.HYBRID,
|
|
|
18 |
google.maps.MapTypeId.SATELLITE,
|
|
|
19 |
google.maps.MapTypeId.TERRAIN]
|
|
|
20 |
}
|
|
|
21 |
};
|
|
|
22 |
var ctaLayer = null;
|
|
|
23 |
var osmMapType = new google.maps.ImageMapType({
|
|
|
24 |
getTileUrl: function(coord, zoom) {
|
|
|
25 |
return "http://tile.openstreetmap.org/" +
|
|
|
26 |
zoom + "/" + coord.x + "/" + coord.y + ".png";
|
|
|
27 |
},
|
|
|
28 |
tileSize: new google.maps.Size(256, 256),
|
|
|
29 |
isPng: true,
|
|
|
30 |
alt: "OpenStreetMap",
|
|
|
31 |
name: "OSM",
|
|
|
32 |
maxZoom: 19
|
|
|
33 |
});
|
|
|
34 |
|
|
|
35 |
/*+--------------------------------------------------------------------------------------------------------+*/
|
|
|
36 |
// INITIALISATION DU CODE
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
//Déclenchement d'actions quand JQuery et le document HTML sont OK
|
|
|
40 |
$(document).ready(function() {
|
|
|
41 |
initialiserWidget();
|
|
|
42 |
});
|
|
|
43 |
/*+--------------------------------------------------------------------------------------------------------+*/
|
|
|
44 |
// FONCTIONS
|
|
|
45 |
|
|
|
46 |
function initialiserWidget() {
|
|
|
47 |
afficherStats();
|
|
|
48 |
initialiserAffichageCarte();
|
|
|
49 |
initialiserAffichagePanneauLateral();
|
|
|
50 |
|
|
|
51 |
initialiserCarte();
|
|
|
52 |
initialiserInfoBulle();
|
|
|
53 |
chargerLimitesCommunales();
|
|
|
54 |
rafraichirCarte();
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
function afficherStats() {
|
|
|
58 |
// Ajout du nombre de communes où des observations ont eu lieu
|
|
|
59 |
$('#commune-nbre').append(obs.stats.communes.formaterNombre());
|
|
|
60 |
// Ajout du nombre d'observations
|
|
|
61 |
$('#obs-nbre').append(obs.stats.observations.formaterNombre());
|
|
|
62 |
// Ajout du nombre de plantes
|
|
|
63 |
$('.plantes-nbre').append(plantesNbre.formaterNombre());
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
function initialiserAffichageCarte() {
|
|
|
67 |
$('#carte').height($(window).height() - 35);
|
|
|
68 |
$('#carte').width($(window).width() - 24);
|
|
|
69 |
|
|
|
70 |
if (nt != '*') {
|
|
|
71 |
$('#carte').css('left', 0);
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
function initialiserAffichagePanneauLateral() {
|
|
|
76 |
$('#panneau-lateral').height($(window).height() - 35);
|
|
|
77 |
|
|
|
78 |
if (nt == '*') {
|
|
|
79 |
$('#pl-ouverture').bind('click', afficher);
|
|
|
80 |
$('#pl-fermeture').bind('click', cacher);
|
|
|
81 |
$('.taxon').live('click', filtrerParTaxon);
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
function initialiserCarte() {
|
|
|
86 |
map = new google.maps.Map(document.getElementById('carte'), carteOptions);
|
|
|
87 |
// Ajout de la couche OSM à la carte
|
|
|
88 |
map.mapTypes.set('OSM', osmMapType);
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
function initialiserInfoBulle() {
|
|
|
92 |
google.maps.event.addListener(infoBulle, 'domready', modifierContenuInfoBulle);
|
|
|
93 |
google.maps.event.addListener(infoBulle, 'closeclick', deplacerCartePointClique);
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
function chargerLimitesCommunales() {
|
|
|
97 |
if (urlsLimitesCommunales != null) {
|
|
|
98 |
for (urlId in urlsLimitesCommunales) {
|
|
|
99 |
var url = urlsLimitesCommunales[urlId];
|
|
|
100 |
ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
|
|
|
101 |
ctaLayer.setMap(map);
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
function rafraichirCarte() {
|
|
|
107 |
var points = [];
|
|
|
108 |
var bounds = new google.maps.LatLngBounds();
|
|
|
109 |
for (var i = 0; i < obs.stats.communes; ++i) {
|
|
|
110 |
var maLatLng = new google.maps.LatLng(obs.points[i].coord_x, obs.points[i].coord_y);
|
|
|
111 |
var pointImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(24, 32));
|
|
|
112 |
var point = new google.maps.Marker({
|
|
|
113 |
position: maLatLng,
|
|
|
114 |
map: map,
|
|
|
115 |
icon: pointImage,
|
|
|
116 |
stationId: obs.points[i].id
|
|
|
117 |
});
|
|
|
118 |
|
|
|
119 |
bounds.extend(maLatLng);
|
|
|
120 |
|
|
|
121 |
google.maps.event.addListener(point, 'click', function() {
|
|
|
122 |
pointClique = this;
|
|
|
123 |
|
|
|
124 |
infoBulle.open(map, this);
|
|
|
125 |
|
|
|
126 |
var limites = map.getBounds();
|
|
|
127 |
var centre = limites.getCenter();
|
|
|
128 |
var nordEst = limites.getNorthEast();
|
|
|
129 |
var centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
|
|
|
130 |
map.panTo(centreSudLatLng);
|
|
|
131 |
|
|
|
132 |
afficherMsgChargement();
|
|
|
133 |
chargerFormatObs(this.stationId, '*');
|
|
|
134 |
});
|
|
|
135 |
|
|
|
136 |
points.push(point);
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
if (pointsOrigine == null && boundsOrigine == null) {
|
|
|
140 |
pointsOrigine = points;
|
|
|
141 |
boundsOrigine = bounds;
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
executerMarkerClusterer(points, bounds);
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
function modifierContenuInfoBulle() {
|
|
|
148 |
// Onglet Tableau : Jquery => TableSorter
|
|
|
149 |
if ($("#observations table").get() != '') {
|
|
|
150 |
ajouterTableauTriable("#observations table");
|
|
|
151 |
}
|
|
|
152 |
// Onglet Liste : Jquery => FancyBox
|
|
|
153 |
if ($("#observations ol").get() != '') {
|
|
|
154 |
ajouterGaleriePhoto("a.cel-img");
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
function ajouterTableauTriable(element) {
|
|
|
159 |
// add parser through the tablesorter addParser method
|
|
|
160 |
$.tablesorter.addParser({
|
|
|
161 |
// Définition d'un id unique pour ce parsseur
|
|
|
162 |
id: 'date_cel',
|
|
|
163 |
is: function(s) {
|
|
|
164 |
// retourne false si le parsseur n'est pas autodétecté
|
|
|
165 |
return false;
|
|
|
166 |
},
|
|
|
167 |
format: function(s) {
|
|
|
168 |
// Transformation date jj/mm/aaaa en aaaa/mm/jj
|
|
|
169 |
s = s.replace(/(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})/, "$3/$2/$1");
|
|
|
170 |
// Remplace la date par un nombre de millisecondes pour trier numériquement
|
|
|
171 |
return $.tablesorter.formatFloat(new Date(s).getTime());
|
|
|
172 |
},
|
|
|
173 |
// set type, either numeric or text
|
|
|
174 |
type: 'numeric'
|
|
|
175 |
});
|
|
|
176 |
$(element).tablesorter({
|
|
|
177 |
headers: {
|
|
|
178 |
1: {
|
|
|
179 |
sorter:'date_cel'
|
|
|
180 |
}
|
|
|
181 |
}
|
|
|
182 |
});
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
function ajouterGaleriePhoto(element) {
|
|
|
186 |
$(element).fancybox({
|
|
|
187 |
transitionIn : 'elastic',
|
|
|
188 |
transitionOut : 'elastic',
|
|
|
189 |
speedIn : 600,
|
|
|
190 |
speedOut : 200,
|
|
|
191 |
overlayShow : true
|
|
|
192 |
}).live('click', function(e) {
|
|
|
193 |
if (e.stopPropagation) {
|
|
|
194 |
e.stopPropagation();
|
|
|
195 |
}
|
|
|
196 |
return false;
|
|
|
197 |
});
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
function deplacerCartePointClique() {
|
|
|
201 |
map.panTo(pointClique.position);
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
function executerMarkerClusterer(points, bounds) {
|
|
|
205 |
if (markerClusterer) {
|
|
|
206 |
markerClusterer.clearMarkers();
|
|
|
207 |
}
|
|
|
208 |
markerClusterer = new MarkerClusterer(map, points);
|
|
|
209 |
map.fitBounds(bounds);
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
function afficherMsgChargement() {
|
|
|
213 |
var chargement = document.getElementById('chargement').cloneNode(true);
|
|
|
214 |
chargement.setAttribute('id', 'chargement-copie');
|
|
|
215 |
infoBulle.setContent(chargement);
|
|
|
216 |
}
|
|
|
217 |
|
841 |
jpm |
218 |
var pagineur = {'limite':150, 'obsTotal':0, 'stationId':null, 'format':null};
|
|
|
219 |
|
|
|
220 |
function handlePaginationClick(new_page_index, pagination_container) {
|
|
|
221 |
$('.obs-liste-conteneur').css('display', 'none');
|
|
|
222 |
$('#chargement').clone().attr('id', 'chargement-copie').appendTo('#observations').css('display', 'block');
|
|
|
223 |
console.log($('#chargement').get());
|
|
|
224 |
|
|
|
225 |
var start = new_page_index * pagineur.limite;
|
|
|
226 |
var url = urlObs+
|
|
|
227 |
'&format='+pagineur.format+
|
|
|
228 |
'&station='+pagineur.stationId+
|
|
|
229 |
'&start='+start+
|
|
|
230 |
'&limit='+pagineur.limite;
|
|
|
231 |
$.get(url, function(observations) {
|
|
|
232 |
$('#chargement-copie').remove();
|
|
|
233 |
$('.obs-liste-conteneur').css('display', 'block');
|
|
|
234 |
$('#obs-liste').empty();
|
|
|
235 |
$('#obs-liste').append(observations);
|
|
|
236 |
});
|
|
|
237 |
return false;
|
|
|
238 |
}
|
|
|
239 |
|
836 |
jpm |
240 |
function chargerFormatObs(stationId, format) {
|
841 |
jpm |
241 |
pagineur.obsTotal = parseInt($('#obs-total').text());
|
|
|
242 |
pagineur.stationId = stationId;
|
|
|
243 |
pagineur.format = format;
|
|
|
244 |
|
|
|
245 |
var start = 1 * pagineur.limite;
|
|
|
246 |
var url = urlStation+
|
|
|
247 |
'&format='+format+
|
|
|
248 |
'&station='+stationId+
|
|
|
249 |
'&start='+start+
|
|
|
250 |
'&limit='+pagineur.limite;
|
836 |
jpm |
251 |
$.get(url, function(observations){
|
|
|
252 |
infoBulle.setContent(observations);
|
841 |
jpm |
253 |
// First Parameter: number of items
|
|
|
254 |
// Second Parameter: options object
|
|
|
255 |
$("#pagination").pagination(pagineur.obsTotal, {
|
|
|
256 |
items_per_page:pagineur.limite,
|
|
|
257 |
callback:handlePaginationClick
|
|
|
258 |
});
|
836 |
jpm |
259 |
});
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
function arreter(event) {
|
|
|
263 |
if (event.stopPropagation) {
|
|
|
264 |
event.stopPropagation();
|
|
|
265 |
} else if (window.event) {
|
|
|
266 |
window.event.cancelBubble = true;
|
|
|
267 |
}
|
|
|
268 |
return false;
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
function afficher() {
|
|
|
272 |
$('#panneau-lateral').width(300);
|
|
|
273 |
$('#pl-contenu').css('display', 'block');
|
|
|
274 |
$('#pl-ouverture').css('display', 'none');
|
|
|
275 |
$('#pl-fermeture').css('display', 'block');
|
|
|
276 |
$('#carte').css('left', '300px');
|
|
|
277 |
|
|
|
278 |
google.maps.event.trigger(map, 'resize');
|
|
|
279 |
};
|
|
|
280 |
|
|
|
281 |
function cacher() {
|
|
|
282 |
$('#panneau-lateral').width(24);
|
|
|
283 |
$('#pl-contenu').css('display', 'none');
|
|
|
284 |
$('#pl-ouverture').css('display', 'block');
|
|
|
285 |
$('#pl-fermeture').css('display', 'none');
|
|
|
286 |
$('#carte').css('left', '24px');
|
|
|
287 |
|
|
|
288 |
google.maps.event.trigger(map, 'resize');
|
|
|
289 |
};
|
|
|
290 |
|
|
|
291 |
function ouvrirPopUp(url, nom) {
|
|
|
292 |
window.open(url, nom, 'scrollbars=yes,width=650,height=600,directories=no,location=no,menubar=no,status=no,toolbar=no');
|
|
|
293 |
};
|
|
|
294 |
|
|
|
295 |
function filtrerParTaxon() {
|
|
|
296 |
var ntAFiltrer = $('.nt', this).text();
|
|
|
297 |
infoBulle.close();
|
|
|
298 |
$('#taxon-'+nt).removeClass('taxon-actif');
|
|
|
299 |
if (nt == ntAFiltrer) {
|
|
|
300 |
nt = '*';
|
|
|
301 |
executerMarkerClusterer(pointsOrigine, boundsOrigine);
|
|
|
302 |
} else {
|
|
|
303 |
var url = urlObsCarte+'&'+
|
|
|
304 |
'num_taxon='+ntAFiltrer+'&'+
|
|
|
305 |
'formatRetour=jsonp'+'&'+
|
|
|
306 |
'callback=?';
|
|
|
307 |
$.getJSON(url, function (observations) {
|
|
|
308 |
obs = observations;
|
|
|
309 |
nt = ntAFiltrer;
|
|
|
310 |
$('#taxon-'+nt).addClass('taxon-actif');
|
|
|
311 |
rafraichirCarte();
|
|
|
312 |
});
|
|
|
313 |
}
|
|
|
314 |
};
|
|
|
315 |
|
|
|
316 |
/**
|
|
|
317 |
* +-------------------------------------+
|
|
|
318 |
* Number.prototype.formaterNombre
|
|
|
319 |
* +-------------------------------------+
|
|
|
320 |
* Params (facultatifs):
|
|
|
321 |
* - Int decimales: nombre de decimales (exemple: 2)
|
|
|
322 |
* - String signe: le signe precedent les decimales (exemple: "," ou ".")
|
|
|
323 |
* - String separateurMilliers: comme son nom l'indique
|
|
|
324 |
* Returns:
|
|
|
325 |
* - String chaine formatee
|
|
|
326 |
* @author ::mastahbenus::
|
|
|
327 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
|
|
|
328 |
* @souce http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
|
|
|
329 |
*/
|
|
|
330 |
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
|
|
|
331 |
var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
|
|
|
332 |
|
|
|
333 |
function is_int(nbre) {
|
|
|
334 |
nbre = nbre.replace(',', '.');
|
|
|
335 |
return !(parseFloat(nbre)-parseInt(nbre) > 0);
|
|
|
336 |
}
|
|
|
337 |
|
|
|
338 |
if (decimales == undefined) {
|
|
|
339 |
if (is_int(_sNombre)) {
|
|
|
340 |
decimales = 0;
|
|
|
341 |
} else {
|
|
|
342 |
decimales = 2;
|
|
|
343 |
}
|
|
|
344 |
}
|
|
|
345 |
if (signe == undefined) {
|
|
|
346 |
if (is_int(_sNombre)) {
|
|
|
347 |
signe = '';
|
|
|
348 |
} else {
|
|
|
349 |
signe = '.';
|
|
|
350 |
}
|
|
|
351 |
}
|
|
|
352 |
if (separateurMilliers == undefined) {
|
|
|
353 |
separateurMilliers = ' ';
|
|
|
354 |
}
|
|
|
355 |
|
|
|
356 |
function separeMilliers (sNombre) {
|
|
|
357 |
var sRetour = "";
|
|
|
358 |
while (sNombre.length % 3 != 0) {
|
|
|
359 |
sNombre = "0"+sNombre;
|
|
|
360 |
}
|
|
|
361 |
for (i = 0; i < sNombre.length; i += 3) {
|
|
|
362 |
if (i == sNombre.length-1) separateurMilliers = '';
|
|
|
363 |
sRetour += sNombre.substr(i, 3) + separateurMilliers;
|
|
|
364 |
}
|
|
|
365 |
while (sRetour.substr(0, 1) == "0") {
|
|
|
366 |
sRetour = sRetour.substr(1);
|
|
|
367 |
}
|
|
|
368 |
return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
|
|
|
369 |
}
|
|
|
370 |
|
|
|
371 |
if (_sNombre.indexOf('.') == -1) {
|
|
|
372 |
for (i = 0; i < decimales; i++) {
|
|
|
373 |
_sDecimales += "0";
|
|
|
374 |
}
|
|
|
375 |
_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
|
|
|
376 |
} else {
|
|
|
377 |
var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
|
|
|
378 |
if (sDecimalesTmp.length > decimales) {
|
|
|
379 |
var nDecimalesManquantes = sDecimalesTmp.length - decimales;
|
|
|
380 |
var nDiv = 1;
|
|
|
381 |
for (i = 0; i < nDecimalesManquantes; i++) {
|
|
|
382 |
nDiv *= 10;
|
|
|
383 |
}
|
|
|
384 |
_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
|
|
|
385 |
}
|
|
|
386 |
_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
|
|
|
387 |
}
|
|
|
388 |
return _sRetour;
|
|
|
389 |
}
|