Subversion Repositories Applications.bazar

Rev

Rev 478 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 478 Rev 486
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: "OSM",
63
			mapTypeId: "OSM",
64
			mapTypeControlOptions: {
64
			mapTypeControlOptions: {
65
				mapTypeIds: ["OSM", 
65
				mapTypeIds: ["OSM", 
66
					google.maps.MapTypeId.ROADMAP,
66
					google.maps.MapTypeId.ROADMAP,
67
					google.maps.MapTypeId.HYBRID,
67
					google.maps.MapTypeId.HYBRID,
68
					google.maps.MapTypeId.SATELLITE,
68
					google.maps.MapTypeId.SATELLITE,
69
					google.maps.MapTypeId.TERRAIN]
69
					google.maps.MapTypeId.TERRAIN]
70
			},
70
			},
71
			mapTypeControl: true,
71
			mapTypeControl: true,
72
			scaleControl: true
72
			scaleControl: true
73
		};
73
		};
74
	    map = new google.maps.Map(document.getElementById("map"), optionsGoogleMapsv3);
74
	    map = new google.maps.Map(document.getElementById("map"), optionsGoogleMapsv3);
75
		map.mapTypes.set("OSM", new google.maps.ImageMapType({
75
		map.mapTypes.set("OSM", new google.maps.ImageMapType({
76
 			getTileUrl: function(coord, zoom) {
76
 			getTileUrl: function(coord, zoom) {
77
 				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
78
 				zoom + "/" + coord.x + "/" + coord.y + ".png";
78
 				zoom + "/" + coord.x + "/" + coord.y + ".png";
79
 			},
79
 			},
80
 			tileSize: new google.maps.Size(256, 256),
80
 			tileSize: new google.maps.Size(256, 256),
81
 			isPng: true,
81
 			isPng: true,
82
 			alt: "OpenStreetMap",
82
 			alt: "OpenStreetMap",
83
 			name: "OSM",
83
 			name: "OSM",
84
			maxZoom: 19
84
			maxZoom: 19
85
		}));
85
		}));
-
 
86
 
-
 
87
		var mention = \'<div id="origine-donnees">Tuiles : <a href="http://www.openstreetmap.fr" target="_blank">OsmFr</a><br/>\';
-
 
88
		mention += \'Carte : <a href="http://www.openstreetmap.org/copyright" target="_blank">© les contributeurs d\\\'OpenStreetMap</a></div>\';
-
 
89
		$("#map").append(mention);
-
 
90
	
-
 
91
		// ecouteur sur changement de fond
-
 
92
		google.maps.event.addListener( map, \'maptypeid_changed\', function() { 
-
 
93
			if (map.getMapTypeId() == "OSM") {
-
 
94
				$("#origine-donnees").show();
-
 
95
			} else {
-
 
96
				$("#origine-donnees").hide();
-
 
97
			}
-
 
98
		});
86
 
99
 
87
	    google.maps.event.addListener(map, "click", function(event) {
100
	    google.maps.event.addListener(map, "click", function(event) {
88
			if (marker != null) {
101
			if (marker != null) {
89
				marker.setMap(null);
102
				marker.setMap(null);
90
				marker = null;
103
				marker = null;
91
	    	}
104
	    	}
92
			// On ajoute un marqueur a l endroit du clic et on place les coordonnees dans les champs latitude et longitude
105
			// On ajoute un marqueur a l endroit du clic et on place les coordonnees dans les champs latitude et longitude
93
			marker = event.overlay;
106
			marker = event.overlay;
94
	      	marker = new google.maps.Marker({
107
	      	marker = new google.maps.Marker({
95
				position: event.latLng,
108
				position: event.latLng,
96
				draggable: true,
109
				draggable: true,
97
				map: map
110
				map: map
98
			});
111
			});
99
	      	google.maps.event.addListener(marker, "dragend", function () {
112
	      	google.maps.event.addListener(marker, "dragend", function () {
100
            	coordMarker = marker.getPosition() ;
113
            	coordMarker = marker.getPosition() ;
101
            	flat.value = coordMarker.lat();
114
            	flat.value = coordMarker.lat();
102
            	flon.value = coordMarker.lng();
115
            	flon.value = coordMarker.lng();
103
          	});
116
          	});
104
          	setLatLonForm(marker);
117
          	setLatLonForm(marker);
105
    	});';
118
    	});';
106
		if ($formtemplate->getElementValue ('latitude') != '' && $formtemplate->getElementValue('longitude') != '') {
119
		if ($formtemplate->getElementValue ('latitude') != '' && $formtemplate->getElementValue('longitude') != '') {
107
			$script .= '
120
			$script .= '
108
				point = new google.maps.LatLng('.$formtemplate->getElementValue('latitude').', '.$formtemplate->getElementValue('longitude').');
121
				point = new google.maps.LatLng('.$formtemplate->getElementValue('latitude').', '.$formtemplate->getElementValue('longitude').');
109
				marker = new google.maps.Marker({
122
				marker = new google.maps.Marker({
110
					position: point,
123
					position: point,
111
					draggable: true,
124
					draggable: true,
112
					map: map
125
					map: map
113
				});
126
				});
114
		      	google.maps.event.addListener(marker, "dragend", function () {
127
		      	google.maps.event.addListener(marker, "dragend", function () {
115
	            	coordMarker = marker.getPosition() ;
128
	            	coordMarker = marker.getPosition() ;
116
	            	flat.value = coordMarker.lat();
129
	            	flat.value = coordMarker.lat();
117
	            	flon.value = coordMarker.lng();
130
	            	flon.value = coordMarker.lng();
118
	          	});
131
	          	});
119
			map.setCenter(point);
132
			map.setCenter(point);
120
			' ;
133
			' ;
121
		} 
134
		} 
122
	    $script .= 'geocoder = new google.maps.Geocoder();
135
	    $script .= 'geocoder = new google.maps.Geocoder();
123
	};
136
	};
124
	function showAddress() {
137
	function showAddress() {
125
        var adresse = document.getElementById("bf_adresse").value;
138
        var adresse = document.getElementById("bf_adresse").value;
126
        if (adresse == "") {
139
        if (adresse == "") {
127
            return false;
140
            return false;
128
        }
141
        }
129
        var ville = "";
142
        var ville = "";
130
        if (document.getElementById("bf_ville")) {
143
        if (document.getElementById("bf_ville")) {
131
            ville = document.getElementById("bf_ville").value ;
144
            ville = document.getElementById("bf_ville").value ;
132
        }
145
        }
133
        var cp = document.getElementById("bf_cp_lieu_evenement").value ;
146
        var cp = document.getElementById("bf_cp_lieu_evenement").value ;
134
        var pays;
147
        var pays;
135
        if (document.getElementById("liste30")) {
148
        if (document.getElementById("liste30")) {
136
            var selectIndex = document.getElementById("liste30").selectedIndex;
149
            var selectIndex = document.getElementById("liste30").selectedIndex;
137
            pays = document.getElementById("liste30").options[selectIndex].text ;
150
            pays = document.getElementById("liste30").options[selectIndex].text ;
138
        } else {
151
        } else {
139
            pays = document.getElementById("bf_pays").value;
152
            pays = document.getElementById("bf_pays").value;
140
        }
153
        }
141
        var address = adresse + \' \' + \' \' + cp + \' \' + ville + \' \' +pays ;
154
        var address = adresse + \' \' + \' \' + cp + \' \' + ville + \' \' +pays ;
142
        if (address && geocoder) {
155
        if (address && geocoder) {
143
            geocoder.geocode({
156
            geocoder.geocode({
144
                address: address
157
                address: address
145
            }, function(result, status) {
158
            }, function(result, status) {
146
                 if (status != google.maps.GeocoderStatus.OK) {
159
                 if (status != google.maps.GeocoderStatus.OK) {
147
                    alert(address + " not found");
160
                    alert(address + " not found");
148
            } else {
161
            } else {
149
                map.fitBounds(result[0].geometry.viewport);
162
                map.fitBounds(result[0].geometry.viewport);
150
                marker = new google.maps.Marker({
163
                marker = new google.maps.Marker({
151
                    position: result[0].geometry.location,
164
                    position: result[0].geometry.location,
152
                    draggable: true,
165
                    draggable: true,
153
                    map: map
166
                    map: map
154
                });
167
                });
155
                google.maps.event.addListener(marker, "dragend", function () {
168
                google.maps.event.addListener(marker, "dragend", function () {
156
                    coordMarker = marker.getPosition() ;
169
                    coordMarker = marker.getPosition() ;
157
                    flat.value = coordMarker.lat();
170
                    flat.value = coordMarker.lat();
158
                    flon.value = coordMarker.lng();
171
                    flon.value = coordMarker.lng();
159
                });
172
                });
160
                setLatLonForm(marker);
173
                setLatLonForm(marker);
161
                //marker.openInfoWindowHtml(address+ "'.BAZ_GOOGLE_MSG.'");
174
                //marker.openInfoWindowHtml(address+ "'.BAZ_GOOGLE_MSG.'");
162
            }
175
            }
163
        });
176
        });
164
    }
177
    }
165
    }
178
    }
166
	function setLatLonForm(marker) {
179
	function setLatLonForm(marker) {
167
  		coordMarker = marker.getPosition() ;
180
  		coordMarker = marker.getPosition() ;
168
  		flat.value = coordMarker.lat();
181
  		flat.value = coordMarker.lat();
169
  		flon.value = coordMarker.lng();
182
  		flon.value = coordMarker.lng();
170
	}
183
	}
171
';
184
';
172
 
185
 
173
 
186
 
174
 
187
 
175
/*
188
/*
176
* +--Fin du code ----------------------------------------------------------------------------------------+
189
* +--Fin du code ----------------------------------------------------------------------------------------+
177
*
190
*
178
* $Log: not supported by cvs2svn $
191
* $Log: not supported by cvs2svn $
179
* +-- Fin du code ----------------------------------------------------------------------------------------+
192
* +-- Fin du code ----------------------------------------------------------------------------------------+
180
*/
193
*/