1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| /***** Carte IGN *****/
<?php if($this->key_ign != null): ?>
<?php
$public_dir = $_SERVER['DOCUMENT_ROOT'];
$autoconf_path = getenv('PREVARISC_IGN_AUTOCONF');
$autoconf_path = file_exists($public_dir.$autoconf_path) ? $autoconf_path : "";
?>
viewer = initViewer('geoportail-container',
'<?php echo $this->key_ign ?>',
[<?php echo $this->default_lon ?>, <?php echo $this->default_lat ?>],
'<b>Centre par défaut</b>',
'<?php echo $autoconf_path ?>');
viewer.listen('mapLoaded', afterInitMap);
viewer.listen('located', afterPositionLocated);
viewer.listen('azimuthChanged', onRotation);
function afterInitMap () {
// Ajout du bouton FullScreen sur la carte
var fsControl = new ol.control.FullScreen({});
viewer.getLibMap().addControl(fsControl);
// Ajout des couches utilisateur
viewer = addUserLayers(viewer,
'<?php echo $this->key_ign ?>',
<?php echo json_encode($this->couches_cartographiques) ?>);
nbCouches = viewer.getLibMap().getLayers().getLength();
// On enlève le marker par défaut, les outils de mesures, et le reset d'orientation
$('.ol-overlay-container').css('display', 'none');
$('div[id^=GPtoolbox-measure-main-]').css('display', 'none');
$('.ol-rotate').css('visibilty', 'hidden');
$('#adresse-modal #geolocme').removeAttr('disabled');
$('#adresse-modal #geolocme_nominatim').removeAttr('disabled');
};
function afterPositionLocated () {
$("span.result").text("Géolocalisée IGN");
$('#geoportail-container').css('visibility', 'visible');
// Changement des coordonnées et du marker
lonlat = updateCoordinates([viewer.getCenter().x, viewer.getCenter().y], 'EPSG:3857', 'EPSG:4326');
putMarkerAt(viewer.getLibMap(), lonlat, nbCouches);
};
function onRotation () {
viewer.getAzimuth() === 0 ? $('.ol-rotate').css('display', 'none') : $('.ol-rotate').css('display', 'block');
};
viewer.getLibMap().on('singleclick', function(evt) {
lonlat = updateCoordinates(evt.coordinate, 'EPSG:3857', 'EPSG:4326');
putMarkerAt(viewer.getLibMap(), lonlat, nbCouches);
});
$('#adresse-modal #geolocme').click(function(e) {
e.preventDefault();
var adresse = "";
var numero = $("input[name='numero']").val().trim();
var voie = $("input[name='voie_ac']").val().trim();
var codepostal = $("input[name='code_postal']").val();
var commune = $("input[name='commune_ac']").val().replace(/\(.*\)/g, '');
if (!commune) {
$("span.result").text("Pas de commune renseignée");
return false;
}
if (!voie) {
$("span.result").text("Pas de voie renseignée");
return false;
}
if (numero) {
adresse += numero + ", ";
}
adresse += voie + ", " + codepostal + ", " + commune;
$("span.result").text("Géolocalisation en cours...");
viewer.setCenter({
location : adresse,
locationType : ['StreetAddress']
});
return false;
});
<?php endif ?> |
Partager