<?php session_start();
if(isset($_REQUEST['debug'])) {ini_set('display_errors', 'On');} 
require ('milfs/xajax/xajax.inc.php');
$xajax = new xajax();
//require ('json.lab.php');
require ('milfs/funciones/funciones.php');
require ("milfs/funciones/conex.php");
//require_once ('includes/markdown.php');
//require ('funciones/convert.php');
$xajax->processRequests(); 
//if($_REQUEST[id2] =='') {$agregar= $_REQUEST[id];}else {$agregar = $_REQUEST[id2];}
$formulario_nombre = remplacetas('form_id','id',$_REQUEST[id],'nombre') ;
$agregar_nombre = remplacetas('form_id','id',$agregar,'nombre') ;
$id_empresa = remplacetas('form_id','id',$_REQUEST[id],'id_empresa') ;
$plantilla ="mapa";
?>

<!DOCTYPE html>
<html lang="en">
   <head >
   <title><?php echo $formulario_nombre[0] ?> MILFS</title>
    <meta charset="utf-8">
    <meta name="viewport" content="user-scalable=no, width=device-width,  maximum-scale=1,  initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
     <?php $xajax->printJavascript("milfs/xajax/");  ?>
    <link rel="shortcut icon" href="favicon-152.png">
	<link rel="apple-touch-icon-precomposed" href="favicon-152.png">
<link rel="stylesheet" href="librerias/leaflet/leaflet.css"/>
<link rel="stylesheet" href="librerias/leaflet/leaflet-search.css"/>
<script src="librerias/leaflet/leaflet.js"></script>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="librerias/leaflet/leaflet-providers.js"></script>
<script src="librerias/leaflet/leaflet-search.js"></script>
	<link rel="stylesheet" type="text/css" media="screen" href="milfs/css/bootstrap.css">
<style type="text/css">
.navbar-default {
background:rgba(255,255,255,1)  ;

}
@media (max-width: 800px) {
    .panel-map{
        max-width: 970px;
    }
   
  
}
@media (min-width: 800px) {
    .panel-map{
        max-width: 200px;
    }
}

        
	.leaflet-popup-content {    word-wrap: break-word !important;  /*width:600px !important; */ }

#map { position:absolute; top:0; bottom:0; width:100%;  }
  /* Sticky footer styles
-------------------------------------------------- */
html {
  position: relative;
  min-height: 100%;
}
body {
  /* Margin bottom by footer height */
  margin-bottom: 60px;
  padding: 0; margin: 0; 
}



/* Custom page CSS
-------------------------------------------------- */
/* Not required for template or sticky footer method. */

body > .container {
  padding: 60px 15px 0;
}
.container .text-muted {
  margin: 20px 0;
}

.footer {
  position: absolute;
  bottom: 3px;
	width: 95%;
	margin: 0 auto;
	
	 height: 120px;
  
  /* Set the fixed height of the footer here */

   z-index: 999999;
}
#div_leyenda {
  padding: 2px;
  background-color: white;
  border-radius: 3px;
  width: 90%;
 
  overflow-x: scroll;
  
  
  
 
}

code {
  font-size: 80%;
}
.modal-dialog {
  width: 70%;
  height: 50%;
  padding: 0;
}

.modal-content {
  height: 50%;
}
  </style>
  <?php
  $css_adicional = remplacetas('form_parametrizacion','campo',"index",'descripcion'," tabla='css' and  opcion = 'adicional' and id_empresa = '$id_empresa[0]'") ;

	if($css_adicional[0] !="") {
	$css_adicional ="<style >
	$css_adicional[0]
	<!-- adicional -->
	</style>";
	}
	else {
	$css_adicional ="<style ><!-- nada --></style>";
	}
  echo $css_adicional; ?>
</head>
<body>

<div id="map" style="">

	<?php  $categorias = lista_categorias($_REQUEST['id'],'','') ;
	if($categorias !="") {
	$pie="
<div style='' class='' id='contenedor_pie' >
	<div  style='' class='container' >
	<a href='#' onclick=\"xajax_limpia_div('contenedor_pie'); \"><span class='pull-right'><i class='fa fa-times'></i></span></a>
	$categorias
		</div></div>
</div>";
$leyenda ="<div id='div_leyenda'><a class='btn btn-default  btn-xs' onclick=xajax_contenido_ocultar('div_leyenda');>Cerrar</a> $categorias </div> ";
	
		
	}else{
	
	}
	//echo $pie;
	 ?>
</div>
<script type="text/javascript">

var map = L.map('map');
//var terrainTiles = L.tileLayer.provider('OpenTopoMap');
//terrainTiles.addTo(map);
map.setView([4, -74.9005222], 5);

function addDataToMap(data, map) {
    var dataLayer = L.geoJson(data, {
    	            pointToLayer: function(feature, latlng) {
                var smallIcon = new L.Icon({
				     iconSize: [60, 60],
				     iconAnchor: [13, 27],
				     popupAnchor:  [1, -24],
				     iconUrl: feature.properties.icon.iconUrl

					 });
                return L.marker(latlng, {icon: smallIcon});
            },
        onEachFeature: function(feature, layer) {
            var popupText = feature.properties.description
               
               
            layer.bindPopup(popupText); }
        });
        map.fitBounds(dataLayer.getBounds());
    dataLayer.addTo(map);

}

/* PROVIDERS */

var legend = L.control({position: 'bottomright'});



    legend.onAdd = function (map) {
    var div = L.DomUtil.create('div', 'info legend');
    div.innerHTML = "<?php echo $leyenda; ?> <a class='btn btn-info  btn-xs' onclick=\"xajax_contenido_show('div_leyenda'); \"><span class=''>Leyenda</span></a>";
    
    div.id = "info legend"

        return div;
    };
    legend.addTo(map);
    
    
var defaultLayer = L.tileLayer.provider('OpenTopoMap').addTo(map);

		var baseLayers = {
			'Topográfico': defaultLayer,
			'OpenStretMap': L.tileLayer.provider('OpenStreetMap.Mapnik') ,
			'Blanco y Negro': L.tileLayer.provider('OpenStreetMap.BlackAndWhite'),
			'Humanitario.': L.tileLayer.provider('OpenStreetMap.HOT'),
			'Satelital': L.tileLayer.provider('Esri.WorldImagery')
			
			
		};

		var overlayLayers = {

		};

		var layerControl = L.control.layers(baseLayers, overlayLayers,{collapsed:false}).addTo(map);




		// resize layers control to fit into view.
		function resizeLayerControl() {
			var layerControlHeight = document.body.clientHeight - (10 + 50);
			var layerControl = document.getElementsByClassName('leaflet-control-layers-expanded')[0];

			layerControl.style.overflowY = 'auto';
			layerControl.style.maxHeight = layerControlHeight + 'px';
		}
		
		map.on('resize', resizeLayerControl);
		resizeLayerControl();

map.addControl( new L.Control.Search({
		url: 'https://nominatim.openstreetmap.org/search?format=json&q={s}',
		jsonpParam: 'json_callback',
		propertyName: 'display_name',
		propertyLoc: ['lat','lon'],
		markerLocation: true,
		autoCollapse: true,
		autoType: false,
		minLength: 2,
		zoom:17
	}) );
	


	
	
/* PROVIDERS */

 

/* $.getJSON("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson", function(data) { addDataToMap(data, map); });*/
$.getJSON("https://tupale.co/milfs/geojson.php?id=<?php echo $_REQUEST['id'] ?>&buscar=<?php echo $_REQUEST['buscar'] ?>", function(data) { addDataToMap(data, map); });
</script>
</body>
</html>