Django

Code

Show
Ignore:
Timestamp:
04/04/08 07:57:19 (9 months ago)
Author:
jbronn
Message:

gis: GoogleMap: The Google Maps JavaScript? API is now used for automatic zoom level determination; the center_lat and center_lon keywords have been removed.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/maps/google/gmap.py

    r7213 r7400  
    44from django.utils.safestring import mark_safe 
    55 
    6 # Declaring the GoogleMapException prior to getting the  
    7 # default `GZOOM` GoogleZoom instance. 
    86class GoogleMapException(Exception): pass 
    97from django.contrib.gis.maps.google.overlays import GPolygon, GPolyline 
    10 from django.contrib.gis.maps.google.zoom import GoogleZoom 
    11 GZOOM = GoogleZoom() 
    128 
    139# The default Google Maps URL (for the API javascript) 
     
    2319    xmlns    = mark_safe('xmlns:v="urn:schemas-microsoft-com:vml"') # XML Namespace (for IE VML). 
    2420 
    25     def __init__(self, key=None, api_url=None, version=None, 
    26                  center=None, center_lat=0.0, center_lon=0.0, 
    27                  zoom=None, dom_id='map', load_func='gmap_load',  
     21    def __init__(self, key=None, api_url=None, version=None,  
     22                 center=None, zoom=None, dom_id='map', load_func='gmap_load',  
    2823                 kml_urls=[], polygons=[], polylines=[], 
    2924                 template='gis/google/js/google-map.js', 
     
    7671                    self.polylines.append(GPolyline(pline)) 
    7772        
    78         # Automatically determining the zoom level if there are 
    79         # GPolygon and/or GPolyline overlays. 
    80         if (self.polygons or self.polylines) and zoom is None: 
    81             envelopes = [p.envelope for p in self.polygons] 
    82             envelopes.extend([p.envelope for p in self.polylines]) 
    83             # Creating a MultiPolygon of all the envelopes, this will 
    84             # be used in determining the zoom level. 
    85             zoom = geos.MultiPolygon(envelopes) 
    86             zoom.srid = 4326 
    87          
    88         # If a GEOSGeometry object is passed in for the `zoom` keyword 
    89         # argument, then try to automatically determine an appropriate 
    90         # zoom level. 
    91         if isinstance(zoom, geos.GEOSGeometry): 
    92             self.zoom = GZOOM.get_zoom(zoom) 
    93         else: 
    94             self.zoom = zoom 
    95  
    96         # The map center coordinate -- the `center_lon` and `center_lat` keyword 
    97         # are deprecated. 
    98         if not center: 
    99             center = (center_lon, center_lat) 
     73        # If GPolygons and/or GPolylines are used the zoom will be automatically 
     74        # calculated via the Google Maps API.  If both a zoom level and a 
     75        # center coordinate are provided with polygons/polylines, no automatic 
     76        # determination will occur. 
     77        self.calc_zoom = False 
     78        if self.polygons or self.polylines: 
     79            if center is None or zoom is None: 
     80                self.calc_zoom = True 
     81     
     82        # Defaults for the zoom level and center coordinates if the zoom 
     83        # is not automatically calculated. 
     84        if zoom is None: zoom = 4 
     85        self.zoom = zoom 
     86        if center is None: center = (0, 0) 
    10087        self.center = center 
    10188 
    10289        # Setting the parameters for the javascript template. 
    103         params = {'center' : self.center, 
     90        params = {'calc_zoom' : self.calc_zoom, 
     91                  'center' : self.center, 
    10492                  'dom_id' : self.dom_id, 
    10593                  'kml_urls' : self.kml_urls, 
  • django/branches/gis/django/contrib/gis/maps/google/__init__.py

    r7213 r7400  
    5757      version. 
    5858""" 
    59 from django.contrib.gis.maps.google.gmap import GoogleMap, GZOOM 
     59from django.contrib.gis.maps.google.gmap import GoogleMap 
    6060from django.contrib.gis.maps.google.overlays import GPolygon, GPolyline 
    6161from django.contrib.gis.maps.google.zoom import GoogleZoom