Opened 7 years ago

Last modified 46 hours ago

#11094 new Bug

default_lon and default_lat have no effect for OSMGeoAdmin

Reported by: stuartk Owned by: stuartk
Component: GIS Version: master
Severity: Normal Keywords: OSMGeoAdmin, gis
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When using the default_lon and default_lat options with OSMGeoAdmin, no changes are made to the presented map. The options work when using GeoModelAdmin.

Using the examples given on the Open Street Map wiki for using OpenLayers, I have created a small patch to the openlayers.js file. I have tested it, and it doesn't effect the use of GeoModelAdmin.

Attachments (1)

openlayers.diff (771 bytes) - added by stuartk 7 years ago.
Open Layers javascript file patch

Download all attachments as: .zip

Change History (8)

Changed 7 years ago by stuartk

Open Layers javascript file patch

comment:1 Changed 7 years ago by stuartk

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to stuartk
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 7 years ago by stuartk

When using the default_lon and default_lat options with OSMGeoAdmin, no changes are made to the presented map. The options work when using GeoModelAdmin.

Using the examples given on the Open Street Map wiki for using OpenLayers, I have created a small patch to the openlayers.js file. I have tested it, and it doesn't effect the use of GeoModelAdmin.

comment:3 Changed 7 years ago by stuartk

  • Version changed from 1.1-beta-1 to SVN

comment:4 Changed 7 years ago by jbronn

  • Resolution set to invalid
  • Status changed from assigned to closed

The default_lon and default_lat are not working for you because OSMGeoAdmin uses a different projection system than GeoModelAdmin. Specifically, OSMGeoAdmin uses the so-called "Google" projection (SRID=900913) and GeoModelAdmin uses WGS84 (SRID=4326). As such, just transform your default_lon and default_lat values to 900913:

>>> from django.contrib.gis.geos import Point
>>> pnt = Point(lon, lat, srid=4326)
>>> pnt.transform(900913)
>>> default_lon, default_lat = pnt.coords

comment:5 Changed 8 days ago by KJ

  • Easy pickings unset
  • Has patch unset
  • Resolution invalid deleted
  • Severity set to Normal
  • Status changed from closed to new
  • Type set to Bug
  • UI/UX unset

The comment above actually describes why this bug exists and how to make a workaround, not why it is not a bug. If I’m not mistaken, coordinates in the Web Mercator projection cannot be named “latitude” and “longitude”. Two ways to fix this (not excluding each other):

Ⓐ Assuming that default_lon and default_lat are always given using WGS84 projection and converting them automatically. (Though it would not break any documented behavior, such a change should be probably mentioned in release notes in the section which lists backwards incompatible changes).
Ⓑ Adding a field named default_center which would allow specifying an arbitrary django.contrib.gis.geos.Point object as map center. If no SRID is given, it can possibly be assumed that SRID is the same as the map_srid attribute of the model admin class. As this mechanism is more generic, it would be probably wise to deprecate default_lon and default_lat.

comment:6 Changed 3 days ago by timgraham

  • Summary changed from OSMGeoAdmin not accepting default_lon and default_lat to default_lon and default_lat have no effect for OSMGeoAdmin
  • Triage Stage changed from Unreviewed to Accepted

I'm not too knowledgeable about GIS, so I can't comment on the appropriate solution.

comment:7 Changed 46 hours ago by claudep

Option B is interesting. Patch welcome!

Note: See TracTickets for help on using tickets.
Back to Top