Did I find the right examples for you? yes no      Crawl my project      Python Jobs

# ModestMaps.calculateMapExtent

All Samples(1)  |  Call(1)  |  Derive(0)  |  Import(0)
```Based on a provider, width & height values, and a list of locations,
returns the coordinate of an initial tile and its point placement,
relative to the map center.
```

```        def calculateMapExtent(provider, width, height, *args):
""" Based on a provider, width & height values, and a list of locations,
returns the coordinate of an initial tile and its point placement,
relative to the map center.
"""
coordinates = map(provider.locationCoordinate, args)

TL = Core.Coordinate(min([c.row for c in coordinates]),
min([c.column for c in coordinates]),
min([c.zoom for c in coordinates]))

BR = Core.Coordinate(max([c.row for c in coordinates]),
max([c.column for c in coordinates]),
max([c.zoom for c in coordinates]))

# multiplication factor between horizontal span and map width
hFactor = (BR.column - TL.column) / (float(width) / provider.tileWidth())

# multiplication factor expressed as base-2 logarithm, for zoom difference
hZoomDiff = math.log(hFactor) / math.log(2)

# possible horizontal zoom to fit geographical extent in map width
hPossibleZoom = TL.zoom - math.ceil(hZoomDiff)

# multiplication factor between vertical span and map height
vFactor = (BR.row - TL.row) / (float(height) / provider.tileHeight())

# multiplication factor expressed as base-2 logarithm, for zoom difference
vZoomDiff = math.log(vFactor) / math.log(2)

# possible vertical zoom to fit geographical extent in map height
vPossibleZoom = TL.zoom - math.ceil(vZoomDiff)

# initial zoom to fit extent vertically and horizontally
initZoom = min(hPossibleZoom, vPossibleZoom)

## additionally, make sure it's not outside the boundaries set by provider limits
#initZoom = min(initZoom, provider.outerLimits().zoom)
#initZoom = max(initZoom, provider.outerLimits().zoom)

# coordinate of extent center
centerRow = (TL.row + BR.row) / 2
centerColumn = (TL.column + BR.column) / 2
centerZoom = (TL.zoom + BR.zoom) / 2
centerCoord = Core.Coordinate(centerRow, centerColumn, centerZoom).zoomTo(initZoom)

return calculateMapCenter(provider, centerCoord)
```

```        self.ctx['map'] = ModestMaps.mapByExtent(provider, sw, ne, dims)