Subversion Repositories Applications.bazar

Rev

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

Rev 475 Rev 476
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: bazar.fonct.google.php,v 1.1 2007-06-04 15:24:00 alexandre_tb Exp $
22
// CVS : $Id: bazar.fonct.google.php,v 1.1 2007-06-04 15:24:00 alexandre_tb Exp $
23
/**
23
/**
24
* Formulaire
24
* Formulaire
25
*
25
*
26
* Les fonctions et script specifique a un carto google
26
* Les fonctions et script specifique a un carto google
27
*
27
*
28
*@package bazar
28
*@package bazar
29
//Auteur original :
29
//Auteur original :
30
*@author        Aleandre GRANIER <alexandre@tela-botanica.org>
30
*@author        Aleandre GRANIER <alexandre@tela-botanica.org>
31
*@copyright     Tela-Botanica 2000-2007
31
*@copyright     Tela-Botanica 2000-2007
32
*@version       $Revision: 1.1 $
32
*@version       $Revision: 1.1 $
33
// +------------------------------------------------------------------------------------------------------+
33
// +------------------------------------------------------------------------------------------------------+
34
*/
34
*/
35
 
35
 
36
$script = '
36
$script = '
37
// Variables globales
37
// Variables globales
38
    var map = null;
38
    var map = null;
39
	var geocoder = null;
39
	var geocoder = null;
40
	var marker = null;
40
	var marker = null;
41
	var flat = null;
41
	var flat = null;
42
    var flon = null;
42
    var flon = null;
43
 
43
 
44
 // cette fonction peut d�j� �tre pr�sente
44
 // cette fonction peut d�j� �tre pr�sente
45
                // fonction portable pour ajout de listeners
45
                // fonction portable pour ajout de listeners
46
                function addListener(element, baseName, handler)
46
                function addListener(element, baseName, handler)
47
                {
47
                {
48
                        if (element.addEventListener) {
48
                        if (element.addEventListener) {
49
                                element.addEventListener(baseName, handler, false) ;
49
                                element.addEventListener(baseName, handler, false) ;
50
                        } else if (element.attachEvent) {
50
                        } else if (element.attachEvent) {
51
                                element.attachEvent(\'on\'+baseName, handler) ;
51
                                element.attachEvent(\'on\'+baseName, handler) ;
52
                        }
52
                        }
53
                }
53
                }
54
    addListener(window,\'load\',loadMap) ;
54
    addListener(window,\'load\',loadMap) ;
55
    function loadMap() {
55
    function loadMap() {
56
		flat = document.getElementById("latitude");
56
		flat = document.getElementById("latitude");
57
	    flon = document.getElementById("longitude");
57
	    flon = document.getElementById("longitude");
58
 
58
 
59
		var optionsGoogleMapsv3 = {
59
		var optionsGoogleMapsv3 = {
60
			// On centre la carte sur le languedoc roussillon
60
			// On centre la carte sur le languedoc roussillon
61
			center: new google.maps.LatLng(43.84245116699036, 3.768310546875),
61
			center: new google.maps.LatLng(43.84245116699036, 3.768310546875),
62
			zoom: 7,
62
			zoom: 7,
63
			mapTypeId: google.maps.MapTypeId.G_HYBRID_MAP,
-
 
64
			mapTypeId: "OSM",
63
			mapTypeId: "OSM",
65
			mapTypeControlOptions: {
64
			mapTypeControlOptions: {
66
			mapTypeIds: ["OSM", 
65
				mapTypeIds: ["OSM", 
67
				google.maps.MapTypeId.ROADMAP,
66
					google.maps.MapTypeId.ROADMAP,
68
				google.maps.MapTypeId.HYBRID,
67
					google.maps.MapTypeId.HYBRID,
69
				google.maps.MapTypeId.SATELLITE,
68
					google.maps.MapTypeId.SATELLITE,
70
				google.maps.MapTypeId.TERRAIN]
69
					google.maps.MapTypeId.TERRAIN]
71
			},
70
			},
72
			mapTypeControl: true,
71
			mapTypeControl: true,
73
			scaleControl: true
72
			scaleControl: true
74
		};
73
		};
75
	    map = new google.maps.Map(document.getElementById("map"), optionsGoogleMapsv3);
74
	    map = new google.maps.Map(document.getElementById("map"), optionsGoogleMapsv3);
76
		map.mapTypes.set("OSM", new google.maps.ImageMapType({
75
		map.mapTypes.set("OSM", new google.maps.ImageMapType({
77
 			getTileUrl: function(coord, zoom) {
76
 			getTileUrl: function(coord, zoom) {
78
 				return "http://osm.tela-botanica.org/tile/" + // cache de tuiles avec nginx
77
 				return "http://osm.tela-botanica.org/tile/" + // cache de tuiles avec nginx
79
 				zoom + "/" + coord.x + "/" + coord.y + ".png";
78
 				zoom + "/" + coord.x + "/" + coord.y + ".png";
80
 			},
79
 			},
81
 			tileSize: new google.maps.Size(256, 256),
80
 			tileSize: new google.maps.Size(256, 256),
82
 			isPng: true,
81
 			isPng: true,
83
 			alt: "OpenStreetMap",
82
 			alt: "OpenStreetMap",
84
 			name: "OSM",
83
 			name: "OSM",
85
			maxZoom: 19
84
			maxZoom: 19
86
		}));
85
		}));
87
 
86
 
88
	    google.maps.event.addListener(map, "click", function(event) {
87
	    google.maps.event.addListener(map, "click", function(event) {
89
			if (marker != null) {
88
			if (marker != null) {
90
				marker.setMap(null);
89
				marker.setMap(null);
91
				marker = null;
90
				marker = null;
92
	    	}
91
	    	}
93
			// On ajoute un marqueur a l endroit du clic et on place les coordonnees dans les champs latitude et longitude
92
			// On ajoute un marqueur a l endroit du clic et on place les coordonnees dans les champs latitude et longitude
94
			marker = event.overlay;
93
			marker = event.overlay;
95
	      	marker = new google.maps.Marker({
94
	      	marker = new google.maps.Marker({
96
				position: event.latLng,
95
				position: event.latLng,
97
				draggable: true,
96
				draggable: true,
98
				map: map
97
				map: map
99
			});
98
			});
100
	      	google.maps.event.addListener(marker, "dragend", function () {
99
	      	google.maps.event.addListener(marker, "dragend", function () {
101
            	coordMarker = marker.getPosition() ;
100
            	coordMarker = marker.getPosition() ;
102
            	flat.value = coordMarker.lat();
101
            	flat.value = coordMarker.lat();
103
            	flon.value = coordMarker.lng();
102
            	flon.value = coordMarker.lng();
104
          	});
103
          	});
105
          	setLatLonForm(marker);
104
          	setLatLonForm(marker);
106
    	});';
105
    	});';
107
		if ($formtemplate->getElementValue ('latitude') != '' && $formtemplate->getElementValue('longitude') != '') {
106
		if ($formtemplate->getElementValue ('latitude') != '' && $formtemplate->getElementValue('longitude') != '') {
108
			$script .= '
107
			$script .= '
109
				point = new google.maps.LatLng('.$formtemplate->getElementValue('latitude').', '.$formtemplate->getElementValue('longitude').');
108
				point = new google.maps.LatLng('.$formtemplate->getElementValue('latitude').', '.$formtemplate->getElementValue('longitude').');
110
				marker = new google.maps.Marker({
109
				marker = new google.maps.Marker({
111
					position: point,
110
					position: point,
112
					draggable: true,
111
					draggable: true,
113
					map: map
112
					map: map
114
				});
113
				});
115
		      	google.maps.event.addListener(marker, "dragend", function () {
114
		      	google.maps.event.addListener(marker, "dragend", function () {
116
	            	coordMarker = marker.getPosition() ;
115
	            	coordMarker = marker.getPosition() ;
117
	            	flat.value = coordMarker.lat();
116
	            	flat.value = coordMarker.lat();
118
	            	flon.value = coordMarker.lng();
117
	            	flon.value = coordMarker.lng();
119
	          	});
118
	          	});
120
			map.setCenter(point);
119
			map.setCenter(point);
121
			' ;
120
			' ;
122
		} 
121
		} 
123
	    $script .= 'geocoder = new google.maps.Geocoder();
122
	    $script .= 'geocoder = new google.maps.Geocoder();
124
	};
123
	};
125
	function showAddress() {
124
	function showAddress() {
126
		var adresse = document.getElementById("bf_adresse").value;
125
		var adresse = document.getElementById("bf_adresse").value;
127
    	var ville = "";
126
    	var ville = "";
128
	  	if (document.getElementById("bf_ville")) {
127
	  	if (document.getElementById("bf_ville")) {
129
	  		ville = document.getElementById("bf_ville").value ;
128
	  		ville = document.getElementById("bf_ville").value ;
130
	  	}
129
	  	}
131
	  	var cp = document.getElementById("bf_cp_lieu_evenement").value ;
130
	  	var cp = document.getElementById("bf_cp_lieu_evenement").value ;
132
	    var pays;
131
	    var pays;
133
	  	if (document.getElementById("liste30")) {
132
	  	if (document.getElementById("liste30")) {
134
	  		var selectIndex = document.getElementById("liste30").selectedIndex;
133
	  		var selectIndex = document.getElementById("liste30").selectedIndex;
135
	  		pays = document.getElementById("liste30").options[selectIndex].text ;
134
	  		pays = document.getElementById("liste30").options[selectIndex].text ;
136
	  	} else {
135
	  	} else {
137
	  		pays = document.getElementById("bf_pays").value;
136
	  		pays = document.getElementById("bf_pays").value;
138
	  	}
137
	  	}
139
	  	var address = adresse + \' \' + \' \' + cp + \' \' + ville + \' \' +pays ;
138
	  	var address = adresse + \' \' + \' \' + cp + \' \' + ville + \' \' +pays ;
140
	  	if (geocoder) {
139
	  	if (geocoder) {
141
	    	geocoder.geocode({
140
	    	geocoder.geocode({
142
	    		address: address
141
	    		address: address
143
	    	}, function(result, status) {
142
	    	}, function(result, status) {
144
	    		 if (status != google.maps.GeocoderStatus.OK) {
143
	    		 if (status != google.maps.GeocoderStatus.OK) {
145
    				alert(address + " not found");
144
    				alert(address + " not found");
146
			} else {
145
			} else {
147
			marker.setMap(null);
146
			marker.setMap(null);
148
			marker = null;
147
			marker = null;
149
			//map.setCenter(point, 13);
148
			//map.setCenter(point, 13);
150
			map.fitBounds(result[0].geometry.viewport);
149
			map.fitBounds(result[0].geometry.viewport);
151
			marker = new google.maps.Marker({
150
			marker = new google.maps.Marker({
152
				position: result[0].geometry.location,
151
				position: result[0].geometry.location,
153
				draggable: true,
152
				draggable: true,
154
				map: map
153
				map: map
155
				});
154
				});
156
			google.maps.event.addListener(marker, "dragend", function () {
155
			google.maps.event.addListener(marker, "dragend", function () {
157
					coordMarker = marker.getPosition() ;
156
					coordMarker = marker.getPosition() ;
158
					flat.value = coordMarker.lat();
157
					flat.value = coordMarker.lat();
159
					flon.value = coordMarker.lng();
158
					flon.value = coordMarker.lng();
160
				});
159
				});
161
			setLatLonForm(marker);
160
			setLatLonForm(marker);
162
			//marker.openInfoWindowHtml(address+ "'.BAZ_GOOGLE_MSG.'");
161
			//marker.openInfoWindowHtml(address+ "'.BAZ_GOOGLE_MSG.'");
163
		}
162
		}
164
      		});
163
      		});
165
  		}
164
  		}
166
	}
165
	}
167
	function setLatLonForm(marker) {
166
	function setLatLonForm(marker) {
168
  		coordMarker = marker.getPosition() ;
167
  		coordMarker = marker.getPosition() ;
169
  		flat.value = coordMarker.lat();
168
  		flat.value = coordMarker.lat();
170
  		flon.value = coordMarker.lng();
169
  		flon.value = coordMarker.lng();
171
	}
170
	}
172
';
171
';
173
 
172
 
174
 
173
 
175
 
174
 
176
/*
175
/*
177
* +--Fin du code ----------------------------------------------------------------------------------------+
176
* +--Fin du code ----------------------------------------------------------------------------------------+
178
*
177
*
179
* $Log: not supported by cvs2svn $
178
* $Log: not supported by cvs2svn $
180
* +-- Fin du code ----------------------------------------------------------------------------------------+
179
* +-- Fin du code ----------------------------------------------------------------------------------------+
181
*/
180
*/