0) :
$js = '';
$GLOBALS['wiki']->AddCSSFile('styles/vendor/leaflet/leaflet.css');
$GLOBALS['wiki']->AddCSSFile('tools/bazar/presentation/styles/bazarcarto.css');
$GLOBALS['wiki']->AddCSSFile('javascripts/vendor/leaflet-draw/leaflet.draw.css');
$GLOBALS['wiki']->AddJavascriptFile('tools/bazar/presentation/javascripts/bazar.js');
$GLOBALS['wiki']->AddJavascriptFile('javascripts/vendor/leaflet/leaflet.min.js');
$GLOBALS['wiki']->AddJavascriptFile('javascripts/vendor/leaflet-providers/leaflet-providers.js');
$GLOBALS['wiki']->AddJavascriptFile('javascripts/vendor/leaflet-draw/leaflet.draw.js', false, true);
?>
AddJavascriptFile('tools/bazar/libs/vendor/leaflet/spiderfier/oms.min.js');
$markersjs = 'var popups = Array();'."\n".'oms = new OverlappingMarkerSpiderfier(map'.$params['nbbazarliste'].');'."\n".
'var popup = new L.Popup();
oms.addListener("click", function(marker) {
marker.openPopup();
});
oms.addListener(\'spiderfy\', function(markers) {
map'.$params['nbbazarliste'].'.closePopup();
});'."\n";
} elseif ($params['cluster'] == 'true' or $params['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 ($params['fullscreen'] == 'true' || $params['fullscreen'] == '1') {
$params['fullscreen'] = 'true';
$GLOBALS['wiki']->AddCSSFile('styles/vendor/leaflet-fullscreen/leaflet-fullscreen.css');
$GLOBALS['wiki']->AddJavascriptFile('javascripts/vendor/leaflet-fullscreen/leaflet-fullscreen.js');
} else {
$params['fullscreen'] = 'false' ;
}
$i = 0;
$geometries = [];
foreach ($fiches as $fiche) :?>
config['baz_marker_color']);
//icone de marqueur
$icon = $params['iconprefix']
.getCustomValueForEntry($params['icon'], $params['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 (is_array($fiche['geolocation']) && 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: '.$params['iconSize'].',
iconAnchor: '.$params['iconAnchor'].',
popupAnchor: '.$params['popupAnchor'].',
className: \'bazar-marker'.$params['smallmarker'].'\',
html: \''
.(!empty($icon) ? '' : '')
.'
\'
}),
title: \''.addslashes($fiche['bf_titre']).'\'
});
marker[i].bindPopup(\''.preg_replace("(\r\n|\n|\r|)", '', addslashes(baz_voir_fiche($params['barregestion'], $fiche))).'\');
';
if ($params['spider'] == 'true' or $params['spider'] == '1') {
$markersjs .= 'map'.$params['nbbazarliste'].'.addLayer(marker[i]);'."\n".'oms.addMarker(marker[i]);'."\n";
} elseif ($params['cluster'] == 'true' or $params['cluster'] == '1') {
$markersjs .= 'markerscluster.addLayer(marker[i]);'."\n";
} else {
$markersjs .= 'map'.$params['nbbazarliste'].'.addLayer(marker[i]);'."\n";
}
$i++;
}
if (!empty($fiche['geolocation']['geometries'])) {
$geometries[$fiche['id_fiche']] = $fiche['geolocation']['geometries'];
}
endforeach; ?>
AddJavascriptFile('tools/bazar/libs/vendor/leaflet/ajax/dist/leaflet.ajax.min.js');
}
$styleJs = '' ;
$isVisibleByDefault = false;
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: '.$params['iconSize'].',
iconAnchor: '.$params['iconAnchor'].',
popupAnchor: '.$params['popupAnchor'].',
className: "bazar-marker'.$params['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'.$params['nbbazarliste'].');' ;
}
break;
}
}
}
$js.= 'L.control.layers(baseLayers, layers).addTo(map'.$params['nbbazarliste'].');' ;
}
$geometriesModuleJs = '';
if (!empty($geometries)) {
$geometriesModuleJs .= "
var drawnFeatures = new L.FeatureGroup()
map".$params['nbbazarliste'].".addLayer(drawnFeatures)\n";
foreach ($geometries as $id => $g) {
$geometriesModuleJs .= "const geo{$id} = ".json_encode($g)."\n";
$geometriesModuleJs .= 'var popup = \''.preg_replace("(\r\n|\n|\r|)", '', addslashes(baz_voir_fiche($params['barregestion'], $id))).'\''."\n";
$geometriesModuleJs .= "drawnFeatures = drawGeometries(drawnFeatures, geo{$id}.features, popup)\n";
}
}
$GLOBALS['wiki']->AddJavascript( '
import { drawGeometries } from "./tools/bazar/presentation/javascripts/leaflet-draw.helper.js"
var map'.$params['nbbazarliste'].';
$(document).ready(function() {
if ($(\'#osmmap'.$params['nbbazarliste'].'\').length>0) {
'.$js.'
// N\'ajoute pas un doublon de layer, mais active la sélection du layer.
map'.$params['nbbazarliste'].'.addLayer(provider);
map'.$params['nbbazarliste'].'.setView(new L.LatLng('.$params['latitude'].', '.$params['longitude'].'), '.$params['zoom'].');
var i = 0;
var marker = Array();
'. $markersjs .'
}
'.$geometriesModuleJs.'
});', true
);
endif;