Changeset 520
- Timestamp:
- 03/17/08 22:54:13 (8 months ago)
- Files:
-
- trunk/py/wscompose/__init__.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/py/wscompose/__init__.py
r519 r520 262 262 img.save(fh, "PNG") 263 263 264 js = "{\"data\":\"%s\"})" % base64.b64encode(fh.getvalue()) 264 # this probably means it's time to 265 # invest in a templating system... 266 267 js = "{" 268 269 js += "\"X-wscompose-Image-Height:\"%s\"," % img.size[1] 270 js += "\"X-wscompose-Image-Width:\"%s\"," % img.size[0] 271 js += "\"X-wscompose-Map-Zoom\":\"%s\"," % self.ctx['zoom'] 272 273 if self.ctx.has_key('plots') : 274 for data in self.ctx['plots'] : 275 276 pt = self.latlon_to_point(data['latitude'], data['longitude']) 277 278 header = "X-wscompose-Plot-%s" % data['label'] 279 coords = "%s,%s" % (int(pt.x), int(pt.y)) 280 281 js += "\"%s\":\"%s\"," % (header, coords) 282 283 js += "\"data\":\"%s\"" % base64.b64encode(fh.getvalue()) 284 js += "}" 265 285 266 286 if self.ctx.has_key('json_callback') : … … 507 527 if params.has_key('output') : 508 528 509 if params['output'][0] == 'javascript' : 510 pass 511 512 elif params['output'][0] == 'json' : 529 out = params['output'][0].lower() 530 531 if out == 'json' : 532 valid['output'] = 'json' 533 534 elif out == 'javascript' : 513 535 if not params.has_key('callback') : 514 536 self.error(142, 'Missing JSON callback') … … 520 542 self.error(143, e) 521 543 return False 544 545 valid['output'] = 'json' 546 547 elif out == 'png' : 548 # set above 549 pass 550 522 551 else : 523 self.error(144, "Not a valid output format") 524 return False 525 526 valid['output'] = 'json' 527 552 self.error(144, 'Not a valid output format') 553 return False 528 554 529 555 # … … 591 617 self.help_option('bbox', 'A bounding box comprised of comma-separated decimal coordinates in the following order : SW latitude, SW longitude, NE latitude, NE longitude', True, 2) 592 618 self.help_option('accuracy', 'The zoom level / accuracy (as defined by ModestMaps rather than any individual tile provider) of the final image.', True, 2) 619 620 self.help_option('output', 'Although the default output format for maps is \'png\' (you know, like a PNG image file) you may also specify the following alternatives: ', False) 621 self.help_option('json', 'Return a Base64 encoded version of a PNG image, as well as any extra X-wscompose headers, as JSON data structure.', False, 1) 622 self.help_option('javascript', 'Return a Base64 encoded version of a PNG image, as well as any extra X-wscompose headers, as JSON data structure wrapped in a function whose name is defined by the \'callback\' parameter.', False, 1) 623 self.help_option('callback', 'Required if the output format is \'javascript\'; this is the name of the callback function that your JSON data structure will be wrapped in.', False) 593 624 594 625 self.help_option('plot', 'Plot -- but do not render -- the x and y coordinates for a given point. Coordinate data will be returned HTTP header(s) named \'X-wscompose-plot-\' followed by the label you choose when passing latitude and longitude information. You may pass multiple plot arguments, each of which should contain the following comma separated values :', False)
