Skip to content

Commit

Permalink
Initial Commit. Created openlayers map and click event handled
Browse files Browse the repository at this point in the history
  • Loading branch information
justjkk committed May 12, 2011
0 parents commit 4bc9c91
Show file tree
Hide file tree
Showing 73 changed files with 3,212 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.pyc
*~
configuration.py
12 changes: 12 additions & 0 deletions configuration.sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copy this file to configuration.py and enter the real configuration values

CONNECTION_SETTINGS = {
"host" : "localhost", # host where database server is located
"port" : "", # if postgreSQL runs on a TCP port
"dbname" : "dotpath",
"user" : "test",
"password" : "test" # if using md5 or password authentication
}

DEBUG = False # Set to True on development systems; False on production systems

14 changes: 14 additions & 0 deletions dbhelper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import psycopg2

def connect_to_DB(connection_settings):
connstr = "host=" + connection_settings["host"] + " "
if connection_settings["port"] != "":
connstr += "port=" + connection_settings["port"] + " "
connstr += "dbname=" + connection_settings["dbname"] + " "
connstr += "user=" + connection_settings["user"] + " "
connstr += "password=" + connection_settings["password"]

conn = psycopg2.connect(connstr)
conn.set_isolation_level(0)
return conn

35 changes: 35 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python

from flask import Flask, render_template, g, request, abort, make_response

from dbhelper import connect_to_DB

app = Flask(__name__)
app.config.from_object('configuration')

db = connect_to_DB(app.config['CONNECTION_SETTINGS'])

@app.before_request
def before_request():
g.cur = db.cursor()

@app.after_request
def after_request(response):
g.cur.close()
return response

@app.route("/routing.js", methods=["GET"])
def routing_js():
if not "start_location" in request.args or not "finish_location" in request.args:
abort(404)
data = request.args
response = make_response(render_template('routing.js', data=data), 200)
response.headers["Content-Type"] = "text/javascript; charset=utf-8"
return response

@app.route("/")
def index():
return render_template('index.html')

if __name__ == "__main__":
app.run()
13 changes: 13 additions & 0 deletions static/css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
body {
margin: 50px 0;
}

#map-container {
width: 600px;
margin: 0px auto;
}

#map {
width: 600px;
height: 480px;
}
Binary file added static/img/checkered_flag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/start_flag.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,553 changes: 2,553 additions & 0 deletions static/js/OpenLayers.js

Large diffs are not rendered by default.

Binary file added static/js/img/blank.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/cloud-popup-relative.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/drag-rectangle-off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/drag-rectangle-on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/east-mini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/layer-switcher-maximize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/layer-switcher-minimize.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/marker-blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/marker-gold.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/marker-green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/marker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/measuring-stick-off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/measuring-stick-on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/north-mini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/panning-hand-off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/panning-hand-on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/slider.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/south-mini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/west-mini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/zoom-minus-mini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/zoom-plus-mini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/zoom-world-mini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/js/img/zoombar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions static/js/jquery.js

Large diffs are not rendered by default.

124 changes: 124 additions & 0 deletions static/js/scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
function CreateMap() {

// Create Openlayers Map object
map = new OpenLayers.Map({
div: "map",
controls:[
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.LayerSwitcher()
],
allOverlays: true,
});

// Create Icons for markers
var iconSize = new OpenLayers.Size(32,32);
var iconOffset = new OpenLayers.Pixel(-4,-32);
var start_icon = new OpenLayers.Icon("/static/img/start_flag.png", iconSize, iconOffset);
var finish_icon = new OpenLayers.Icon("/static/img/checkered_flag.png", iconSize, iconOffset);

// Add OSM Baselayer
var osm = new OpenLayers.Layer.OSM();
map.addLayer(osm);

// Position map zoomed on Chennai
map.setCenter(
new OpenLayers.LonLat(80.2, 13.02).transform(
new OpenLayers.Projection("EPSG:4326"),
map.getProjectionObject()
),
11 // <- default zoom level
);

// Create pointsLayer which contains start and stop markers
var pointsLayer = new OpenLayers.Layer.Markers("Points");
map.addLayer(pointsLayer);

// Initialize markers
start_marker = null;
finish_marker = null;

// Create Click class to handle clicking on Map
OpenLayers.Control.Click = OpenLayers.Class(
OpenLayers.Control,
{
defaultHandlerOptions: {
'single': true,
'double': false,
'pixelTolerance': 0,
'stopSingle': false,
'stopDouble': false
},

initialize: function(options) {
OpenLayers.Control.prototype.initialize.apply(
this, arguments
);
this.handler = new OpenLayers.Handler.Click(
this,
{
'click': this.trigger
}
);
},

// Event Handler for click
trigger: function(e) {
if(start_marker == null) // First click sets Start marker
{
if(finish_marker != null)
pointsLayer.removeMarker(finish_marker);
start_marker = new OpenLayers.Marker(
map.getLonLatFromViewPortPx(e.xy),
start_icon.clone()
);
pointsLayer.addMarker(start_marker);
}
else if(finish_marker == null) // Second click sets Finish
// marker and draws route
{
finish_marker = new OpenLayers.Marker(
map.getLonLatFromViewPortPx(e.xy),
finish_icon.clone()
);
pointsLayer.addMarker(finish_marker);

// Convert coordinates to 4326 projection
var start_lonlat = start_marker.lonlat.clone().transform(
map.getProjectionObject(),
new OpenLayers.Projection("EPSG:4326")
);
var finish_lonlat = finish_marker.lonlat.clone().transform(
map.getProjectionObject(),
new OpenLayers.Projection("EPSG:4326")
);

// Make AJAX request to fetch routing data
$.ajax('/routing.js?start_location=' + start_lonlat +
'&finish_location=' + finish_lonlat);
}
else // Third click resets the map
{
if(start_marker != null)
{
pointsLayer.removeMarker(start_marker);
start_marker.destroy();
start_marker = null;
}
if(finish_marker != null)
{
pointsLayer.removeMarker(finish_marker);
finish_marker.destroy();
finish_marker = null;
}
}
}
}
);

// Bind click event handler to map
var click = new OpenLayers.Control.Click();
map.addControl(click);
click.activate()
}
Empty file.
10 changes: 10 additions & 0 deletions static/js/theme/default/google.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.olLayerGoogleCopyright {
right: 3px;
bottom: 2px;
left: auto;
}
.olLayerGooglePoweredBy {
left: 2px;
bottom: 2px;
}

7 changes: 7 additions & 0 deletions static/js/theme/default/ie6-style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.olControlZoomPanel div {
background-image: url(img/zoom-panel-NOALPHA.png);
}
.olControlPanPanel div {
background-image: url(img/pan-panel-NOALPHA.png);
}

Binary file added static/js/theme/default/img/add_point_off.png
Binary file added static/js/theme/default/img/add_point_on.png
Binary file added static/js/theme/default/img/blank.gif
Binary file added static/js/theme/default/img/close.gif
Binary file added static/js/theme/default/img/drag-rectangle-on.png
Binary file added static/js/theme/default/img/draw_line_off.png
Binary file added static/js/theme/default/img/draw_line_on.png
Binary file added static/js/theme/default/img/draw_point_off.png
Binary file added static/js/theme/default/img/draw_point_on.png
Binary file added static/js/theme/default/img/draw_polygon_off.png
Binary file added static/js/theme/default/img/draw_polygon_on.png
Binary file added static/js/theme/default/img/editing_tool_bar.png
Binary file added static/js/theme/default/img/move_feature_off.png
Binary file added static/js/theme/default/img/move_feature_on.png
Binary file added static/js/theme/default/img/pan-panel-NOALPHA.png
Binary file added static/js/theme/default/img/pan-panel.png
Binary file added static/js/theme/default/img/pan_off.png
Binary file added static/js/theme/default/img/pan_on.png
Binary file added static/js/theme/default/img/panning-hand-off.png
Binary file added static/js/theme/default/img/panning-hand-on.png
Binary file added static/js/theme/default/img/remove_point_off.png
Binary file added static/js/theme/default/img/remove_point_on.png
Binary file added static/js/theme/default/img/ruler.png
Binary file added static/js/theme/default/img/save_features_off.png
Binary file added static/js/theme/default/img/save_features_on.png
Binary file added static/js/theme/default/img/view_next_off.png
Binary file added static/js/theme/default/img/view_next_on.png
Binary file added static/js/theme/default/img/view_previous_off.png
Binary file added static/js/theme/default/img/view_previous_on.png
Binary file added static/js/theme/default/img/zoom-panel.png
Loading

0 comments on commit 4bc9c91

Please sign in to comment.