Add description popups for trip times
--- a/include/common.inc.php
+++ b/include/common.inc.php
@@ -6,7 +6,7 @@
"phperror",
"awsotp",
//"squallotp",
- //"vanilleotp",
+ "vanilleotp",
"database",
"other"
);
--- a/labs/tripPlannerTester.kml.php
+++ b/labs/tripPlannerTester.kml.php
@@ -49,7 +49,7 @@
"latdeltasize" => $latdeltasize,
"londeltasize" => $londeltasize,
"regionname" => $md['key'],
- "plan" => $plan . "<br/><a href='" . htmlspecialchars($url) . "'>original plan</a>"
+ "plan" => $plan . '<br/><a href="' . htmlspecialchars($md['url']) . '">original plan</a>'
);
$regionTimes[] = $time;
}
@@ -137,8 +137,8 @@
"finishlon" => 149.1243,
)
);
-$latdeltasize = 0.025;
-$londeltasize = 0.025;
+$latdeltasize = 0.005;
+$londeltasize = 0.005;
$from = "Wattle Street";
$fromPlace = (startsWith($from, "-") ? $from : geocode($from, false));
$startTime = "9:00 am";
@@ -147,6 +147,7 @@
$regionTimes = Array();
$testRegions = Array();
$useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
+if ($kml) echo "<name> $from at $startTime on $startDate </name>";
if ($csv) echo "<pre>";
if ($csv) echo "lat,lon,time,latdeltasize, londeltasize, region key name\n";
$rc = new RollingCurl("processResult_cb");
@@ -155,11 +156,12 @@
for ($i = $boundingBox['startlat']; $i >= $boundingBox['finishlat']; $i-= $latdeltasize) {
for ($j = $boundingBox['startlon']; $j <= $boundingBox['finishlon']; $j+= $londeltasize) {
$url = $otpAPIurl . "ws/plan?date=" . urlencode($startDate) . "&time=" . urlencode($startTime) . "&mode=TRANSIT%2CWALK&optimize=QUICK&maxWalkDistance=440&wheelchair=false&toPlace=" . $i . "," . $j . "&fromPlace=$fromPlace";
+ //debug($url);
$request = new RollingCurlRequest($url);
$request->headers = Array(
"Accept: application/json"
);
- $request->metadata = Array( "i" => $i, "j" => $j, "key" => $key);
+ $request->metadata = Array( "i" => $i, "j" => $j, "key" => $key, "url" => $url);
$rc->add($request);
}
}
@@ -171,15 +173,14 @@
//$maxTime = max($regionTimes);
//$rangeTime = $maxTime - $minTime;
//$deltaTime = $rangeTime / $colorSteps;
-// $Gradients = Gradient(strrev("66FF00") , strrev("FF0000") , $colorSteps); // KML is BGR not RGB so strrev
- $Gradients = Gradient("66FF00" , "FF0000" , $colorSteps); // KML is BGR not RGB so strrev
+ $Gradients = Gradient(strrev("66FF00") , strrev("FF0000") , $colorSteps); // KML is BGR not RGB so strrev
foreach ($testRegions as $testRegion) {
//$band = (floor(($testRegion[time] - $minTime) / $deltaTime));
$band = (floor($testRegion[time] / 10));
if ($band > $colorSteps) $band = $colorSteps;
echo "<Placemark>
<name>" . $testRegion['regionname'] . " time {$testRegion['time']} band $band</name>
- <description> {$testRegion['plan']} </description>
+ <description> <![CDATA[ {$testRegion['plan']} ]]> </description>
<Style>
<PolyStyle>
<color>c7" . $Gradients[$band] . "</color>" . // 7f = 50% alpha, c7=78%
--- a/labs/tripPlannerTester.php
+++ b/labs/tripPlannerTester.php
@@ -3,7 +3,9 @@
<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);
@@ -16,13 +18,13 @@
};
// create the ol map object
- var map = new OpenLayers.Map('map', options);
+ map = new OpenLayers.Map('map', options);
var osmtiles = new OpenLayers.Layer.OSM("OSM");
var nearmap = new OpenLayers.Layer.OSM.NearMap("NearMap");
- var tripplantest = new OpenLayers.Layer.GML("tripplantest", "tripPlannerTester.kml.php", {
+ var tripplantest = new OpenLayers.Layer.GML("tripplantest", "tripPlannerTester.kml", {
format: OpenLayers.Format.KML,
formatOptions: {
extractStyles: true,
@@ -44,9 +46,45 @@
{
displayProjection: new OpenLayers.Projection("EPSG:900913")
}));
+
+ select = new OpenLayers.Control.SelectFeature(tripplantest);
+
+ tripplantest.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>