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

Issue #373 #376

Merged
merged 4 commits into from
Aug 24, 2023
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
15 changes: 11 additions & 4 deletions packages/frontend/src/components/common/DataExplorer/MapViz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ReactDOM from 'react-dom';
import 'mapbox-gl/dist/mapbox-gl.css';
import mapboxgl, { GeoJSONSourceRaw } from 'mapbox-gl';
import GeoJSON from 'geojson';
import PortalConfig from '../../../portal_configs.json';
import type { Dataframe, DataframeRow, Field } from './types';

type Props = {
Expand Down Expand Up @@ -47,7 +48,7 @@ const LATITUDE_FIELD_POSSIBILITIES = ['latitude', 'lat', 'y'];
const LONGITUDE_FIELD_POSSIBILITIES = ['longitude', 'long', 'x'];

export function MapViz({ dataframe }: Props): JSX.Element {
const { data, fields } = dataframe;
const { data, fields, city} = dataframe;
const mapRef = React.useRef<mapboxgl.Map | null>(null);
const tooltipRef = React.useRef(
new mapboxgl.Popup({
Expand Down Expand Up @@ -101,8 +102,14 @@ export function MapViz({ dataframe }: Props): JSX.Element {
accessToken: process.env.REACT_APP_SCOUT_MAPBOX_API_KEY ?? '',
container: 'map',
style: 'mapbox://styles/mapbox/light-v11',
center: [-73.95, 40.72],
zoom: 10,
center:
city in PortalConfig
? (PortalConfig[city as keyof typeof PortalConfig].coordinate as [
number,
number,
])
: [0, 0],
zoom: city in PortalConfig ? 10 : 2,
bearing: 0,
pitch: 0,
pitchWithRotate: false,
Expand Down Expand Up @@ -155,7 +162,7 @@ export function MapViz({ dataframe }: Props): JSX.Element {
});
});
}
}, [geojson, fields]);
}, [geojson, fields, city]);

return (
<>
Expand Down
3 changes: 3 additions & 0 deletions packages/frontend/src/components/common/DataExplorer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export type Dataframe = {

/** The header fields of this dataframe */
fields: readonly Field[];

/** city fields of this dataframe */
city: string;
};

export type VizType = 'table' | 'bars' | 'scatterplot' | 'map';
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default function VisualizationExplorer({ dataset }: Props): JSX.Element {
name: 'Empty Dataframe',
data: [],
fields: [],
city: 'empty-city',
};
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,5 +164,6 @@ export default function socrataResultsToDataframe(
id: dataset.id,
name: dataset.name,
data: transformedRows,
city: dataset.portal.abbreviation,
};
}
12 changes: 8 additions & 4 deletions packages/frontend/src/portal_configs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,34 @@
"logo": "https://opendata.cityofnewyork.us/wp-content/themes/opendata-wp/assets/img/nyc-open-data-logo.svg",
"socrataDomain": "data.cityofnewyork.us",
"urlSuffix": "NYC",
"adminLevel": "city"
"adminLevel": "city",
"coordinate": [-73.98, 40.73]
},
"NYS": {
"prefix": "ny_state",
"name": "New York State",
"logo": "https://static-assets.ny.gov/sites/all/themes/ny_gov/images/nygov-logo.png",
"socrataDomain": "data.ny.gov",
"urlSuffix": "NYS",
"adminLevel": "state"
"adminLevel": "state",
"coordinate": [-73.98, 40.73]
},
"CHI": {
"prefix": "chicago",
"name": "Chicago",
"logo": "https://data.cityofchicago.org/api/assets/73F1665C-0FE6-4183-8AD1-E91DB8EFAFA4?7CB02402-8E06-48B0-8C9A-3890182D58C7.png",
"socrataDomain": "data.cityofchicago.org",
"urlSuffix": "CHI",
"adminLevel": "city"
"adminLevel": "city",
"coordinate": [-87.62, 41.88]
},
"NAS": {
"prefix": "Nashville",
"name": "Nashville",
"logo": "https://data.nashville.gov/api/assets/097E3AD5-B563-42CD-8EBB-05635C6E28F8?site-title.png",
"socrataDomain": "data.nashville.gov",
"urlSuffix": "NAS",
"adminLevel": "city"
"adminLevel": "city",
"coordinate": [-86.74, 36.19]
}
}