Problem inserting javascript into php

0

I have a problem with inserting javascript code into php. What I am trying to do is create a map and insert markers (points) in it. The data is taken from a database in mysql, the queries are php and the rest in javascript. What I show here is a fragment within a function but when I try to do the select it does not show me the map (but I put that part in php it appears to me well). Could you help me see why this problem arises? I also tried putting echo and put the script in quotes but the result is the same

Public function ShowOrigenPMapa($latitud,$longitud){

	$origen = array ();
		include ('./config.php');
		include ('./define.php');
		
		$param = explode ( "=", $_POST [id] ); // prov-cliente-empresa-linea-origen-destino
	
		$sql_cli = "select cliente.*,cliente_provincia.*,s1.svr_replica_ip replica_cliente ,sr.svr_replica_ip replica_clip from cliente
	left join servidor s1 on s1.svr_ip=cliente_host
	,cliente_provincia
	left join servidor sr on sr.svr_ip=clip_host
	
where cliente_id = " . $param [1];
		$sql_cli .= " and clip_provincia_id=" . $param [0] . " and clip_cliente_id=cliente_id";
	
		$res_cli = $this->conn->query ( $sql_cli );
		$row_cli = $res_cli->fetch_array ( MYSQLI_ASSOC );
		$usageoloc = $row_cli [clip_usa_geoloc];
	
		$host = $row_cli [cliente_host];
		if ($row_cli ['replica_cliente'] > "") {
			$host = $row_cli ['replica_cliente'];
		}
		if ($row_cli ['clip_host'] > "") {
			$host = $row_cli ['clip_host'];
		}
		if ($row_cli ['replica_clip'] > "") {
			$host = $row_cli ['replica_clip'];
		}
		$db = $row_cli ['cliente_db'];
		if ($row_cli ['clip_db'] > "") {
			$db = $row_cli ['clip_db'];
		}
		$user = $ezMap ['user'];
		if ($row_cli ['clip_user'] > "") {
			$user = $row_cli ['clip_user'];
		}
		$pass = $ezMap ['pass'];
		if ($row_cli ['clip_pass'] > "") {
			$pass = $row_cli ['clip_pass'];
		}
		$this->link_db_cli = new mysqli ( $host, $user, $pass, $db );
		
		if (! $this->link_db_cli) {
			continue;
		}
		$this->link_db_cli->query ( "SET NAMES 'UTF8'" );
		$fecha=date('Y-m-d');
	
?>		
	
<script type="text/javascript">
		var latitud = <?php echo $latitud;?>;
		var longitud = <?php echo $longitud;?>;
		//alert (latitud);
		//alert (longitud);
<?php 
$qgps= "select locgps_codigo, locgps_id, locgps_localidad_id, localidad_nombre, locgps_latitud, locgps_longitud, locgps_tipo, locgps_nombre from localidad_gps left join localidad on locgps_localidad_id = localidad_id where locgps_tipo = 4";
 ?>
//ACA DEBERÍA IR UN WHILE PARA QUE CREE MARCADORES SEGÚN LAS CANTIDAD DE RESPUESTAS DEL SELECT
		 var iconFeature = new ol.Feature({
		  geometry: new ol.geom.Point([1, 8]),
		  name: 'Null Island',
		  population: 4000,
		  rainfall: 500
		});	
		var iconStyle = new ol.style.Style({
		  image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
		    anchor: [0.5, 46],
		    anchorXUnits: 'fraction',
		    anchorYUnits: 'pixels',
		    src: 'img/parabus2.png'
		  }))
		});	
		iconFeature.setStyle(iconStyle);	
		var vectorSource = new ol.source.Vector({
		  features: [iconFeature]
		});	
		var vectorLayer = new ol.layer.Vector({
		  source: vectorSource
		});		
		var rasterLayer = new ol.layer.Tile({
		  source: new ol.source.OSM()
		});
		var map = new ol.Map({
		  layers: [rasterLayer, vectorLayer],
		  target: document.getElementById('map'),
		  view: new ol.View({
		    center: ol.proj.transform(
                    [longitud, latitud], 'EPSG:4326', 'EPSG:3857'),
		    zoom: 10
		  })
		});
		var element = document.getElementById('popup');
		
		var popup = new ol.Overlay({
		  element: element,
		  positioning: 'bottom-center',
		  stopEvent: false,
		  offset: [0, -50]
		});
		map.addOverlay(popup);
		map.on('click', function(evt) {
		  var feature = map.forEachFeatureAtPixel(evt.pixel,
		      function(feature) {
		        return feature;
		      });
		  if (feature) {
		    var coordinates = feature.getGeometry().getCoordinates();
		    popup.setPosition(coordinates);
		    $(element).popover({
		      'placement': 'top',
		      'html': true,
		      'content': feature.get('name')
		    });
		    $(element).popover('show');
		  } else {
		    $(element).popover('destroy');
		  }
		});
		map.on('pointermove', function(e) {
		  if (e.dragging) {
		    $(element).popover('destroy');
		    return;
		  }
		  var pixel = map.getEventPixel(e.originalEvent);
		  var hit = map.hasFeatureAtPixel(pixel);
		  map.getTarget().style.cursor = hit ? 'pointer' : '';
		});           
</script>
		
}

public function ShowDestinoP() {
<?php	
    
asked by Luis 05.04.2018 в 22:04
source

0 answers