Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD][12.0] google map drawing #289

Merged
merged 2 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions web_view_google_map/views/google_places_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
<t t-set="google_maps_api_key" t-value="request.env['ir.config_parameter'].sudo().get_param('google.api_key_geocode')"/>
<t t-set="google_maps_lang_localization" t-value="request.env['ir.config_parameter'].sudo().get_param('google.lang_localization')"/>
<t t-set="google_maps_region_localization" t-value="request.env['ir.config_parameter'].sudo().get_param('google.region_localization')"/>
<t t-set="google_maps_libraries" t-value="request.env['ir.config_parameter'].sudo().get_param('google.maps_libraries')"/>

This comment was marked as resolved.

<script src="/web_view_google_map/static/lib/markercluster/markerclusterer.js"></script>
<t t-if="google_maps_api_key">
<script t-attf-src="https://maps.googleapis.com/maps/api/js?v=quarterly&amp;libraries=geometry,places&amp;key=#{google_maps_api_key}&amp;#{google_maps_lang_localization}#{google_maps_region_localization}"></script>
<script t-attf-src="https://maps.googleapis.com/maps/api/js?v=quarterly&amp;libraries=#{google_maps_libraries}&amp;key=#{google_maps_api_key}&amp;#{google_maps_lang_localization}#{google_maps_region_localization}"></script>
</t>
<t t-if="not google_maps_api_key">
<script t-attf-src="https://maps.googleapis.com/maps/api/js?v=quarterly&amp;libraries=geometry,places#{google_maps_lang_localization}#{google_maps_region_localization}"></script>
<script t-attf-src="https://maps.googleapis.com/maps/api/js?v=quarterly&amp;libraries=#{google_maps_libraries}#{google_maps_lang_localization}#{google_maps_region_localization}"></script>
</t>
</template>
<template id="webclient_bootstrap" name="webclient_bootstrap gmaps" inherit_id="web.webclient_bootstrap">
Expand Down
35 changes: 35 additions & 0 deletions web_widget_google_map_drawing/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
**This file is going to be generated by oca-gen-addon-readme.**

*Manual changes will be overwritten.*

Please provide content in the ``readme`` directory:

* **DESCRIPTION.rst** (required)
* INSTALL.rst (optional)
* CONFIGURE.rst (optional)
* **USAGE.rst** (optional, highly recommended)
* DEVELOP.rst (optional)
* ROADMAP.rst (optional)
* HISTORY.rst (optional, recommended)
* **CONTRIBUTORS.rst** (optional, highly recommended)
* CREDITS.rst (optional)

Content of this README will also be drawn from the addon manifest,
from keys such as name, authors, maintainers, development_status,
and license.

A good, one sentence summary in the manifest is also highly recommended.


Automatic changelog generation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`HISTORY.rst` can be auto generated using `towncrier <https://pypi.org/project/towncrier>`_.

Just put towncrier compatible changelog fragments into `readme/newsfragments`
and the changelog file will be automatically generated and updated when a new fragment is added.

Please refer to `towncrier` documentation to know more.

NOTE: the changelog will be automatically generated when using `/ocabot merge $option`.
If you need to run it manually, refer to `OCA/maintainer-tools README <https://github.com/OCA/maintainer-tools>`_.
3 changes: 3 additions & 0 deletions web_widget_google_map_drawing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright Yopi Angi
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models
27 changes: 27 additions & 0 deletions web_widget_google_map_drawing/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright Yopi Angi
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Google Map View Drawing Mixin',
'summary': 'Add drawing tools to Google Map view in Odoo',
'version': '12.0.1.0.0',
'author': 'Yopi Angi, Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/geospatial',
'license': 'AGPL-3',
'category': 'Extra Tools',
'depends': [
'web_view_google_map',
],
'images': ['static/description/thumbnails.png'],
'data': [
'data/google_maps_library.xml',
'views/template.xml',
'views/res_config_settings_views.xml',
'security/ir.model.access.csv',
],
'qweb': ['static/src/xml/drawing.xml'],
'installable': True,
'maintainers': [
'gityopie',
'brian10048',
],
}
5 changes: 5 additions & 0 deletions web_widget_google_map_drawing/data/google_maps_library.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<odoo>
<data noupdate="1">
<function model="ir.config_parameter" name="set_param" eval="('google.maps_libraries', 'geometry,places,drawing')"/>
</data>
</odoo>
4 changes: 4 additions & 0 deletions web_widget_google_map_drawing/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright Yopi Angi
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import res_config_settings
from . import drawing_mixin
26 changes: 26 additions & 0 deletions web_widget_google_map_drawing/models/drawing_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright Yopi Angi
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo.tools import safe_eval


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)
42 changes: 42 additions & 0 deletions web_widget_google_map_drawing/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright Yopi Angi
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models, fields


class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'

google_maps_drawing = fields.Boolean(string='Drawing')

@api.multi
def set_values(self):
super(ResConfigSettings, self).set_values()
ICPSudo = self.env['ir.config_parameter'].sudo()
libraries = self._set_google_maps_drawing()
ICPSudo.set_param('google.maps_libraries', libraries)

@api.model
def get_values(self):
res = super(ResConfigSettings, self).get_values()
lib_drawing = self._get_google_maps_drawing()
res['google_maps_drawing'] = lib_drawing
return res

@api.model
def _get_google_maps_drawing(self):
ICPSudo = self.env['ir.config_parameter'].sudo()
google_maps_libraries = ICPSudo.get_param(
'google.maps_libraries', default='')
libraries = google_maps_libraries.split(',')
return 'drawing' in libraries

@api.multi
def _set_google_maps_drawing(self):
ICPSudo = self.env['ir.config_parameter'].sudo()
google_maps_libraries = ICPSudo.get_param(
'google.maps_libraries', default='')
libraries = google_maps_libraries.split(',')
if self.google_maps_drawing:
libraries.append('drawing')
result = ','.join(libraries)
return result
2 changes: 2 additions & 0 deletions web_widget_google_map_drawing/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Yopi Angi <yopiangi@gmail.com>
* Brian McMaster <brian@mcmpest.com>
11 changes: 11 additions & 0 deletions web_widget_google_map_drawing/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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)
75 changes: 75 additions & 0 deletions web_widget_google_map_drawing/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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

.. code-block:: python

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

.. code-block:: xml

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

How to load shape(s) on `map` view

.. code-block:: xml

<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>
2 changes: 2 additions & 0 deletions web_widget_google_map_drawing/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_google_map_drawing_shape_mixin,access_google_map_drawing_shape_mixin,model_google_map_drawing_shape_mixin,base.group_user,1,1,1,1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading