0) : $js = ''; // TODO: y-a-t'il pagination en mode carto ? echo $pager_links; $GLOBALS['wiki']->AddCSSFile('styles/vendor/leaflet/leaflet.css'); $GLOBALS['wiki']->AddCSSFile('tools/bazar/presentation/styles/bazarcarto.css'); $GLOBALS['wiki']->AddJavascriptFile('tools/bazar/libs/bazar.js'); $GLOBALS['wiki']->AddJavascriptFile('javascripts/vendor/leaflet/leaflet.min.js'); $GLOBALS['wiki']->AddJavascriptFile('javascripts/vendor/leaflet-providers/leaflet-providers.js'); ?>
AddJavascriptFile('tools/bazar/libs/vendor/leaflet/spiderfier/oms.min.js'); $markersjs = 'var popups = Array();'."\n".'oms = new OverlappingMarkerSpiderfier(map'.$param['nbbazarliste'].');'."\n". 'var popup = new L.Popup(); oms.addListener("click", function(marker) { marker.openPopup(); }); oms.addListener(\'spiderfy\', function(markers) { map'.$param['nbbazarliste'].'.closePopup(); });'."\n"; } elseif ($param['cluster'] == 'true' or $param['cluster'] == '1') { $GLOBALS['wiki']->AddCSSFile('styles/vendor/leaflet-markercluster/leaflet.markercluster.css'); $GLOBALS['wiki']->AddJavascriptFile('javascripts/vendor/leaflet-markercluster/leaflet-markercluster.min.js'); $markersjs = 'var markerscluster = new L.MarkerClusterGroup();'."\n"; } else { $markersjs = ''; } if ($param['fullscreen'] == 'true' || $param['fullscreen'] == '1') { $param['fullscreen'] = 'true'; $GLOBALS['wiki']->AddCSSFile('styles/vendor/leaflet-fullscreen/leaflet-fullscreen.css'); $GLOBALS['wiki']->AddJavascriptFile('javascripts/vendor/leaflet-fullscreen/leaflet-fullscreen.js'); } else { $param['fullscreen'] = 'false' ; } $i = 0; foreach ($fiches as $fiche) :?> config['baz_marker_color']); //icone de marqueur $icon = $param['iconprefix'] .getCustomValueForEntry($param['icon'], $param['iconfield'], $fiche, $GLOBALS['wiki']->config['baz_marker_icon']); if (!isset($fiche['geolocation'])) { // backward compatibility hack for old carte_google fields $fiche['geolocation'] = []; $tab = explode('|', isset($fiche['carte_google']) ? $fiche['carte_google'] : ''); if (!empty($tab[0]) && !empty($tab[1])) { $fiche['geolocation']['bf_latitude'] = $tab[0]; $fiche['geolocation']['bf_longitude'] = $tab[1]; } elseif (!empty($fiche['bf_latitude']) && !empty($fiche['bf_longitude'])){ $fiche['geolocation']['bf_latitude'] = $fiche['bf_latitude']; $fiche['geolocation']['bf_longitude'] = $fiche['bf_longitude']; } } if (count($fiche['geolocation'])>1 && $fiche['geolocation']['bf_latitude']!='' && $fiche['geolocation']['bf_longitude']!='' && is_numeric($fiche['geolocation']['bf_latitude']) && is_numeric($fiche['geolocation']['bf_longitude'])) { // on genere le point marqueur sur la carte $markersjs .= ' i++; var markerLocation = new L.LatLng('.$fiche['geolocation']['bf_latitude'].', '.$fiche['geolocation']['bf_longitude'].'); marker[i] = new L.Marker( markerLocation, { icon: L.divIcon({ iconSize: '.$param['iconSize'].', iconAnchor: '.$param['iconAnchor'].', popupAnchor: '.$param['popupAnchor'].', className: \'bazar-marker'.$param['smallmarker'].'\', html: \'
' .(!empty($icon) ? '' : '') .'
\' }), title: \''.addslashes($fiche['bf_titre']).'\' }); marker[i].bindPopup(\''.preg_replace("(\r\n|\n|\r|)", '', addslashes(baz_voir_fiche($param['barregestion'], $fiche))).'\'); '; if ($param['spider'] == 'true' or $param['spider'] == '1') { $markersjs .= 'map'.$param['nbbazarliste'].'.addLayer(marker[i]);'."\n".'oms.addMarker(marker[i]);'."\n"; } elseif ($param['cluster'] == 'true' or $param['cluster'] == '1') { $markersjs .= 'markerscluster.addLayer(marker[i]);'."\n"; } else { $markersjs .= 'map'.$param['nbbazarliste'].'.addLayer(marker[i]);'."\n"; } $i++; } endforeach; ?> AddJavascript( $js ); $js .= 'var layers = {};' ; if( is_array($param['layers']) ){ $leafletajaxIncluded = false ; foreach( $param['layers'] as $layer ) { @list( $layerLabel, $layerType, $layerOptions, $layerUrl ) = explode('|', $layer); if( $layerUrl == null ) { $layerUrl = $layerOptions ; $layerOptions = null ; } $layerType = strtolower($layerType); if( ! in_array($layerType, array('tiles','geojson') ) ){ $js.= 'alert("Erreur paramètre \\"layers\\": le type \\"'.$layerType.'\\" est inconnu")'; } switch($layerType) { case 'tiles': $js.= 'layers["'.$layerLabel.'"] = L.tileLayer("'.$layerUrl.'");' ; break; case 'geojson': // URL: Attention au Blocage d’une requête multi-origines (Cross-Origin Request). // Le plus simple est de recopier les data GeoJson dans une page du Wiki puis de l'appeler avec le handler "/raw". // STYLE: // http://leafletjs.com/reference.html#path-options // http://leafletjs.com/reference.html#marker-options if( ! $leafletajaxIncluded ) { $leafletajaxIncluded = true ; $GLOBALS['wiki']->AddJavascriptFile('tools/bazar/libs/vendor/leaflet/ajax/dist/leaflet.ajax.min.js'); } $styleJs = '' ; if( $layerOptions!=null ){ // extract 'visiblebydefault' if (preg_match_all("/visiblebydefault\\s*;?/i",$layerOptions,$matches)){ $isVisibleByDefault = true; foreach ($matches[0] as $key => $value) { $layerOptions = str_replace($value,'',$layerOptions); } } $layerOptions = str_replace(';',',',$layerOptions); $styleJs.=' style: function (feature, latlng) { // pour les lignes et polygones if( feature.geometry.type=="Point" ) return ; return {'.$layerOptions.'}; }, pointToLayer: function (feature, latlng) { // pour les points // parsing de layerOptions pour distinguer les options de marker et celles pour construire un icon pour le marker. var layerOptions = "'.$layerOptions.'".split(","); var markerOptions = {} , iconClass=null, color=null ; for( opt in layerOptions ) { opt = layerOptions[opt].split(":"); switch(opt[0].trim()) { case "opacity": case "clickable": // les options pour le marker http://leafletjs.com/reference.html#marker markerOptions[opt[0].trim()] = opt[1].trim(); break; case "icon": // pour le html du L.divIcon http://leafletjs.com/reference.html#divicon // supprimer les éventuels apostrhophes iconClass = opt[1].trim().replace(/\'/g, ""); break; case "color": // pour le html du L.divIcon color = opt[1].trim(); break; } } if( iconClass!=null || color!=null ) { // Construit un L.divIcon pour le marker, sinon ce sera par défaut la goutte bleu. markerOptions["icon"] = L.divIcon({ iconSize: '.$param['iconSize'].', iconAnchor: '.$param['iconAnchor'].', popupAnchor: '.$param['popupAnchor'].', className: "bazar-marker'.$param['smallmarker'].'", html: "
" + (iconClass==null?"":"") + "
" }); } return L.marker(latlng, markerOptions); }, '; } $js.= 'layers["'.$layerLabel.'"] = L.geoJson.ajax("'.$layerUrl.'", { '.$styleJs.' onEachFeature: function (feature, layer) { //layer.bindPopup(feature.properties.NOM + feature.properties.NOM_QP); var str = "" ; for( var prop in feature.properties){ if( prop.toLowerCase() == "url" ) { str+= prop +": " + feature.properties[prop] +"
"; } else { str+= prop +": "+ feature.properties[prop] +"
"; } } layer.bindPopup( str ); } } );' ; if ($isVisibleByDefault){ // add layer to the map $js.= 'layers["'.$layerLabel.'"].addTo(map'.$param['nbbazarliste'].');' ; } break; } } } $js.= 'L.control.layers(baseLayers, layers).addTo(map'.$param['nbbazarliste'].');' ; } $GLOBALS['wiki']->AddJavascript( ' $(document).ready(function() { if ($(\'#osmmap'.$param['nbbazarliste'].'\').length>0) { '.$js.' // N\'ajoute pas un doublon de layer, mais active la sélection du layer. map'.$param['nbbazarliste'].'.addLayer(provider); map'.$param['nbbazarliste'].'.setView(new L.LatLng('.$param['latitude'].', '.$param['longitude'].'), '.$param['zoom'].'); var i = 0; var marker = Array(); '. $markersjs .' } });' ); endif;