62 lines
1.8 KiB
PHP
62 lines
1.8 KiB
PHP
<link rel="stylesheet" href="openlayers/ol.css" />
|
|
<script src="openlayers/ol.js"></script>
|
|
|
|
<?php
|
|
function ShowMap($coords){
|
|
if(count($coords)>0){
|
|
?>
|
|
<div id="mymap" style="width:300px;height:300px;overflow:hidden;"></div>
|
|
<script>
|
|
var style = new ol.style.Style({
|
|
image: new ol.style.Circle({
|
|
fill: new ol.style.Fill({color: '#FF0000'}),
|
|
stroke: new ol.style.Stroke({color: '#000000'}),
|
|
radius: 5
|
|
})
|
|
});
|
|
<?php
|
|
echo "var coordinates = [";
|
|
for ($i=0; $i<count($coords)-1;$i++){
|
|
$loc = $coords[$i];
|
|
echo '['. $loc[1] . ',' . $loc[0] . '],';
|
|
}
|
|
echo '['. $coords[$i][1] . ',' . $coords[$i][0] . ']];';
|
|
?>
|
|
var pos = new ol.proj.fromLonLat([coordinates[0][0],coordinates[0][1]]);
|
|
var features = [];
|
|
for(var i=0; i<coordinates.length; i++){
|
|
var feat = new ol.Feature({
|
|
geometry: new ol.geom.Point(new ol.proj.fromLonLat([coordinates[i][0],coordinates[i][1]]))
|
|
});
|
|
feat.setStyle(style);
|
|
features.push(feat);
|
|
}
|
|
|
|
var vectorSource = new ol.source.Vector({features:features});
|
|
var vectorLayer = new ol.layer.Vector({
|
|
source: vectorSource,
|
|
opacity: 0.5
|
|
});
|
|
var map = new ol.Map({
|
|
target: document.getElementById("mymap"),
|
|
layers: [
|
|
new ol.layer.Tile({
|
|
source: new ol.source.OSM()
|
|
}),
|
|
vectorLayer
|
|
],
|
|
view: new ol.View({
|
|
center: pos,
|
|
zoom:13
|
|
})
|
|
});
|
|
</script>
|
|
<?php
|
|
}else{
|
|
?>
|
|
<span style="display:inline-block" class="alert alert-danger" role="alert">No bus on its way yet. <a href="javascript:history.back()">Go back?</a></span>
|
|
|
|
<?php
|
|
}
|
|
}
|
|
?>
|