Change map parameter to be array of coordinates.
This commit is contained in:
parent
6c4b29c37f
commit
51629eeece
2 changed files with 20 additions and 8 deletions
|
@ -29,7 +29,7 @@ if (isValidStop($_GET["stop"])){
|
|||
echo '<div id="routes" class="tab-pane fade in active" role="tabpanel">';
|
||||
PrintRoutes($_GET["stop"]);
|
||||
echo '</div><div id="map" class="tab-pane fade" role="tabpanel">';
|
||||
ShowMap($stop['lat'],$stop['lon']);
|
||||
ShowMap(array(array($stop['lat'],$stop['lon'])));
|
||||
echo '</div></div>';
|
||||
} else {
|
||||
echo '<span style="display:inline-block" class="alert alert-danger" role="alert">No such stop. <a href="javascript:history.back()">Go back?</a></span>';
|
||||
|
|
|
@ -2,11 +2,10 @@
|
|||
<script src="openlayers/ol.js"></script>
|
||||
|
||||
<?php
|
||||
function ShowMap($lat,$lon){
|
||||
function ShowMap($coords){
|
||||
?>
|
||||
<div id="mymap" style="width:300px;height:300px;overflow:hidden;"></div>
|
||||
<script>
|
||||
var pos = new ol.proj.fromLonLat([<?=$lon?>, <?=$lat?>]);
|
||||
var style = new ol.style.Style({
|
||||
image: new ol.style.Circle({
|
||||
fill: new ol.style.Fill({color: '#FF0000'}),
|
||||
|
@ -14,12 +13,25 @@ function ShowMap($lat,$lon){
|
|||
radius: 5
|
||||
})
|
||||
});
|
||||
var feat = new ol.Feature({
|
||||
geometry: new ol.geom.Point(pos)
|
||||
});
|
||||
feat.setStyle(style);
|
||||
<?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:[feat]});
|
||||
var vectorSource = new ol.source.Vector({features:features});
|
||||
var vectorLayer = new ol.layer.Vector({
|
||||
source: vectorSource,
|
||||
opacity: 0.5
|
||||
|
|
Reference in a new issue