Hack GeoDjango Admin With Mapquest Tiles
The GeoDjango model admin provides a great OpenLayers interface, allowing a user to create geographic features (points, lines, polygons) directly via a web map. Out-of-the-box, GeoDjango ships with a base GeoAdmin class, using the default OL world borders layer, as well as a subclass for OSM streets data. The OSM layer is great, and provides a good base for most use cases. That being said, for PntTrax, I needed aerial tiles. My application deals primarily with the storage of field collected (GPS, field notes, aerial markup, etc.) data. Our data occur primarily in non-urban areas, where natural features provide a much better context for orientation then would be expected with any streets layer, OSM or otherwise. Mapquest provides a good set of aerial tiles, that can be easily integrated into OpenLayers.
It’s easier to place a point on this:
The OSMGeoAdmin class is a subclass of the base GeoModelAdmin. The GeoModelAdmin contains a set of configuration parameters for the map, covering basic setup. The OSMGeoAdmin class utilizes many of those configuration parameters, but configures the map for a spherical mercator projection. Since our Mapquest Aerial Tiles also require a spherical mercator projection, our class will be a subclass of the OSMGeoAdmin.
We add the following code below the OSMGeoAdmin class definition.
1 2 3 4
Modify the GIS Admin Package’s __init__.py
__init__.py file imports the
OSMGeoAdmin class, let’s modify it to include our
1 2 3 4
Again, using the OpenStreetMap implementation as a reference, we can see that
osm.js extends the basic
openlayers.js file, but replaces the contents of the
block with an a reference to the OpenStreetMap layer.
We’ll create a similar file in this package called
mapquest.js. The contents are as
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
We’ll call the file
mapquest.html. Here are the contents:
In admin.py, Reference mapquestGeoAdmin
The last step is to replace references to
1 2 3 4 5
And there you go. Your Django GeoAdmin interface is now rocking aerial tiles courtesy of Mapquest.