--- a/betweenpoint.php +++ b/betweenpoint.php @@ -10,11 +10,46 @@ // create the ol map object var map = new OpenLayers.Map('map'); - var osmtiles = new OpenLayers.Layer.OSM("local", "http://127.0.0.1/tiles/${z}/${x}/${y}.png") + var osmtiles = new OpenLayers.Layer.OSM("local", "http://10.0.1.154/tiles/${z}/${x}/${y}.png") // use http://open.atlas.free.fr/GMapsTransparenciesImgOver.php and http://code.google.com/p/googletilecutter/ to make tiles markers = new OpenLayers.Layer.Markers("Between Stop Markers"); - + //hanlde mousedown on regions that are not points by reporting latlng +OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { + defaultHandlerOptions: { + 'single': true, + 'double': false, + 'pixelTolerance': 0, + 'stopSingle': false, + 'stopDouble': false + }, + + initialize: function(options) { + this.handlerOptions = OpenLayers.Util.extend( + {}, this.defaultHandlerOptions + ); + OpenLayers.Control.prototype.initialize.apply( + this, arguments + ); + this.handler = new OpenLayers.Handler.Click( + this, { + 'click': this.trigger + }, this.handlerOptions + ); + }, + + trigger: function(e) { + var lonlat = map.getLonLatFromViewPortPx(e.xy).transform( + new OpenLayers.Projection("EPSG:900913"), + new OpenLayers.Projection("EPSG:4326") + ); + $('form input[name="newlatlng"]').val(lonlat.lat + ";" + lonlat.lon ); + } + + }); + var click = new OpenLayers.Control.Click(); + map.addControl(click); + click.activate(); <?php $conn = pg_connect("dbname=bus user=postgres password=snmc"); if (!$conn) { @@ -34,7 +69,9 @@ marker.id="' . $stop['geohash'] . '"; markers.addMarker(marker); marker.events.register("mousedown", marker, function() { + document.getElementById("between_points").innerHTML += this.id+";"; +$(\'form input[name="oldgeopo"]\').val(this.id); }); '; } @@ -51,11 +88,31 @@ function submitBetween () { $.post("betweenpoint.submit.php", $("#inputform").serialize(), function(html){ $("#response").html(html); - //clearForms(); - return false; - }); -}; - + clearForms(); + return false; + }); +}; +function submitMove () { + $.post("betweenpoint.move.php", $("#moveform").serialize(), function(html){ + $("#response").html(html); + clearForms(); + return false; + }); +}; +function submitDelete () { + $.post("betweenpoint.delete.php", $("#moveform").serialize(), function(html){ + $("#response").html(html); + clearForms(); + return false; + }); +}; +function submitAdd () { + $.post("betweenpoint.add.php", $("#moveform").serialize(), function(html){ + $("#response").html(html); + clearForms(); + return false; + }); +}; function OnChange(dropdown) { var myindex = dropdown.selectedIndex @@ -129,7 +186,9 @@ // Strip off individual platforms because it usually doesn't matter for routes $timetable["time_points"] = preg_replace("/\(Platform.*/","",$timetable["time_points"]); for ($i = 0; $i < sizeof($timetable["time_points"]) - 1; $i++) { - @$paths[trim($timetable["time_points"][$i]) . "->" . trim($timetable["time_points"][$i + 1])] .= $timetable["short_name"] . ";"; + $key = trim($timetable["time_points"][$i]) . "->" . trim($timetable["time_points"][$i + 1]); + if (strstr($paths[$key],";" . $timetable["short_name"] . ";") === false) + @$paths[$key] .= $timetable["short_name"] . ";"; } } } @@ -139,28 +198,35 @@ $completedPaths = array(); $result_betweenstops = pg_query($conn, "Select * FROM between_stops"); while ($path = pg_fetch_assoc($result_betweenstops)) { - $completedPaths[trim($path['fromlocation']) . "->" . trim($path['tolocation'])] .= trim($path['routes']); - } - + $key = trim($path['fromlocation']) . "->" . trim($path['tolocation']); + $completedPaths[$key].= trim($path['routes']); + + } + + $processed = 0; foreach ($paths as $path => $routes) { if (!in_array($path, array_keys($completedPaths))) { - echo "<option value=\"$routes:$path\">" . sizeof(explode(";", $routes)) . " $path</option>\n"; + echo "<option value=\"$routes:$path\"> $path ($routes) </option>\n"; + $processed++; } else { $completedRoutes = explode(";", $completedPaths[$path]); $incompleteRoutes = ""; foreach (explode(";", $routes) as $route) { - if (!in_array($route,$completedRoutes)) { + if (!in_array($route,$completedRoutes) && strstr($incompleteRoutes,';'.$route.';') === false) { $incompleteRoutes .= $route.';'; } } - if ($incompleteRoutes != "") echo "<option value=\"$incompleteRoutes:$path\">" . sizeof(explode(";", $incompleteRoutes)) . " $path</option>\n"; + if ($incompleteRoutes != "") { + echo "<option value=\"$incompleteRoutes:$path\"> $path ($incompleteRoutes) </option>\n"; + $processed++; + } } } + echo "</select>$processed"; ?> -</select> from <input type="text" name="from" id="from"/> to <input type="text" name="to" id="to"/> <br> @@ -171,6 +237,13 @@ <br> <textarea name="between_points" id="between_points" rows="1" cols="120"></textarea> </form> + <form id="moveform"> +oldgeopo <input type="text" name="oldgeopo" id="oldgeopo"/> +newlatlng <input type="text" name="newlatlng" id="newlatlng" size="60"/> + <input type="button" onclick="javascript:submitMove()" value="Move!"> + <input type="button" onclick="javascript:submitAdd()" value="Add!"> + <input type="button" onclick="javascript:submitDelete()" value="Delete!"> +</form> <div id="response"> <!-- Our message will be echoed out here --> </div>