0) :
$js = '';
// TODO: y-a-t'il pagination en mode carto ?
echo $pager_links;
$GLOBALS['wiki']->AddCSSFile('tools/bazar/libs/vendor/leaflet/leaflet.css');
$GLOBALS['wiki']->AddJavascriptFile('tools/bazar/libs/bazar.js');
$GLOBALS['wiki']->AddJavascriptFile('tools/bazar/libs/vendor/leaflet/leaflet.js');
$GLOBALS['wiki']->AddJavascriptFile('tools/bazar/libs/vendor/leaflet/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('tools/bazar/libs/vendor/leaflet/markercluster/MarkerCluster.css');
$GLOBALS['wiki']->AddJavascriptFile('tools/bazar/libs/vendor/leaflet/markercluster/leaflet.markercluster.js');
$markersjs = 'var markerscluster = new L.MarkerClusterGroup();'."\n";
} else {
$markersjs = '';
}
if ($param['fullscreen'] == 'true' || $param['fullscreen'] == '1') {
$param['fullscreen'] = 'true';
$GLOBALS['wiki']->AddCSSFile('tools/bazar/libs/vendor/leaflet/fullscreen/Control.FullScreen.css');
$GLOBALS['wiki']->AddJavascriptFile('tools/bazar/libs/vendor/leaflet/fullscreen/Control.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']);
$tab = explode('|', isset($fiche['carte_google']) ? $fiche['carte_google'] : '');
if (count($tab)>1 && $tab[0]!='' && $tab[1]!='' && is_numeric($tab[0]) && is_numeric($tab[1])) {
// on genere le point marqueur sur la carte
$markersjs .= '
i++;
var markerLocation = new L.LatLng('.$tab[0].', '.$tab[1].');
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 ){
$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 );
}
} );' ;
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;