Stop Browser Map
--- a/include/common.inc.php
+++ b/include/common.inc.php
@@ -163,7 +163,7 @@
$key => $val
));
}
- if ($sort_ascending) $array = array_reverse($temp_array);
+ if ($sort_ascending && isset($temp_array)) $array = array_reverse($temp_array);
else $array = $temp_array;
}
function r_implode( $glue, $pieces )
--- a/labs/index.php
+++ b/labs/index.php
@@ -10,6 +10,8 @@
<p>Analysis of route timing points</p></a></li>
<li><a href="busstopdensity.php"><h3>Bus Stop Density Map</h3>
<p>Analysis of bus stop coverage</p></a></li>
+ <li><a href="stopBrowser.php"><h3>Bus Stop Browser Map</h3>
+ <p>Bus stop location/route browser</p></a></li>
<li>More coming soon!</li>
</ul>
</div>
--- /dev/null
+++ b/labs/stopBrowser.kml.php
@@ -1,1 +1,62 @@
+<?php
+ header('Content-type: application/vnd.google-earth.kml+xml');
+//http://wiki.openstreetmap.org/wiki/OpenLayers_Dynamic_KML
+// Creates the KML/XML Document.
+ $dom = new DOMDocument('1.0', 'UTF-8');
+
+ // Creates the root KML element and appends it to the root document.
+ $node = $dom->createElementNS('http://earth.google.com/kml/2.1', 'kml');
+ $parNode = $dom->appendChild($node);
+
+ // Creates a KML Document element and append it to the KML element.
+ $dnode = $dom->createElement('Document');
+ $docNode = $parNode->appendChild($dnode);
+
+
+$bbox = $_GET['bbox']; // get the bbox param from google earth
+list($bbox_south, $bbox_west, $bbox_north,$bbox_east) = explode(",", $bbox); // west, south, east, north
+
+include ('../include/common.inc.php');
+$debugOkay = Array();
+$contents = getNearbyStops( (($bbox_west+ $bbox_east) /2), ($bbox_south + $bbox_north)/2 ,50, 3000);
+foreach ($contents as $stop) {
+ $description = 'http://bus.lambdacomplex.org/' . 'stop.php?stopid=' . $stop['stop_id'] ." <br>";
+ $trips = getStopTripsWithTimes($stop['stop_id'], "", "", "", 3);
+ if ($trips) {
+ foreach ($trips as $key => $row) {
+ if ($key < 3) {
+ $description .= $row['route_short_name'] . ' ' . $row['route_long_name'] . ' @ ' . $row['arrival_time'] . "<br>";
+ }
+ }
+ } else {
+ $description .= "No more trips today";
+ }
+ // Creates a Placemark and append it to the Document.
+ $node = $dom->createElement('Placemark');
+ $placeNode = $docNode->appendChild($node);
+
+ // Creates an id attribute and assign it the value of id column.
+ $placeNode->setAttribute('id', 'placemark' . $stop['stop_id']);
+
+ // Create name, and description elements and assigns them the values of the name and address columns from the results.
+ $nameNode = $dom->createElement('name',htmlentities($stop['stop_name']));
+ $descriptionNode = $dom->createElement('description',$description);
+ $placeNode->appendChild($nameNode);
+ $placeNode->appendChild($descriptionNode);
+
+ // Creates a Point element.
+ $pointNode = $dom->createElement('Point');
+ $placeNode->appendChild($pointNode);
+
+ // Creates a coordinates element and gives it the value of the lng and lat columns from the results.
+ $coorStr = $stop['stop_lon'] . ',' . $stop['stop_lat'];
+ $coorNode = $dom->createElement('coordinates', $coorStr);
+ $pointNode->appendChild($coorNode);
+ }
+
+
+ $kmlOutput = $dom->saveXML();
+ echo $kmlOutput;
+?>
+
--- /dev/null
+++ b/labs/stopBrowser.php
@@ -1,1 +1,102 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <script src="openlayers/OpenLayers.js"></script>
+ <SCRIPT TYPE="text/javascript" SRC="OpenStreetMap.js"></SCRIPT>
+ <script type="text/javascript">
+ var map,select;
+
+
+function init()
+{
+ var extent = new OpenLayers.Bounds(148.98, -35.48, 149.25, -35.15);
+
+ // set up the map options
+ var options =
+ {
+ maxExtent: extent,
+ numZoomLevels: 20,
+ };
+
+ // create the ol map object
+ map = new OpenLayers.Map('map', options);
+
+var osmtiles = new OpenLayers.Layer.OSM("OSM");
+var nearmap = new OpenLayers.Layer.OSM.NearMap("NearMap");
+
+ var stopbrowser = new OpenLayers.Layer.Vector("POI", {
+ projection: new OpenLayers.Projection("EPSG:4326"),
+ strategies: [
+ new OpenLayers.Strategy.BBOX(),
+ ],
+ protocol: new OpenLayers.Protocol.HTTP({
+ url: "stopBrowser.kml.php", //Note that it is probably worth adding a Math.random() on the end of the URL to stop caching.
+ format: new OpenLayers.Format.KML({
+ extractStyles: true,
+ extractAttributes: true
+ }),
+ })
+ });
+
+ map.addLayers([osmtiles,stopbrowser,nearmap]);
+
+ var lonLat = new OpenLayers.LonLat(149.11, -35.28).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
+ map.setCenter(lonLat, 15);
+ map.addControl( new OpenLayers.Control.LayerSwitcher({'ascending':false}));
+ map.addControl(new OpenLayers.Control.MousePosition(
+ {
+ displayProjection: new OpenLayers.Projection("EPSG:4326"),
+ suffix: "__________________________________"
+ }));
+ map.addControl(new OpenLayers.Control.MousePosition(
+ {
+ displayProjection: new OpenLayers.Projection("EPSG:900913")
+ }));
+
+ select = new OpenLayers.Control.SelectFeature(stopbrowser);
+
+ stopbrowser.events.on({
+ "featureselected": onFeatureSelect,
+ "featureunselected": onFeatureUnselect
+ });
+
+ map.addControl(select);
+ select.activate();
+
+}
+ function onPopupClose(evt) {
+ select.unselectAll();
+ }
+ function onFeatureSelect(event) {
+ var feature = event.feature;
+ // Since KML is user-generated, do naive protection against
+ // Javascript.
+ var content = "<h2>"+feature.attributes.name + "</h2>" + feature.attributes.description;
+ if (content.search("<script") != -1) {
+ content = "Content contained Javascript! Escaped content below.<br />" + content.replace(/</g, "<");
+ }
+ popup = new OpenLayers.Popup.FramedCloud("chicken",
+ feature.geometry.getBounds().getCenterLonLat(),
+ new OpenLayers.Size(100,100),
+ content,
+ null, true, onPopupClose);
+ feature.popup = popup;
+ map.addPopup(popup);
+ }
+ function onFeatureUnselect(event) {
+ var feature = event.feature;
+ if(feature.popup) {
+ map.removePopup(feature.popup);
+ feature.popup.destroy();
+ delete feature.popup;
+ }
+ }
+ </script>
+
+ </head>
+ <body onload="init()">
+ <div id="map" width="100%" height="100%" class="smallmap"></div>
+ </body>
+</html>
+
+