[PLUGINS] +clavettes et dependances
[lhc/web/clavette_www.git] / www / plugins / gis / formulaires / configurer_gis.html
1 <div class="formulaire_spip formulaire_configurer formulaire_configurer_gis">
2
3 [<p class="reponse_formulaire reponse_formulaire_ok">(#ENV*{message_ok})</p>]
4 [<p class="reponse_formulaire reponse_formulaire_erreur">(#ENV*{message_erreur})</p>]
5
6 <div id="map_config" class="carte_gis" style="width: 100%; height: 370px"></div>
7
8 <form method="post" action="#ENV{action}"><div>
9 #ACTION_FORMULAIRE{#ENV{action}}
10 <ul>
11 <li class="rechercher_adresse editer_map_config">
12 <label for="champ_map_config_geocoder"><:gis:label_rechercher_address:></label>
13 <input type="text" class="text" name="champ_map_config_geocoder" id="champ_map_config_geocoder" value="" />
14 <a id="map_config_rechercher_geocodage"><:info_rechercher:></a>
15 </li>
16 [(#SAISIE{input,lat,
17 label=<:gis:lat:>,
18 defaut=0,
19 size=40})]
20 [(#SAISIE{input,lon,
21 label=<:gis:lon:>,
22 defaut=0,
23 size=40})]
24 [(#SAISIE{input,zoom,
25 label=<:gis:zoom:>,
26 defaut=0,
27 size=2,
28 maxlength=2})]
29
30 #SET{layers,#ARRAY}
31 <BOUCLE_layer(DATA){source table, #EVAL{$GLOBALS['gis_layers']}}>
32 #SET{layers,#GET{layers}|array_merge{#ARRAY{#CLE,#VALEUR|table_valeur{nom}}}}
33 </BOUCLE_layer>
34
35 [(#SET{layer_defaut,openstreetmap_mapnik})]
36 [(#VAL{_GIS_LAYER_DEFAUT}|defined|oui)
37 [(#SET{layer_defaut,[(#EVAL{_GIS_LAYER_DEFAUT})]})]
38 ]
39 [(#VAL{_GIS_LAYER_DEFAUT_FORCE}|defined|oui)
40 [(#SET{layer_readonly,readonly})]
41 [(#SET{layer_disable,disabled})]
42 [(#SET{layer_forcee,[(#EVAL{_GIS_LAYER_DEFAUT_FORCE})]})]
43 [(#SET{layer_explications,<:gis:explication_layer_forcee:>})]
44 ]
45 [(#SAISIE{selection,layer_defaut,
46 label=<:gis:cfg_lbl_layer_defaut:>,
47 cacher_option_intro=oui,
48 defaut=#GET{layer_defaut},
49 valeur_forcee=#GET{layer_forcee},
50 readonly=#GET{layer_readonly},
51 disable=#GET{layer_disable},
52 explication=#GET{layer_explications},
53 datas=#GET{layers}})]
54
55 [(#SAISIE{selection_multiple,layers,
56 label=<:gis:cfg_lbl_layers:>,
57 cacher_option_intro=oui,
58 defaut=#GET{layer_defaut},
59 datas=#GET{layers}})]
60
61 [(#SAISIE{input,api_key_bing,
62 label=<:gis:cfg_lbl_api_key_bing:>,
63 explication=<:gis:cfg_inf_bing{url=https://www.bingmapsportal.com/}:>,
64 size=40})]
65
66 [(#SAISIE{oui_non,geocoder,
67 defaut='',
68 label=<:gis:cfg_lbl_geocoder:>,
69 explication=<:gis:cfg_inf_geocoder:>})]
70
71 [(#SAISIE{oui_non,adresse,
72 defaut='',
73 label=<:gis:cfg_lbl_adresse:>,
74 explication=<:gis:cfg_inf_adresse:>})]
75
76 [(#SAISIE{oui_non,geolocaliser_user_html5,
77 defaut='',
78 label=<:gis:cfg_lbl_geolocaliser_user_html5:>,
79 explication=<:gis:cfg_inf_geolocaliser_user_html5:>})]
80
81 [(#SAISIE{choisir_objets,gis_objets,
82 label=<:gis:cfg_lbl_activer_objets:>,
83 exclus=spip_gis})]
84
85 </ul>
86
87
88 <p class="boutons">
89 <input type="submit" name="_cfg_ok" class="submit" value="<:bouton_enregistrer:>" />
90 </p>
91 </div></form>
92
93 <script type="text/javascript">
94 /*<![CDATA[*/
95
96 (function($){
97 var map, map_container = 'map_config', geocoder, marker;
98
99 var maj_inputs = function(map,pos,action) {
100 if(action == 'click'){
101 var zoom = map.getZoom();
102 $("#champ_lat").val(pos.lat);
103 $("#champ_lon").val(pos.lng);
104 $("#champ_zoom").val(zoom);
105 annuler_geocoder = 1;
106 }else if(annuler_geocoder != 1){
107 if(pos.point == 'undefined'){
108 $('#champ_#ENV{champ_lat,lat}').val(pos.lat);
109 $('#champ_#ENV{champ_lon,lon}').val(pos.lng);
110 map.panTo(pos);
111 marker.setLatLng(pos);
112 }else{
113 $('#champ_#ENV{champ_lat,lat}').val(pos.point.lat);
114 $('#champ_#ENV{champ_lon,lon}').val(pos.point.lng);
115 map.panTo(pos.point);
116 marker.setLatLng(pos.point);
117 }
118 }
119 }
120
121 function geocode(query) {
122 if(!query.error)
123 maj_inputs(map,query,'geocoding');
124 else
125 alert('<:gis:erreur_geocoder:> '+query.search);
126 }
127
128 var init_config = function() {
129 map = new L.Map(map_container);
130
131 map.attributionControl.setPrefix('');
132
133 //default layer
134 #SET{layer_defaut,#REM|gis_layer_defaut} #SET{layers,#EVAL{$GLOBALS['gis_layers']}}
135 var [(#GET{layer_defaut})] = [new (#GET{layers}|table_valeur{#GET{layer_defaut}/layer})];
136 map.addLayer([(#GET{layer_defaut})]);
137
138 <B_layers>
139 var layers_control = new L.Control.Layers();
140 layers_control.addBaseLayer([(#GET{layer_defaut})],["(#GET{layers}|table_valeur{#GET{layer_defaut}/nom})"]);
141 <BOUCLE_layers(DATA){source table, #GET{layers}}{si #ENV{control_type,#ENV{controle_type}}|!={non}|et{#ENV{no_control,#ENV{aucun_controle}}|!={oui}}|et{#CONFIG{gis/layers,#ARRAY}|count|>{1}|oui}|oui}>[
142 (#CLE|!={#GET{layer_defaut}}|oui|et{#CLE|in_array{#CONFIG{gis/layers,#ARRAY}}|oui}|oui)
143 layers_control.addBaseLayer([new (#VALEUR|table_valeur{layer})],"[(#VALEUR|table_valeur{nom})]");]
144 </BOUCLE_layers>
145 map.addControl(layers_control);
146 // classe noajax sur le layer_control pour éviter l'ajout de hidden par SPIP
147 $(layers_control._form).addClass('noajax');
148 </B_layers>
149
150 map.setView(new L.LatLng(#ENV{lat,0},#ENV{lon,0}),#ENV{zoom,0});
151
152 marker = new L.Marker(new L.LatLng(#ENV{lat,0},#ENV{lon,0}));
153 map.addLayer(marker);
154
155 geocoder = new L.Geocoder(geocode,{acceptLanguage:'#ENV{lang}'});
156
157 // mettre a jour les coordonnees quand on clique la carte
158 map.on('click', function(e) {
159 annuler_geocoder = 0;
160 marker.setLatLng(e.latlng);
161 map.panTo(e.latlng);
162 maj_inputs(map,e.latlng,'click');
163 });
164
165 // geocoder si clic...
166 $('a#map_config_rechercher_geocodage').css("cursor","pointer").click(function(){
167 var address = $("#champ_map_config_geocoder").val();
168 annuler_geocoder = 0;
169 geocoder.geocode(address);
170 });
171
172 // ne pas soumettre le formulaire si on presse Entree depuis le champ de recherche
173 $('#champ_map_config_geocoder').keypress(function(e){
174 if (e.which == 13) {
175 $('a#map_config_rechercher_geocodage').trigger("click");
176 return false;
177 }
178 });
179
180 // mettre à jour le zoom quand on le modifie
181 map.on('zoomend', function(e) {
182 $("#champ_zoom").val(e.target._zoom);
183 });
184 }
185
186 $(function(){
187 jQuery.getScript('[(#PRODUIRE{fond=javascript/gis.js}|compacte)]',function(){
188 init_config();
189 });
190 //onAjaxLoad(init_config);
191 });
192
193 })(jQuery);
194 /*]]>*/
195 </script>
196 </div>