| 319 | | |
|---|
| 320 | | def send_map (self, img) : |
|---|
| | 326 | |
|---|
| | 327 | def add_markers (self, mmap, img, args) : |
|---|
| | 328 | |
|---|
| | 329 | # note the mmap-iness of the 'map' object |
|---|
| | 330 | # apparently python is too stupid not to |
|---|
| | 331 | # confuse it with its own 'map' function... |
|---|
| | 332 | |
|---|
| | 333 | coords = {} |
|---|
| | 334 | |
|---|
| | 335 | for details in args['markers'] : |
|---|
| | 336 | res = self.add_marker2(mmap, img, details) |
|---|
| | 337 | |
|---|
| | 338 | label = "Marker-%s" % details['label'] |
|---|
| | 339 | |
|---|
| | 340 | if res : |
|---|
| | 341 | coords[label] = ",".join(map(str, res)) |
|---|
| | 342 | else : |
|---|
| | 343 | coords[label] = "FAIL" |
|---|
| | 344 | |
|---|
| | 345 | return coords |
|---|
| | 346 | |
|---|
| | 347 | # ########################################################## |
|---|
| | 348 | |
|---|
| | 349 | def add_marker2(self, map, img, args) : |
|---|
| | 350 | |
|---|
| | 351 | try : |
|---|
| | 352 | loc = ModestMaps.Geo.Location(args['latitude'], args['longitude']) |
|---|
| | 353 | pt = map.locationPoint(loc) |
|---|
| | 354 | except Exception, e : |
|---|
| | 355 | print "OH NOES %s" % e |
|---|
| | 356 | return False |
|---|
| | 357 | |
|---|
| | 358 | marker = self.get_marker(args) |
|---|
| | 359 | |
|---|
| | 360 | if args.has_key('fill') : |
|---|
| | 361 | marker = self.fill_marker(img, marker, args) |
|---|
| | 362 | |
|---|
| | 363 | x = int(pt.x) |
|---|
| | 364 | y = int(pt.y) |
|---|
| | 365 | |
|---|
| | 366 | mx = x - 28 |
|---|
| | 367 | my = y - 134 |
|---|
| | 368 | |
|---|
| | 369 | img.paste(marker, (mx, my), marker) |
|---|
| | 370 | return (x, y, mx, my) |
|---|
| | 371 | |
|---|
| | 372 | # ########################################################## |
|---|
| | 373 | |
|---|
| | 374 | def fill_marker(self, img, marker, args) : |
|---|
| | 375 | |
|---|
| | 376 | if args['provider'] == args['marker'] : |
|---|
| | 377 | offset = 75 / 2 |
|---|
| | 378 | nw = (x / 2) - offset |
|---|
| | 379 | se = (y / 2) + offset |
|---|
| | 380 | thumb = img.crop((nw, nw, se, se)) |
|---|
| | 381 | |
|---|
| | 382 | else : |
|---|
| | 383 | args['height'] = 75 |
|---|
| | 384 | args['width'] = 75 |
|---|
| | 385 | args['provider'] = args['marker'] |
|---|
| | 386 | args['marker'] = '' |
|---|
| | 387 | args['dither'] = 0 |
|---|
| | 388 | thumb = self.draw_map(args) |
|---|
| | 389 | |
|---|
| | 390 | # |
|---|
| | 391 | |
|---|
| | 392 | marker.paste(thumb, (11, 10)) |
|---|
| | 393 | return marker |
|---|
| | 394 | |
|---|
| | 395 | # ########################################################## |
|---|
| | 396 | |
|---|
| | 397 | def send_map (self, img, meta) : |
|---|
| | 567 | |
|---|
| | 568 | # |
|---|
| | 569 | # markers? (the new new) |
|---|
| | 570 | # |
|---|
| | 571 | |
|---|
| | 572 | if params.has_key('markers') : |
|---|
| | 573 | |
|---|
| | 574 | valid['markers'] = [] |
|---|
| | 575 | |
|---|
| | 576 | for pos in params['markers'] : |
|---|
| | 577 | |
|---|
| | 578 | marker_data = {} |
|---|
| | 579 | |
|---|
| | 580 | details = pos.split(",") |
|---|
| | 581 | details = map(string.strip, details) |
|---|
| | 582 | |
|---|
| | 583 | if len(details) < 3 : |
|---|
| | 584 | self.error(101, "Missing or incomplete %s parameter : %s" % ('marker', pos)) |
|---|
| | 585 | return False |
|---|
| | 586 | |
|---|
| | 587 | if not re_label.match(details[0]) : |
|---|
| | 588 | self.error(102, "Not a valid marker label : %s" % pos) |
|---|
| | 589 | return False |
|---|
| | 590 | |
|---|
| | 591 | marker_data['label'] = unicode(details[0]) |
|---|
| | 592 | |
|---|
| | 593 | if not re_coord.match(details[1]) : |
|---|
| | 594 | self.error(102, "Not a valid lat/long : %s" % pos) |
|---|
| | 595 | return False |
|---|
| | 596 | |
|---|
| | 597 | marker_data['latitude'] = float(details[1]) |
|---|
| | 598 | |
|---|
| | 599 | if not re_coord.match(details[2]) : |
|---|
| | 600 | self.error(102, "Not a valid lat/long : %s" % pos) |
|---|
| | 601 | return False |
|---|
| | 602 | |
|---|
| | 603 | marker_data['longitude'] = float(details[2]) |
|---|
| | 604 | |
|---|
| | 605 | if len(details) > 3 : |
|---|
| | 606 | |
|---|
| | 607 | if not re_provider.match(details[3].upper()) : |
|---|
| | 608 | self.error(102, "Not a valid marker provider") |
|---|
| | 609 | return False |
|---|
| | 610 | |
|---|
| | 611 | marker_data['fill'] = unicode(details[3]) |
|---|
| | 612 | |
|---|
| | 613 | valid['markers'].append(marker_data) |
|---|