Skip to content

Commit

Permalink
init: version 1.0.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
brandboat committed Dec 9, 2014
1 parent ac8ec6b commit 188f877
Show file tree
Hide file tree
Showing 71 changed files with 12,991 additions and 369 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.swp
map.osm
./node_modules
3 changes: 3 additions & 0 deletions app/config/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var path = require('path');
var env = process.env.NODE_ENV || 'development';
var routes = require('../routes');
var errorHandler = require('errorhandler');
var favicon = require('serve-favicon');

module.exports = function (app, express) {
app.set('env', env);
Expand All @@ -20,6 +21,8 @@ module.exports = function (app, express) {
// ROUTES
app.use(routes);

app.use(favicon(path.join(app.config.root, 'public', 'favicon.ico')));

// load static files in /public
app.use(express.static(path.join(app.config.root, 'public')));

Expand Down
74 changes: 65 additions & 9 deletions app/controllers/route.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
exports.queryTime = function(req, res) {
var pg = require('pg');
var config = require('../config/config');
Expand All @@ -23,7 +24,7 @@ exports.queryTime = function(req, res) {
//output: Tue Jan 15 2013 19:12:47 GMT-600 (CST)
client.end();
});
}
}*/

exports.pgr_dijkstra = function(req, res) {
var pg = require('pg');
Expand All @@ -32,7 +33,9 @@ exports.pgr_dijkstra = function(req, res) {
//var conString = "postgres://" + config.database.username + ":"
// + config.database.password + "@localhost/" + config.database.dbname;
var client = new pg.Client(conString);
var reqPoint = [
var reqPoint = [];
/*
[
{
"lat": req.query.beginLat,
"lng": req.query.beginLng
Expand All @@ -41,31 +44,59 @@ exports.pgr_dijkstra = function(req, res) {
"lat": req.query.endLat,
"lng": req.query.endLng
}
];
];*/
var point = [];
var i = 0;
var i = 0, j = 0;
var queryStreets = [];



client.connect();
eliminate(req.query.latlngs);
getPoint();

// delete duplicate points.
function eliminate(latlngs) {
var q = latlngs;
reqPoint.push(q[0]);
for(var i = 1; i < q.length; i++) {
if(q[i].lat === q[i - 1].lat && q[i].lng === q[i - 1].lng) {
} else {
reqPoint.push(q[i]);
}
}
}

// get the nearest point of begin and end point in topology network(database).
function getPoint() {
if( i === reqPoint.length) {
return dijkstra(point[0], point[1]);
if(i === reqPoint.length) {
dijkstra(point[j], point[j + 1]);
j++;
return;
}
var qStr = "SELECT id FROM ways_vertices_pgr ORDER BY st_distance(the_geom, st_setsrid(st_makepoint(" + reqPoint[i].lng + "," + reqPoint[i].lat + "), 4326)) LIMIT 1;";
// console.log(qStr);

client.query(qStr, function(err,result) {
if(err) {
console.log(qStr);
return console.error('✗ Postgresql Running Query Error', err);
}
// console.log("%j", reqPoint[i]);
// console.log(result);
point[i++] = result.rows[0].id;
getPoint();
});
}

function dijkstra(begin, end) {
if(j === point.length - 1){
allDone(queryStreets);
return;
}

var qStr = "WITH result AS (SELECT * FROM ways JOIN (SELECT seq, id1 AS node, id2 AS edge_id, cost, ROW_NUMBER() OVER (PARTITION BY 1) AS rank FROM pgr_dijkstra('SELECT gid AS id, source::integer, target::integer, length::double precision AS cost FROM ways'," + begin + ", " + end + ", false, false)) AS route ON ways.gid = route.edge_id ORDER BY rank) SELECT ST_AsEWKT(result.the_geom), name from result;";
// console.log(qStr);
client.query(qStr, function(err, result) {
if(err) {
console.log(qStr);
Expand All @@ -85,7 +116,9 @@ exports.pgr_dijkstra = function(req, res) {
"coordinates": points
};
return geoJson;
} // parsing the result from query.
}

// parsing the result from query.
function parsingData(data) {
// the data is like : "SRID=4326;LINESTRING(120.2121912 22.9975817,120.2123558 22.9982876)"
var x = 0;
Expand All @@ -106,7 +139,31 @@ exports.pgr_dijkstra = function(req, res) {
var geoObj = toGeoJson(data[i].name, "LineString", points);
result[x++] = geoObj;
}
allDone(result);
collectLines(result);

}

function collectLines(result) {
var _result = [];
var road = "";
var lines = [];
for(var i = 0; i < result.length; i++) {
if(result[i].road !== road) {
var a = {
"road": road,
"lines": lines
};
_result.push(a);
lines = [];
}
road = result[i].road;
lines.push(result[i]);
}
_result.push({"road": road, "lines": lines});
queryStreets.push(_result);
dijkstra(point[j], point[j + 1]);
j++;
//allDone(_result);
}

function allDone(data) {
Expand All @@ -115,4 +172,3 @@ exports.pgr_dijkstra = function(req, res) {
client.end();
}
}

149 changes: 117 additions & 32 deletions app/views/route.jade
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,131 @@ html
meta(name="keywords" content="HTML, CSS, leaflet, JavaScript, openshift, nodejs, openstreetmap")
meta(name="viewport" content="width=device-width, initial-scale=1.0")
meta(name="author" content="brandboat")
link(href="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.css" rel="stylesheet")
link(href="/css/route.css" rel="stylesheet")
link(href="/semantic/packaged/css/semantic.min.css" rel="stylesheet")
link(href='http://fonts.googleapis.com/css?family=Source+Sans+Pro:400,700|Open+Sans:300italic,400,300,700' rel='stylesheet' type='text/css')
link(href="/semantic/packaged/css/semantic.min.css" rel="stylesheet")
link(href="/leaflet/leaflet.css" rel="stylesheet")
link(href="/LeafletMarkerCluster/MarkerCluster.css" rel="stylesheet")
link(href="/LeafletMarkerCluster/MarkerCluster.Default.css" rel="stylesheet")
script(src="/semantic/packaged/javascript/semantic.js" type="text/script")
script(src="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.js?2" type="text/javascript")
script(src="/leaflet/leaflet.js" type="text/javascript")
script(src="/LeafletMarkerCluster/leaflet.markercluster.js" type="text/javascript")
script(src="/javascripts/plugins/Leaflet.MakiMarkers.js" type="text/javascript")
script(src="http://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript")
script(src="//cdnjs.cloudflare.com/ajax/libs/jqueryui-touch-punch/0.2.2/jquery.ui.touch-punch.min.js")
title Routing-on-OSM
title Routing On Openstreetmap

body(onload="start()")
div(id="menu")
div(class="ui primary inverted segment")
body
div(class="ui dimmable dimmed" id="hidden-something")
div(class="ui simple dimmer")
div(class="ui segment" id="geocoder-menu")
div(class="ui divided list" id="geocoder-result")
div(class="ui red button" id="gui-button-cancel") Cancel
div(class="ui fixed inverted segment" id="headerPanel")
h1(class="ui inverted header")
div(class="content") Routing On Openstreetmap
<!--div(class="sub header") brandboat-->
div(class="ui fixed inverted vertical icon menu" id="leftPanel")
div(class="header item") My Trip
a(class="item" id="routing")
<i class="big road icon"></i> Routing
a(class="item" id="search")
<i class="big search icon"></i> Search
a(class="item" id="poi")
<i class="big map marker icon"></i> Things to do
div(class="ui vertically segment" id="routingFunction")
h2(class="ui header")
a(class="item")
<i class="location icon"></i> Routing
div(class="ui black header")
<i class="map marker icon"></i> Control Panel
div(class="ui form segmant")
div(class="inline fields")
div(class="ui button" id="begin") begin
div(class="field")
div(class="ui input")
input(type="text" placeholder="latitude" id="beginLat")
div(class="ui input")
input(type="text" placeholder="longitude" id="beginLng")
div(class="inline fields")
div(class="ui button" id="end") end
div(class="field")
div(class="ui input")
input(type="text" placeholder="latitude" id="endLat")
div(class="ui input")
input(type="text" placeholder="longitude" id="endLng")
div(class="ui buttons")
div(class="ui red button" id="reset") Reset
div(class="or")
div(class="ui green submit button" id="route") Route
div(class="ui black header")
<i class="road icon"></i> Road
div(id="road")
div(id="routing-menu-controll")
div(class="ui form")
div(class="ui inline fields")
div(class="ui inline field")
div(class="ui horizontal large label") Start:
div(class="ui input" id="input-source")
input(type="text" placeholder="Start..." id="gui-input-source")
div(class="ui inline field")
div(class="ui icon button" id="gui-reset-source")
i(class="remove icon")
div(class="ui inline fields")
div(class="ui inline field")
div(class="ui horizontal large label") End:
div(class="ui input" id="input-target")
input(type="text" placeholder="End..." id="gui-input-target")
div(class="ui inline field")
div(class="ui icon button" id="gui-reset-target")
i(class="remove icon")
div(class="ui inline field")
div(class="ui red button" id="gui-reset") Reset
div(id="menu-show")
div(id="road")
div(class="ui vertically segment" id="searchFunction")
h2(class="ui header")
a(class="item")
<i class="search icon"></i> Search
div(class="ui divider")
p Search for an Address or input the coordinate to add to your trip.
div(class="ui fluid large icon input")
input(type="text" placeholder="Search..." id="gui-input-search")
<i class="search icon"></i>
div(class="ui divider")
div(class="ui segment" id="search-point-result")
div(class="ui vertically segment" id="poiFunction")
h2(class="ui center aligned header")
a(class="item")
<i class="map marker icon"></i> Things to do
div(class="ui divider")
div(class="ui checkbox" id="artsEnterainment")
input(type="checkbox" name="artsEnterainment")
label Arts & Enterainment
div(class="ui divider")
div(class="ui checkbox" id="collegeUniversity")
input(type="checkbox" name="collegeUniversity")
label College & University
div(class="ui divider")
div(class="ui checkbox" id="food")
input(type="checkbox" name="food")
label Food
div(class="ui divider")
div(class="ui checkbox" id="nightLifeSpot")
input(type="checkbox" name="nightLifeSpot")
label NightLife Spot
div(class="ui divider")
div(class="ui checkbox" id="outdoorsRecreation")
input(type="checkbox" name="outdoorsRecreation")
label Outdoors Recreation
div(class="ui divider")
div(class="ui checkbox" id="professionalOthersPlaces")
input(type="checkbox" name="professionalOthersPlaces")
label Others Places
div(class="ui divider")
div(class="ui checkbox" id="residence")
input(type="checkbox" name="residence")
label Residence
div(class="ui divider")
div(class="ui checkbox" id="shopService")
input(type="checkbox" name="shopService")
label Shop Service
div(class="ui divider")
div(class="ui checkbox" id="travelTransport")
input(type="checkbox" name="travelTransport")
label Travel Transport
div(id="map")
script(type="text/javascript", src="/javascripts/route.js")

script(type="text/javascript", src="/javascripts/ROSM.base.js")
script(type="text/javascript", src="/javascripts/ROSM.classes.js")
script(type="text/javascript", src="/javascripts/ROSM.Map.js")
script(type="text/javascript", src="/javascripts/ROSM.Markers.js")
script(type="text/javascript", src="/javascripts/ROSM.Marker.js")
script(type="text/javascript", src="/javascripts/ROSM.Routing.js")
script(type="text/javascript", src="/javascripts/ROSM.Route.js")
script(type="text/javascript", src="/javascripts/ROSM.SimpleRoute.js")
script(type="text/javascript", src="/javascripts/ROSM.RoutingGeometry.js")
script(type="text/javascript", src="/javascripts/ROSM.RoutingDescription.js")
script(type="text/javascript", src="/javascripts/ROSM.GUI.js")
script(type="text/javascript", src="/javascripts/ROSM.JSON.js")
script(type="text/javascript", src="/javascripts/ROSM.GeoJson.js")
script(type="text/javascript", src="/javascripts/ROSM.Geocoder.js")
script(type="text/javascript", src="/javascripts/ROSM.POI.js")

script(type="text/javascript", src="/javascripts/main.js")
270 changes: 0 additions & 270 deletions index.html

This file was deleted.

75 changes: 75 additions & 0 deletions node_modules/serve-favicon/HISTORY.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 188f877

Please sign in to comment.