> For the complete documentation index, see [llms.txt](https://docs.lineverge.com/automail/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lineverge.com/automail/configurations/ui-configuration/site/panels/leafletmap.md).

# LeafletMap

Below is an example configuration of a panel using the **LeafletMap** module:

```python
{
    "full_row": True,
    "title": "World Map",
    "url_name": "frame_leaflet_map",
    "url_action_name": "panel_edb_map",
    "type": "Map",
    "width": 12,
    "height": 500,
    "content": {
        "view": custom_views.LeafletMapEdb,
        "view_params": {
            "model": custom_models.EdbCalculation,
            "order_by": "supplier__location__country_code_a2",
        },
        "url_params_list": [
            None,
            {"category": "str"},
        ],
    },
    "footer": {
        "select_name": "category",
        "select_values": {
            "self": "Total Risk Exposure Score",
            "social_and_labor": "Social & Labor Score",
            "health_and_safety": "Health & Safety Score",
            "environment": "Environment Score",
        },
        "col_classes": "col-md-6 col-sm-6 col-xs-6",
    },
},
```

The view\_params are:

* model the model this map is showing
* order\_by  the field in the model

The custom\_views can be defined as followed:

```python
class LeafletMapEdb(api_views.LeafletMap):

    category = "total_risk_exposure_score"

    def get_country_code_a2_map(self):

        def get_background_color(value):
            if value < 3:
                return "#FF5733"
            elif value < 6:
                return "#FFE4B3"
            else:
                return "#4CE64C"

        country_code_a2_map = {}

        queryset = self.get_queryset()
        if queryset.exists():
            country_risks = list(
                queryset
                .values(
                    "supplier__location__country_code_a2",
                    "social_and_labor",
                    "health_and_safety",
                    "environment",
                    "total_risk_exposure_score",
                )
                .distinct()
            )

            for country_risk in country_risks:
                country_code_a2 = country_risk["supplier__location__country_code_a2"].upper()
                country_code_a2_map[country_code_a2] = {
                    "background_color": get_background_color(country_risk.get(self.category, 0)),
                    "attributes": {
                        "Social & Labor Risk": round(
                            country_risk["social_and_labor"], 2
                        ),
                        "Health & Safety Risk": round(
                            country_risk["health_and_safety"], 2
                        ),
                        "Environment Risk": round(country_risk["environment"], 2),
                        "Total Risk Exposure": round(
                            country_risk["total_risk_exposure_score"], 2
                        ),
                    },
                    "image_url": None,
                    "url": None,
                    "custom_html": None,
                }

            return country_code_a2_map

    def get_marker_map(self):
        marker_map = {}
        queryset = self.get_queryset(
            exclude_filters={
                "supplier__latitude__isnull": True,
            }
        )
        if queryset.exists():
            edbcalculations = list(
                queryset.values(
                    "supplier__id",
                    "supplier__name", # title
                    "supplier__latitude",
                    "supplier__longitude",
                    "supplier__company_website",
                    "supplier__business_registration_number",
                    "supplier__factory_ffc",
                    "supplier__facility_street",
                    "supplier__facility_city",
                    "supplier__facility_state",
                    "social_and_labor",
                    "health_and_safety",
                    "environment",
                    "total_risk_exposure_score",
                    "fob_spend",
                ).distinct()
            )
            for edbcalculation in edbcalculations:
                marker_map[edbcalculation["supplier__id"]] = {
                    "coordinates": {
                        "latitude": edbcalculation["supplier__latitude"],
                        "longitude": edbcalculation["supplier__longitude"],
                    },
                    "title": '<a current_page_name="grid_search" class="menu_control_link" name="grid_search_result_{search_reference}{value}" menu_item="grid_search_group_container" href="#custom_web/grid_search_result_{search_reference}/{value}" target="{target}">{label}<i class="mdi mdi-open-in-new"></i></a>'.format(
                        value=edbcalculation["supplier__id"],
                        label=edbcalculation["supplier__name"],
                        search_reference="supplier",
                        target="_blank",
                    ),
                    "attributes": {
                        "BR#": edbcalculation["supplier__business_registration_number"],
                        "FFC#": edbcalculation["supplier__factory_ffc"],
                        "Province": edbcalculation["supplier__facility_state"],
                        "City": edbcalculation["supplier__facility_city"],
                        "Street": edbcalculation["supplier__facility_street"],
                        "Website": "<a href='{url}' target='_blank'>{url}</a>".format(
                            url=edbcalculation["supplier__company_website"]
                        )
                        if edbcalculation["supplier__company_website"]
                        else None,
                        "FOB Spend": str_utils.millions_formatter(edbcalculation["fob_spend"]),
                        # "Social & Labor Risk": round(edbcalculation["social_and_labor"], 2),
                        # "Health & Safety Risk": round(edbcalculation["health_and_safety"], 2),
                        # "Environment Risk": round(edbcalculation["environment"], 2),
                        # "Total Risk Exposure": round(
                        #     edbcalculation["total_risk_exposure_score"], 2
                        # ),
                    },
                    # "image_url": None,
                    # "custom_html": None,
                }

        return marker_map
```

Function get\_marker\_map can have all of the information about the supplier and show them on the map.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.lineverge.com/automail/configurations/ui-configuration/site/panels/leafletmap.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
