Subversion Repositories Applications.bazar

Rev

Rev 484 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 484 Rev 485
1
<?php
1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */ 
3
// +------------------------------------------------------------------------------------------------------+
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
7
// +------------------------------------------------------------------------------------------------------+
8
// | This library is free software; you can redistribute it and/or                                        |
8
// | This library is free software; you can redistribute it and/or                                        |
9
// | modify it under the terms of the GNU Lesser General Public                                           |
9
// | modify it under the terms of the GNU Lesser General Public                                           |
10
// | License as published by the Free Software Foundation; either                                         |
10
// | License as published by the Free Software Foundation; either                                         |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
12
// |                                                                                                      |
12
// |                                                                                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
16
// | Lesser General Public License for more details.                                                      |
16
// | Lesser General Public License for more details.                                                      |
17
// |                                                                                                      |
17
// |                                                                                                      |
18
// | You should have received a copy of the GNU Lesser General Public                                     |
18
// | You should have received a copy of the GNU Lesser General Public                                     |
19
// | License along with this library; if not, write to the Free Software                                  |
19
// | License along with this library; if not, write to the Free Software                                  |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
21
// +------------------------------------------------------------------------------------------------------+
21
// +------------------------------------------------------------------------------------------------------+
22
// CVS : $Id: carte_google.php,v 1.1.2.1 2008-04-16 12:35:25 alexandre_tb Exp $
22
// CVS : $Id: carte_google.php,v 1.1.2.1 2008-04-16 12:35:25 alexandre_tb Exp $
23
/**
23
/**
24
* 
24
* 
25
*@package bazar
25
*@package bazar
26
//Auteur original :
26
//Auteur original :
27
*@author        Alexandre GRANIER <alexandre@tela-botanica.org>
27
*@author        Alexandre GRANIER <alexandre@tela-botanica.org>
28
//Autres auteurs :
28
//Autres auteurs :
29
*@copyright     Tela-Botanica 2000-2008
29
*@copyright     Tela-Botanica 2000-2008
30
*@version       $Revision: 1.1.2.1 $
30
*@version       $Revision: 1.1.2.1 $
31
// +------------------------------------------------------------------------------------------------------+
31
// +------------------------------------------------------------------------------------------------------+
32
*/
32
*/
33
 
33
 
34
include_once PAP_CHEMIN_API_PEAR.'PEAR.php';
34
include_once PAP_CHEMIN_API_PEAR.'PEAR.php';
35
 
35
 
36
 
36
 
37
class Bazar_carte_google extends PEAR {
37
class Bazar_carte_google extends PEAR {
38
	
38
	
39
	var $option = array();
39
	var $option = array();
40
	
40
	
41
	function Bazar_carte_google($options) {
41
	function Bazar_carte_google($options) {
42
		unset ($options['nom_bdd']); // fout la merde avec google maps v2
42
		unset ($options['nom_bdd']); // fout la merde avec google maps v2
43
		$this->options = $options;
43
		$this->options = $options;
44
	}
44
	}
45
	
45
	
46
	function toHTML($valeur) {
46
	function toHTML($valeur) {
47
		if ($GLOBALS['pas_de_carte']) return;
47
		if ($GLOBALS['pas_de_carte']) return;
48
		$html = '';
48
		$html = '';
49
		$val = $this->options['nom_bdd'];
49
		$val = $this->options['nom_bdd'];
50
    	$script = '
50
    	$script = '
51
    // Variables globales
51
    // Variables globales
52
    // cette fonction peut d�j� �tre pr�sente
52
    // cette fonction peut d�j� �tre pr�sente
53
	if (typeof(addListener) != \'function\') {
53
	if (typeof(addListener) != \'function\') {
54
		// fonction portable pour ajout de listeners
54
		// fonction portable pour ajout de listeners
55
		function addListener(element, baseName, handler)
55
		function addListener(element, baseName, handler)
56
		{
56
		{
57
			if (element.addEventListener) {
57
			if (element.addEventListener) {
58
				element.addEventListener(baseName, handler, false) ;
58
				element.addEventListener(baseName, handler, false) ;
59
			} else if (element.attachEvent) {
59
			} else if (element.attachEvent) {
60
				element.attachEvent(\'on\'+baseName, handler) ;
60
				element.attachEvent(\'on\'+baseName, handler) ;
61
			}
61
			}
62
		}
62
		}
63
	}
63
	}
64
    var map = null;
64
    var map = null;
65
    addListener(window,\'load\',loadMap) ;	
65
    addListener(window,\'load\',loadMap) ;	
66
	var geocoder = null;
66
	var geocoder = null;
67
	var lat = document.getElementById("latitude");
67
	var lat = document.getElementById("latitude");
68
    var lon = document.getElementById("longitude");
68
    var lon = document.getElementById("longitude");
69
    
69
    
70
    function loadMap() {
70
    function loadMap() {
71
	var point =  new google.maps.LatLng('.$GLOBALS['_BAZAR_']['ligne_resultat']['bf_latitude'].', '.$GLOBALS['_BAZAR_']['ligne_resultat']['bf_longitude'].');
71
	var point =  new google.maps.LatLng('.$GLOBALS['_BAZAR_']['ligne_resultat']['bf_latitude'].', '.$GLOBALS['_BAZAR_']['ligne_resultat']['bf_longitude'].');
72
	var optionsGoogleMapsv3 = {
72
	var optionsGoogleMapsv3 = {
73
		// On centre la carte sur le languedoc roussillon
73
		// On centre la carte sur le languedoc roussillon
74
		center: point,
74
		center: point,
75
		zoom: 7,
75
		zoom: 7,
76
		mapTypeId: "OSM",
76
		mapTypeId: "OSM",
77
		mapTypeControlOptions: {
77
		mapTypeControlOptions: {
78
			mapTypeIds: ["OSM", 
78
			mapTypeIds: ["OSM", 
79
				google.maps.MapTypeId.ROADMAP,
79
				google.maps.MapTypeId.ROADMAP,
80
				google.maps.MapTypeId.HYBRID,
80
				google.maps.MapTypeId.HYBRID,
81
				google.maps.MapTypeId.SATELLITE,
81
				google.maps.MapTypeId.SATELLITE,
82
				google.maps.MapTypeId.TERRAIN]
82
				google.maps.MapTypeId.TERRAIN]
83
		},
83
		},
84
		mapTypeControl: true,
84
		mapTypeControl: true,
85
		scaleControl: true
85
		scaleControl: true
86
	};
86
	};
87
	map = new google.maps.Map(document.getElementById("map"), optionsGoogleMapsv3);
87
	map = new google.maps.Map(document.getElementById("map"), optionsGoogleMapsv3);
88
	map.mapTypes.set("OSM", new google.maps.ImageMapType({
88
	map.mapTypes.set("OSM", new google.maps.ImageMapType({
89
		getTileUrl: function(coord, zoom) {
89
		getTileUrl: function(coord, zoom) {
90
 			return "http://osm.tela-botanica.org/tile/" + // cache de tuiles avec nginx
90
 			return "http://osm.tela-botanica.org/tile/" + // cache de tuiles avec nginx
91
 			zoom + "/" + coord.x + "/" + coord.y + ".png";
91
 			zoom + "/" + coord.x + "/" + coord.y + ".png";
92
 		},
92
 		},
93
 		tileSize: new google.maps.Size(256, 256),
93
 		tileSize: new google.maps.Size(256, 256),
94
 		isPng: true,
94
 		isPng: true,
95
 		alt: "OpenStreetMap",
95
 		alt: "OpenStreetMap",
96
 		name: "OSM",
96
 		name: "OSM",
97
		maxZoom: 19
97
		maxZoom: 19
98
	}));
98
	}));
99
 
99
 
100
	marker = new google.maps.Marker({
100
	marker = new google.maps.Marker({
101
	position: point,
101
	position: point,
102
		map: map
102
		map: map
103
	});
103
	});
104
 
104
 
105
	var mention = \'<div id="origine-donnees">Tuiles : <a href="http://www.openstreetmap.fr" target="_blank">OsmFr</a><br/>\';
105
	var mention = \'<div id="origine-donnees">Tuiles : <a href="http://www.openstreetmap.fr" target="_blank">OsmFr</a><br/>\';
106
	mention += \'Carte : <a href="http://www.openstreetmap.org/copyright" target="_blank">© les contributeurs d\\\'OpenStreetMap</a></div>\';
106
	mention += \'Carte : <a href="http://www.openstreetmap.org/copyright" target="_blank">© les contributeurs d\\\'OpenStreetMap</a></div>\';
107
	$("#map").append(mention);
107
	$("#map").append(mention);
108
 
108
 
109
	// ecouteur sur changement de fond
109
	// ecouteur sur changement de fond
110
	google.maps.event.addListener( map, \'maptypeid_changed\', function() { 
110
	google.maps.event.addListener( map, \'maptypeid_changed\', function() { 
111
		if (map.getMapTypeId() == "OSM") {
111
		if (map.getMapTypeId() == "OSM") {
112
			$("#origine-donnees").show();
112
			$("#origine-donnees").show();
113
		} else {
113
		} else {
114
			$("#origine-donnees").hide();
114
			$("#origine-donnees").hide();
115
		}
115
		}
116
	});
116
	});
117
};' ;
117
};' ;
118
    	GEN_stockerCodeScript($script);
118
    	GEN_stockerCodeScript($script);
119
    	//GEN_stockerFichierScript('googleMapScript', $this->options['nom_bdd']);
119
    	//GEN_stockerFichierScript('googleMapScript', $this->options['nom_bdd']);
120
    	GEN_stockerFichierScript('googleMapScript', "http://maps.googleapis.com/maps/api/js?sensor=false&key=".BAZ_GOOGLE_KEY);
120
    	GEN_stockerFichierScript('googleMapScript', "http://maps.googleapis.com/maps/api/js?sensor=false&key=".BAZ_GOOGLE_KEY);
121
    	// On ajoute l attribut load a la balise body
121
    	// On ajoute l attribut load a la balise body
122
		//GEN_AttributsBody('onload', 'load()');
122
		//GEN_AttributsBody('onload', 'load()');
123
		$html = '<div id="map" style="width: 400px; height: 300px"></div>';
123
		$html = '<div id="map" style="width: 400px; height: 300px"></div>';
124
		return $html;
124
		return $html;
125
	}
125
	}
126
}
126
}
127
 
127
 
128
/* +--Fin du code ----------------------------------------------------------------------------------------+
128
/* +--Fin du code ----------------------------------------------------------------------------------------+
129
*
129
*
130
* $Log: not supported by cvs2svn $
130
* $Log: not supported by cvs2svn $
131
*
131
*
132
* +-- Fin du code ----------------------------------------------------------------------------------------+
132
* +-- Fin du code ----------------------------------------------------------------------------------------+
133
*/
133
*/
134
?>
134
?>