Compare commits
8 Commits
@portaljs/
...
@portaljs/
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a4ec39d25 | ||
|
|
38bf06f031 | ||
|
|
8560f165fd | ||
|
|
b13e3ade3c | ||
|
|
1394f02038 | ||
|
|
e687779fa6 | ||
|
|
2ec143707d | ||
|
|
4ddfc1126a |
@@ -1,5 +1,17 @@
|
|||||||
# @portaljs/components
|
# @portaljs/components
|
||||||
|
|
||||||
|
## 0.5.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#1063](https://github.com/datopian/portaljs/pull/1063) [`b13e3ade`](https://github.com/datopian/portaljs/commit/b13e3ade3ccefe7dffe84f824bdedd3e512ce499) Thanks [@Gutts-n](https://github.com/Gutts-n)! - Created auto zoom configuration for the map component
|
||||||
|
|
||||||
|
## 0.5.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#1061](https://github.com/datopian/portaljs/pull/1061) [`4ddfc112`](https://github.com/datopian/portaljs/commit/4ddfc1126a3f0b8137ea47a08a36c56b7373b8f6) Thanks [@Gutts-n](https://github.com/Gutts-n)! - Created the style property in the Map component
|
||||||
|
|
||||||
## 0.5.0
|
## 0.5.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@portaljs/components",
|
"name": "@portaljs/components",
|
||||||
"version": "0.5.0",
|
"version": "0.5.2",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "https://portaljs.org",
|
"description": "https://portaljs.org",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { CSSProperties, useEffect, useState } from 'react';
|
||||||
import LoadingSpinner from './LoadingSpinner';
|
import LoadingSpinner from './LoadingSpinner';
|
||||||
import loadData from '../lib/loadData';
|
import loadData from '../lib/loadData';
|
||||||
import chroma from 'chroma-js';
|
import chroma from 'chroma-js';
|
||||||
@@ -21,15 +21,19 @@ export type MapProps = {
|
|||||||
ending: string;
|
ending: string;
|
||||||
};
|
};
|
||||||
tooltip?:
|
tooltip?:
|
||||||
| {
|
| {
|
||||||
propNames: string[];
|
propNames: string[];
|
||||||
}
|
}
|
||||||
| boolean;
|
| boolean;
|
||||||
_id?: number;
|
_id?: number;
|
||||||
}[];
|
}[];
|
||||||
title?: string;
|
title?: string;
|
||||||
center?: { latitude: number | undefined; longitude: number | undefined };
|
center?: { latitude: number | undefined; longitude: number | undefined };
|
||||||
zoom?: number;
|
zoom?: number;
|
||||||
|
style?: CSSProperties;
|
||||||
|
autoZoomConfiguration?: {
|
||||||
|
layerName: string
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export function Map({
|
export function Map({
|
||||||
@@ -44,6 +48,8 @@ export function Map({
|
|||||||
center = { latitude: 45, longitude: 45 },
|
center = { latitude: 45, longitude: 45 },
|
||||||
zoom = 2,
|
zoom = 2,
|
||||||
title = '',
|
title = '',
|
||||||
|
style = {},
|
||||||
|
autoZoomConfiguration = undefined,
|
||||||
}: MapProps) {
|
}: MapProps) {
|
||||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||||
const [layersData, setLayersData] = useState<any>([]);
|
const [layersData, setLayersData] = useState<any>([]);
|
||||||
@@ -96,6 +102,7 @@ export function Map({
|
|||||||
zoom={zoom}
|
zoom={zoom}
|
||||||
scrollWheelZoom={false}
|
scrollWheelZoom={false}
|
||||||
className="h-80 w-full"
|
className="h-80 w-full"
|
||||||
|
style={style ?? {}}
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
whenReady={(map: any) => {
|
whenReady={(map: any) => {
|
||||||
// Enable zoom using scroll wheel
|
// Enable zoom using scroll wheel
|
||||||
@@ -104,17 +111,35 @@ export function Map({
|
|||||||
// Create the title box
|
// Create the title box
|
||||||
var info = new L.Control() as any;
|
var info = new L.Control() as any;
|
||||||
|
|
||||||
info.onAdd = function () {
|
info.onAdd = function() {
|
||||||
this._div = L.DomUtil.create('div', 'info');
|
this._div = L.DomUtil.create('div', 'info');
|
||||||
this.update();
|
this.update();
|
||||||
return this._div;
|
return this._div;
|
||||||
};
|
};
|
||||||
|
|
||||||
info.update = function () {
|
info.update = function() {
|
||||||
this._div.innerHTML = `<h4 style="font-weight: 600; background: #f9f9f9; padding: 5px; border-radius: 5px; color: #464646;">${title}</h4>`;
|
this._div.innerHTML = `<h4 style="font-weight: 600; background: #f9f9f9; padding: 5px; border-radius: 5px; color: #464646;">${title}</h4>`;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (title) info.addTo(map.target);
|
if (title) info.addTo(map.target);
|
||||||
|
if(!autoZoomConfiguration) return;
|
||||||
|
|
||||||
|
let layerToZoomBounds = L.latLngBounds(L.latLng(0, 0), L.latLng(0, 0));
|
||||||
|
|
||||||
|
layers.forEach((layer) => {
|
||||||
|
if(layer.name === autoZoomConfiguration.layerName) {
|
||||||
|
const data = layersData.find(
|
||||||
|
(layerData) => layerData.name === layer.name
|
||||||
|
)?.data;
|
||||||
|
|
||||||
|
if (data) {
|
||||||
|
layerToZoomBounds = L.geoJSON(data).getBounds();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
map.target.fitBounds(layerToZoomBounds);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TileLayer
|
<TileLayer
|
||||||
|
|||||||
@@ -21,6 +21,12 @@ const meta: Meta = {
|
|||||||
zoom: {
|
zoom: {
|
||||||
description: 'Zoom level',
|
description: 'Zoom level',
|
||||||
},
|
},
|
||||||
|
style: {
|
||||||
|
description: "Styles for the container"
|
||||||
|
},
|
||||||
|
autoZoomConfiguration: {
|
||||||
|
description: "Configuration to auto zoom in the specified layer data"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -88,4 +94,32 @@ export const GeoJSONMultipleLayers: Story = {
|
|||||||
center: { latitude: 45, longitude: 0 },
|
center: { latitude: 45, longitude: 0 },
|
||||||
zoom: 2,
|
zoom: 2,
|
||||||
},
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
export const GeoJSONMultipleLayersWithAutoZoomInSpecifiedLayer: Story = {
|
||||||
|
name: 'GeoJSON polygons and points map with auto zoom in the points layer',
|
||||||
|
args: {
|
||||||
|
layers: [
|
||||||
|
{
|
||||||
|
data: 'https://opendata.arcgis.com/datasets/9c58741995174fbcb017cf46c8a42f4b_25.geojson',
|
||||||
|
name: 'Points',
|
||||||
|
tooltip: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
data: 'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_geography_marine_polys.geojson',
|
||||||
|
name: 'Polygons',
|
||||||
|
tooltip: true,
|
||||||
|
colorScale: {
|
||||||
|
starting: '#ff0000',
|
||||||
|
ending: '#00ff00',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
title: 'Polygons and points',
|
||||||
|
center: { latitude: 45, longitude: 0 },
|
||||||
|
zoom: 2,
|
||||||
|
autoZoomConfiguration: {
|
||||||
|
layerName: 'Points'
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user