# Variables in GeoJSON Style rules

**URL:** <https://community.grafana.com/t/variables-in-geojson-style-rules/104951>\
**Category:** Geomap Panel\
**Created:** [October 5, 2023, 10:04am UTC](https://community.grafana.com/t/variables-in-geojson-style-rules/104951 "2023-10-05T10:04:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rafalzuchnik](https://avatars.discourse-cdn.com/v4/letter/r/d26b3c/32.png) [@rafalzuchnik](https://community.grafana.com/u/rafalzuchnik)\
**Post date:** [October 5, 2023, 10:04am UTC](https://community.grafana.com/t/variables-in-geojson-style-rules/104951/1 "2023-10-05T10:04:02Z")

</div>

Hello everybody. I’m trying to use Geomap with GeoJSON layer which represents my area divided into smaller areas. I want to color each area based on sql query and value mapping but as I see, Style rules can only get static values (no variables and colors from value mapping). Is there any way to get coloured areas where color of each area will be based on variables from sql query and value mapping?

 ![Screenshot_20231005_115740](https://us1.discourse-cdn.com/grafana/original/3X/8/4/847db0951dd20884e7c0b212091ffc8f869fcbbd.png)

as you see there is fixed CLUSTER\_ID and color and I need to use variable for CLUSTER\_ID and color from value mapping.

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [October 5, 2023, 5:51pm UTC](https://community.grafana.com/t/variables-in-geojson-style-rules/104951/2 "2023-10-05T17:51:19Z")

</div>

So you would like to while displaying all of them color differently based on a variable change?

Check this thread out.

> [@Geomap: represent data with coloured areas](https://community.grafana.com/t/geomap-represent-data-with-coloured-areas/67616):
>
> Hi, is there a way to link geojson files to queries? we need to represent statistical data for areas. Create a new geojson for every value or set of values is not viable, we have hundreds of maps and thousands of values. It could be very useful link table to geojson data with a key field.

Since you want it to be dynamic reading things from a local file is going to be difficult if not impossible to do styling changes.

if you serve the geojson data from an api service maybe you can use CSS styles to modify your points, line, polygons with thickness & color? Not sure if it will be picked up by grafana geomap plugin though

> <https://gis.stackexchange.com/questions/22474/geojson-styling-information>

```auto
{ 
    "type": "Feature",
    "geometry": {
    "type": "Polygon",
    "coordinates": [[
        [-180.0, 10.0], [20.0, 90.0], [180.0, -5.0], [-30.0, -90.0]
        ]]
    },
    "style": {
        "__comment": "all SVG styles allowed",
        "fill":"red",
        "stroke-width":"3",
        "fill-opacity":0.6
    },
    "className": {
        "baseVal":"A class name"
    }
}

```

Also looks like someone already posted this issue

> <https://github.com/grafana/grafana/issues/71054>
>
> \### 
> \# What went wrong?
> 
> 
> \*\*What happened\*\*:
>  
> !\[изображение\](https://gith…ub.com/grafana/grafana/assets/9244347/de8f6643-aee2-42ff-93c9-1d8c2b59a6d5)
> 
> I created a variable ("cn") to be able to choose one of the properties, which match to custom geoJSON properties.
> Now I want to use this variable inside style rule (see attachment)
> But it doesn't work ("not found" error).
> 
> \*\*What did you expect to happen\*\*:
> 
> GeoMap style rule should work with variable
> 
> 
> 
> \### 
> \# How do we reproduce it?
> 
> 
> \*\*Step 1\*\*:
> 
> \- Open \[Geomap Multi Layers Dashboard\](https://play.grafana.org/d/geomap\_multi-layers/panel-tests-geomap-multi-layers) on Grafana Playground.
> 
> \*\*Step 2\*\*:
> 
> Create custom variable "country" with values: 
> !\[изображение\](https://github.com/grafana/grafana/assets/9244347/37d47338-dcef-4b33-9b62-f9652ab169b4)
> 
> 
> \*\*Step 3\*\*:
> 
> Open Panel settings and try to insert "$country" in the field instead of Canada
> !\[изображение\](https://github.com/grafana/grafana/assets/9244347/aee1b6b7-1f57-4140-800e-e15c4d441a40)
> 
> 
> \### 
> \# What Grafana version are you using?
> 
> v9.5.1

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [October 7, 2024, 2:10pm UTC](https://community.grafana.com/t/variables-in-geojson-style-rules/104951/3 "2024-10-07T14:10:53Z")

</div>


