Login

ReST google-map directive.

Author:
mucius
Posted:
May 17, 2013
Language:
Python
Version:
Not specified
Tags:
restructuredtext google-map directive docutils
Score:
0 (after 0 ratings)

Use this directive to show google-map if you don't want to use 'raw' directive. default location is my favorite place. Of course you can change it :)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from docutils import nodes
from docutils.parsers.rst import directives, Directive


FORM1 = (
    u'<div id="{0}" class="rst-gmap" style="width:{1}; height:{2}">\r\n'
    u'</div>\r\n'
    u'<script type="text/javascript">$(function(){{\r\n'
    u'  show_gmap("{0}", {3}, {4}, {5}, "{6}");\r\n'
    u'}})</script>'
)


class Gmap(Directive):
    """ Google map directive """
    required_arguments = 1
    optional_arguments = 0
    final_argument_whitespace = False
    option_spec = {
        'height': directives.length_or_unitless,
        'width': directives.length_or_percentage_or_unitless,
        'zoom': directives.nonnegative_int,
        'latlng' : directives.unchanged,
        'title': directives.unchanged,
    }

    def run(self):
        map_id = self.arguments[0].strip()
        val = {
            'height': '240px',
            'width' : '320px',
            'zoom' : '15',
            'latlng' : '60.996572,24.462588',
            'title' : 'here!',
        }
        for options in ['height', 'width', 'zoom', 'latlng', 'title']:
            if options in self.options:
                val[options] = self.options[options]
        try:
            latitude, longitude = [x.strip() for x in val['latlng'].split(',')]
        except ValueError:
            raise self.error('Invalid latitude and/or longitude value.')
        try:
            html = FORM1.format(map_id, val['width'], val['height'],
                                latitude, longitude, val['zoom'], val['title'])
        except IOError:
            raise self.error('Could not convert to html. please contact to author.')
        return [nodes.raw('', html, format='html')]


directives.register_directive('gmap', Gmap)

More like this

  1. Django google maps v3 snipplet by summerisgone 5 years ago
  2. Get Latitude and Longitude from google maps by b23 7 years, 8 months ago
  3. Google Map Field and Widget by javinievas 7 years, 2 months ago
  4. Google map on admin address field by coulix 4 years, 11 months ago
  5. Google Maps Templatetag by javinievas 8 years, 1 month ago

Comments

Please login first before commenting.