Changeset 4801
- Timestamp:
- 11/14/08 09:36:27 (2 months ago)
- Files:
-
- googlemapmacro/0.11/tracgooglemap/htdocs/tracgooglemap.js (modified) (2 diffs)
- googlemapmacro/0.11/tracgooglemap/macro.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
googlemapmacro/0.11/tracgooglemap/htdocs/tracgooglemap.js
r4714 r4801 55 55 // associated init function: 56 56 $("div.tracgooglemap") 57 .attr( 'id', function (index) {58 return 'tracgooglemap-' + index;59 })60 57 .each( function (index) { 61 58 var initfunc = tracgooglemapfuncs[index]; 62 59 if (initfunc) { 63 initfunc(this );60 initfunc(this, index); 64 61 } 65 62 }); … … 71 68 var key = $("link.google-key").attr('title'); 72 69 jQuery.getScript("http://www.google.com/jsapi?key=" + key, function () { 73 google.load("maps", "2 ", {"callback" : gmapiloaded})70 google.load("maps", "2.x", {"callback" : gmapiloaded}) 74 71 }); 75 72 } googlemapmacro/0.11/tracgooglemap/macro.py
r4761 r4801 9 9 from trac.core import * 10 10 from trac.util.html import escape,Markup 11 from trac .wiki.apiimport parse_args11 from tracadvparseargs import parse_args 12 12 from trac.wiki.formatter import extract_link 13 13 from trac.wiki.macros import WikiMacroBase … … 20 20 import re 21 21 22 COUNT = '_googlemapmacro_count' 23 22 24 _reWHITESPACES = re.compile(r'\s+') 23 25 _reCOMMA = re.compile(r',\s*') … … 40 42 //<![CDATA[ 41 43 42 TracGoogleMap( function (mapdiv ) {44 TracGoogleMap( function (mapdiv,index) { 43 45 var map = new GMap2(mapdiv, { 44 46 // size: new GSize(%(width)s, %(height)s), … … 63 65 } 64 66 %(markers_str)s 67 if ("%(directions)s") { 68 dirdiv = document.getElementById("tracgooglemap-directions-" + index); 69 gdir = new GDirections(map, dirdiv); 70 gdir.load("%(directions)s"); 71 } 65 72 }, "%(id)s" ); 66 73 … … 68 75 """ 69 76 70 class GoogleMapMacro(WikiMacroBase): 71 """ Provides a macro to insert Google Maps(TM) in Wiki pages 72 """ 77 class GoogleMapMacro (WikiMacroBase): 78 """ Provides a macro to insert Google Maps(TM) in Wiki pages.""" 73 79 implements(IRequestFilter,ITemplateProvider,IRequestFilter,IEnvironmentSetupParticipant) 74 80 … … 157 163 return address 158 164 159 def _parse_args(self, args, strict=True, sep = ',', quote = '"', kw = True, min = -1, num = -1):160 """ parses a comma separated string were the values can include multiple161 quotes """162 esc = 0 # last char was escape char163 quoted = 0 # inside quote164 start = 0 # start of current field165 pos = 0 # current position166 largs = []167 kwargs = {}168 169 def checkkey (arg):170 import re171 arg = arg.replace(r'\,', ',')172 if strict:173 m = re.match(r'\s*[a-zA-Z_]\w+=', arg)174 else:175 m = re.match(r'\s*[^=]+=', arg)176 if m:177 kw = arg[:m.end()-1].strip()178 if strict:179 kw = unicode(kw).encode('utf-8')180 kwargs[kw] = self._strip(arg[m.end():])181 else:182 largs.append(self._strip(arg))183 184 if args:185 for char in args:186 if esc:187 esc = 0188 elif char == quote:189 quoted = not quoted190 elif char == '\\':191 esc = 1192 elif char == sep and not quoted:193 checkkey( args[start:pos] )194 start = pos + 1195 pos = pos + 1196 checkkey( args[start:] )197 198 if num > 0:199 if len(largs) > num:200 largs = largs[0:num]201 elif len(largs) < num:202 min = num203 204 if min > 0 and min > len(largs):205 for i in range(len(largs), min):206 largs.append(None)207 208 if kw:209 return largs, kwargs210 else:211 return largs212 213 165 214 166 def _get_coords(self, address): … … 246 198 247 199 def expand_macro(self, formatter, name, content): 248 largs, kwargs = self._parse_args(content)200 largs, kwargs = parse_args(content, multi=['marker','to']) 249 201 if len(largs) > 0: 250 202 arg = unicode(largs[0]) 203 if _reCOORDS.match(arg): 204 if not 'center' in kwargs: 205 kwargs['center'] = arg 206 else: 207 if not 'address' in kwargs: 208 kwargs['address'] = arg 209 if 'from' in kwargs and not 'address' in kwargs and not 'center' in kwargs: 210 arg = unicode(kwargs['from']) 251 211 if _reCOORDS.match(arg): 252 212 if not 'center' in kwargs: … … 399 359 # Produce markers 400 360 markers_str = "" 361 if not 'marker' in kwargs: 362 kwargs['marker'] = [] 401 363 if 'markers' in kwargs: 364 kwargs['marker'].extend( parse_args( unicode(kwargs['markers']), delim='|', 365 listonly=True) ) 366 if kwargs['marker']: 402 367 markers = [] 403 for marker in self._parse_args(unicode(kwargs['markers']), sep='|', kw=False):404 location, letter, link, title = self._parse_args(marker,405 sep=';', kw=False, num=4 )368 for marker in kwargs['marker']: 369 location, letter, link, title = parse_args( marker, 370 delim=';', listonly=True, minlen=4 )[:4] 406 371 if not title: 407 372 title = link … … 440 405 markers_str = ''.join( markers ) 441 406 407 # Get macro count from request object 408 req = formatter.req 409 count = getattr (req, COUNT, 0) 410 id = 'tracgooglemap-%s' % count 411 setattr (req, COUNT, count + 1) 412 413 # Canvas for this map 414 mapdiv = tag.div ( 415 "Google Map is loading ... (JavaScript enabled?)", 416 id=id, 417 style = "width: %s; height: %s;" % (width,height), 418 class_ = "tracgooglemap" 419 ) 420 421 if 'from' in kwargs and 'to' in kwargs: 422 directions = "from: %s to: %s" % (kwargs['from'],' to: '.join(list(kwargs['to']))) 423 mapnmore = tag.table( 424 tag.tr( 425 tag.td( 426 tag.div( "", 427 class_ = 'tracgooglemap-directions', 428 id = 'tracgooglemap-directions-%s' % count 429 ), 430 style="vertical-align:top;", 431 ), 432 tag.td( 433 mapdiv, 434 style="vertical-align:top;", 435 ) 436 ), 437 class_ = 'tracgooglemaps' 438 ) 439 440 else: 441 directions = "" 442 mapnmore = mapdiv 443 442 444 # put everything in a tidy div 443 445 html = tag.div( … … 449 451 'type':type, 'width':width, 'height':height, 450 452 'types_str':types_str, 'controls_str':controls_str, 451 'markers_str':markers_str 453 'markers_str':markers_str, 'directions':directions, 452 454 }, 453 455 type = "text/javascript"), 454 # Canvas for this map 455 tag.div ( 456 "Google Map is loading ... (JavaScript enabled?)", 457 #id=id, 458 style = "width: %s; height: %s;" % (width,height), 459 class_ = "tracgooglemap" 460 ) 456 mapnmore 461 457 ], 462 458 class_ = "tracgooglemap-parent"
