Skip to main content

Add drawing tools to Google Map view in Odoo

Project description

Beta License: AGPL-3 OCA/geospatial Translate me on Weblate Try me on Runboat

This module extends the Google Map web view in Odoo to allow users to draw polygons, rectangles, and circles on the map.

[![Demo](https://i.ytimg.com/vi/DDUFT6XP8AU/2.jpg)](https://youtu.be/DDUFT6XP8AU “Demo”)

More information about the drawing tools can be found [here](https://developers.google.com/maps/documentation/javascript/examples/drawing-tools)

This module will support three kind of shapes: - [Rectangle](https://developers.google.com/maps/documentation/javascript/examples/rectangle-simple) - [Polygon](https://developers.google.com/maps/documentation/javascript/examples/polygon-simple) - [Circle](https://developers.google.com/maps/documentation/javascript/examples/polygon-simple)

Table of contents

Usage

This module provides an extendable framework and cannot be used on its own. The following provides information on how to implement it for your own module.

## Drawing Mixin

To ease the implementation of this feature, a mixin class has been defined that you can use in your model

class GoogleMapDrawingShapeMixin(models.AbstractModel):
    _name = 'google.map.drawing.shape.mixin'
    _description = 'Google Maps Shape Mixin'
    _rec_name = 'shape_name'

    shape_name = fields.Char(string='Name')
    shape_area = fields.Float(string='Area')
    shape_radius = fields.Float(string='Radius')
    shape_description = fields.Text(string='Description')
    shape_type = fields.Selection([
        ('circle', 'Circle'),
        ('polygon', 'Polygon'),
        ('rectangle', 'Rectangle')],
        string='Type', default='polygon', required=True)
    shape_paths = fields.Text(string='Paths')

    @api.multi
    def decode_shape_paths(self):
        self.ensure_one()
        return safe_eval(self.shape_paths)

How to use the widget

<field name="shape_paths" widget="map_drawing_shape"/>

How to load shape(s) on map view

<record id="view_res_partner_area_map" model="ir.ui.view">
    <field name="name">view.res.partner.area.map</field>
    <field name="model">res.partner.area</field>
    <field name="arch" type="xml">
        <map library="drawing" string="Shape">
            <field name="partner_id"/>
            <field name="shape_name"/>
            <field name="shape_description"/>
            <field name="shape_type"/>
            <field name="shape_radius"/>
            <field name="shape_area"/>
            <field name="shape_paths"/>
            <templates>
                <t t-name="kanban-box">
                    <div class="oe_kanban_global_click">
                        <div class="oe_kanban_details">
                            <strong class="o_kanban_record_title oe_partner_heading">
                                <field name="shape_name"/>
                            </strong>
                            <div>
                                <field name="shape_description"/>
                            </div>
                            <div attrs="{'invisible': [('shape_type', 'not in', ['rectangle', 'polygon'])]}">
                                Area: <field name="shape_area"/>
                            </div>
                            <div attrs="{'invisible': [('shape_type', '!=', 'circle')]}">
                                Radius: <field name="shape_radius"/>
                            </div>
                        </div>
                    </div>
                </t>
            </templates>
        </map>
    </field>
</record>

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed feedback.

Do not contact contributors directly about support or help with technical issues.

Credits

Authors

  • Yopi Angi

Contributors

Maintainers

This module is maintained by the OCA.

Odoo Community Association

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

Current maintainers:

gityopie brian10048

This module is part of the OCA/geospatial project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

File details

Details for the file odoo12_addon_web_widget_google_map_drawing-12.0.1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for odoo12_addon_web_widget_google_map_drawing-12.0.1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f357df88bc2629b3c0de339ed597cae36d21cb30397a976231452d51a9866645
MD5 5b6dbdbd874255039fa49c1db2eb1041
BLAKE2b-256 fa0d2c641f4edfc666b6a24b5f2f01746f28586a3dfa53226088c5af356e42ad

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page