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

Feature/45 choropleth map #46

Merged
merged 26 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fb2109d
[#45] Create data, color & type of choropleth map chart in config
ifirmawan Aug 16, 2024
5d9452a
[#45] Create mapHelper to handle more layer option
ifirmawan Aug 16, 2024
f7a43f3
[#45] Update GeoJson to accept style function
ifirmawan Aug 16, 2024
8729455
[#45] Update Marker to append data in markerLayer
ifirmawan Aug 16, 2024
f09b354
[#45] Handle Choropleth option in MapView
ifirmawan Aug 16, 2024
26e86c5
[#45] Update dist: Choropleth MapView
ifirmawan Aug 16, 2024
7289c75
[#45] Add new icon: ChevronDown
ifirmawan Aug 16, 2024
dc2b15f
[#45] Add Choropleth Map under Geo/Map menu
ifirmawan Aug 16, 2024
942f43c
[#45] Handle choropleth map type in ChartDisplay
ifirmawan Aug 16, 2024
fcdd9e2
[#45] Code formatter changes in Editor
ifirmawan Aug 16, 2024
03b24c0
[#45] Add fillOpacity in layer style state
ifirmawan Aug 16, 2024
639c467
[#45] Add legend style
ifirmawan Aug 16, 2024
0528657
[#45] Add style in default allProps in mapHelper
ifirmawan Aug 16, 2024
b5ba2a2
[#45] Create new Map component: LegendControl
ifirmawan Aug 16, 2024
96f1111
[#45] Refactoring GeoJson to prevent rerendering
ifirmawan Aug 16, 2024
2cbafa1
[#45] Add Legend control and update the snapshot in MapView
ifirmawan Aug 16, 2024
cb83f1c
[#45] Update dist: MapView
ifirmawan Aug 16, 2024
0fc53f7
[#45] Update default fillOpacity layer - MapView
ifirmawan Aug 16, 2024
0c0fd8c
[#32] Fix overlapping layer in Map Marker by adding preload
ifirmawan Aug 19, 2024
29f89eb
[#32] Fix string2WindowObj & create the tests
ifirmawan Aug 19, 2024
9116fa2
[#45] Fix calculateRanges & create the tests
ifirmawan Aug 19, 2024
ffc9600
[#45] Update dist: MapView - choropleth
ifirmawan Aug 19, 2024
be5aabb
[#45] Update MapView docs by adding choropleth example
ifirmawan Aug 19, 2024
c0ef313
[#45] Remove duplicated colors config
ifirmawan Aug 19, 2024
b6c51d6
[#45] Add choropleth map key in code-block
ifirmawan Aug 19, 2024
d307f07
[#45] Handle collapsible subMenuItems in Sidebar
ifirmawan Aug 19, 2024
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
69 changes: 68 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ The `akvo-charts` library allows you to create a variety of charts by leveraging
- [Data](#data-1)
- [Config](#config-1)
- [Example usage of MapView](#example-usage-of-mapview)
- [Example usage with Choropleth Mapping](#example-usage-with-choropleth-mapping)

---

Expand Down Expand Up @@ -1123,11 +1124,15 @@ The `MapView` component provides an easy way to render a map in your React appli
| `style` _(optional)_ | object | Defines the styling for GeoJSON lines and polygons using [Path options](https://leafletjs.com/reference.html#path-option), including properties like color, weight, and fillColor. |
| `onClick(map, props)` _(optional)_| function _or_ string | A function that is triggered when a layer feature is clicked. It receives the [map: Map instance](https://leafletjs.com/reference.html#map-factory) and [props: GeoJSON event properties](https://leafletjs.com/reference.html#geojsonevent-properties) as arguments, allowing you to interact with the map or the feature. |
| `onMouseOver(map, props)` _(optional)_| function _or_ string | A function that is triggered when the mouse hovers over a layer feature. It receives the [map: Map instance](https://leafletjs.com/reference.html#map-factory) and [props: GeoJSON event properties](https://leafletjs.com/reference.html#geojsonevent-properties) as arguments, enabling hover-based interactions. |

|`color` _(optional)_ | array | An array of colors used for choropleth mapping. Each feature will be colored according to its data value based on this color scale.|
|`mapKey` _(optional)_ |string | The key in the GeoJSON feature properties that is used to map the data values for the choropleth map.|
|`choropleth` _(optional)_ | string | The data attribute used for determining the color scale in the choropleth map. This value should match the data property in your dataset.|


#### data

An array of objects that define either marker points or data for choropleth mapping. For markers, objects should include point (latitude, longitude) and label. For choropleth, objects should include keys that match [mapKey](#layer) and the corresponding data value (e.g., density).

| Prop | Type | Description |
|-------|------|--------------|
| `point` | array [LatLng](https://leafletjs.com/reference.html#latlng) | Contains geographic points that will be displayed as markers.|
Expand Down Expand Up @@ -1208,4 +1213,66 @@ const MapViewExample = () => {
export default MapViewExample;
```

#### Example Usage with Choropleth Mapping

Here is an example of how to define a layer in MapView for applying a choropleth map:

```jsx
const ChoroPlethExample = () => {
const config = {
center: [-6.2, 106.816666],
zoom: 8,
height: "100vh",
width: "100%",
};

const data = [
{
Propinsi: "DI. ACEH",
density: 92,
},
{
Propinsi: "SUMATERA UTARA",
density: 205,
},
// more data here
];

const onClick = (map, { target }) => map.fitBounds(target._bounds);
const layer = {
source: "window.topoData",
url: "https://akvo.github.io/akvo-charts/static/geojson/indonesia-prov.geojson",
style: {
color: "#92400e",
weight: 1,
fillColor: "#fbbf24",
fillOpacity: 0.7,
},
color: [
"#FFEDA0",
"#FED976",
"#FFEDA0",
"#FED976",
],
mapKey: "Propinsi",
choropleth: "density",
onClick: onClick,
};

const tile = {
url: "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
maxZoom: 19,
attribution: "© OpenStreetMap",
};

return (
<div>
<MapView tile={tile} layer={layer} data={data} config={config} />
</div>
);
};

export default ChoroPlethExample;
```

---
17 changes: 17 additions & 0 deletions dist/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,20 @@
width: 100%;
height: 100%;
}

.ae-legend {
line-height: 18px;
color: #212121;
background-color: #fff;
padding: 6px;
text-align: left;
border-radius: 4px;
> .icon {
display: block !important;
width: 18px;
height: 18px;
float: left;
margin-right: 8px;
opacity: 0.7;
}
}
Loading
Loading