projection done on the back-end
This commit is contained in:
commit
f50124f634
|
@ -4,8 +4,9 @@ from django.contrib.auth.decorators import login_required
|
|||
|
||||
|
||||
def route(request, slug):
|
||||
srid = int(request.GET.get("srid", 4326))
|
||||
route = get_object_or_404_json(Route, slug=slug)
|
||||
stops = [r.stop.get_geojson() for r in RouteDetail.objects.filter(route=route)]
|
||||
stops = [r.stop.get_geojson(srid=srid) for r in RouteDetail.objects.filter(route=route)]
|
||||
return render_to_json_response({
|
||||
'route': route.get_dict(),
|
||||
'stops': {
|
||||
|
@ -15,8 +16,9 @@ def route(request, slug):
|
|||
})
|
||||
|
||||
def area(request, slug):
|
||||
srid = int(request.GET.get("srid", 4326))
|
||||
area = get_object_or_404_json(Area, slug=slug)
|
||||
stops = [stop.get_geojson() for stop in Stop.objects.filter(area=area)]
|
||||
stops = [stop.get_geojson(srid=srid) for stop in Stop.objects.filter(area=area)]
|
||||
return render_to_json_response({
|
||||
'area': area.get_dict(),
|
||||
'stops': {
|
||||
|
@ -44,12 +46,13 @@ def areas(request):
|
|||
|
||||
def stops(request):
|
||||
qset = Stop.objects.all()
|
||||
srid = int(request.GET.get("srid", 4326))
|
||||
if request.GET.has_key('q'):
|
||||
q = request.GET.get('q', '')
|
||||
qset = qset.filter(display_name__icontains=q) #FIXME: This definitely needs to be a Q object with OR lookups for area name, road name, etc.
|
||||
return render_to_json_response({
|
||||
'type': 'FeatureCollection',
|
||||
'features': [stop.get_geojson() for stop in qset]
|
||||
'features': [stop.get_geojson(srid=srid) for stop in qset]
|
||||
})
|
||||
|
||||
|
||||
|
@ -63,4 +66,5 @@ def stop(request, slug):
|
|||
return render_to_json_response(stop.from_geojson(request.POST))
|
||||
else:
|
||||
stop = get_object_or_404_json(Stop, slug=slug)
|
||||
return render_to_json_response(stop.get_geojson()) #FIXME: please don't repeat this code, its retarded.
|
||||
srid = int(request.GET.get("srid", 4326))
|
||||
return render_to_json_response(stop.get_geojson(srid=srid)) #FIXME: please don't repeat this code, its retarded.
|
||||
|
|
|
@ -122,6 +122,7 @@ class Stop(models.Model):
|
|||
}
|
||||
|
||||
def get_geojson(self, srid=4326):
|
||||
print srid
|
||||
if self.point is not None:
|
||||
geom = json.loads(self.point.transform(srid, True).geojson)
|
||||
else:
|
||||
|
|
|
@ -17,7 +17,7 @@ var API_BASE = "/1.0/",
|
|||
var $list = $('#' + name + 'List');
|
||||
var url = API_BASE + name + "/";
|
||||
var $loadingLi = $('<div />').text("Loading...").appendTo($list);
|
||||
$.getJSON(url, {}, function(items) {
|
||||
$.getJSON(url, {'srid': 3857}, function(items) {
|
||||
$loadingLi.remove();
|
||||
$.each(items, function(i,v) {
|
||||
var $li = $('<div />')
|
||||
|
@ -52,7 +52,7 @@ var API_BASE = "/1.0/",
|
|||
var url = API_BASE + name + "/" + $target.find(".listItemText").text();
|
||||
$target.data("loading", true);
|
||||
var $loading = $('<span />').addClass("loadingSpan").text("Loading...").appendTo($target);
|
||||
$.getJSON(url, {}, function(obj) {
|
||||
$.getJSON(url, {'srid': 3857}, function(obj) {
|
||||
$loading.remove();
|
||||
var stopsGeojson = obj.stops;
|
||||
var stops = stopsGeojson.features;
|
||||
|
@ -138,19 +138,20 @@ var API_BASE = "/1.0/",
|
|||
}
|
||||
|
||||
function initMap() {
|
||||
var center = new OpenLayers.LonLat(72.855211097628413, 19.010775291486027);
|
||||
map = new OpenLayers.Map("mapCol", {});
|
||||
var center = new OpenLayers.LonLat(8110203.9998955, 2170000.4068373);
|
||||
map = new OpenLayers.Map("mapCol", {
|
||||
projection: new OpenLayers.Projection("EPSG:900913")
|
||||
});
|
||||
var layers = [];
|
||||
// layers[0] = new OpenLayers.Layer.OSM();
|
||||
|
||||
layers[0] = new OpenLayers.Layer.Google(
|
||||
"Google Streets", // the default
|
||||
{numZoomLevels: 20, isBaseLayer: true}
|
||||
);
|
||||
|
||||
layers[0] = new OpenLayers.Layer.OSM();
|
||||
geojson_format = new OpenLayers.Format.GeoJSON();
|
||||
//yes, jsonLayer is global. Yes, I know it's wrong.
|
||||
jsonLayer = layers[1] = new OpenLayers.Layer.Vector({'geometryType': 'Point'});
|
||||
jsonLayer = layers[1] = new OpenLayers.Layer.Vector({
|
||||
geometryType: 'Point',
|
||||
projection: new OpenLayers.Projection("EPSG:4326")
|
||||
});
|
||||
// map.addLayer(vector_layer);
|
||||
map.addLayers(layers);
|
||||
map.setCenter(center, 12);
|
||||
|
|
Loading…
Reference in New Issue
Block a user