0

I am working on kepler.gl .... wright now i am reading data from an api and plot that data in keplr.gl and that's working fine here is the code ...

import keplerGlReducer from "kepler.gl/reducers";
import { createStore, combineReducers, applyMiddleware } from "redux";
import { taskMiddleware } from "react-palm/tasks";
import { Provider, useDispatch } from "react-redux";
import KeplerGl from "kepler.gl";
import { addDataToMap } from "kepler.gl/actions";
import useSwr from "swr";

const reducers = combineReducers({
  keplerGl: keplerGlReducer
});

const store = createStore(reducers, {}, applyMiddleware(taskMiddleware));

export default function App() {
  return (
    <Provider store={store}>
      <Map />
      <csv/>
    </Provider>
  );
}

function Map() {
  const dispatch = useDispatch();
  const { data } = useSwr("covid", async () => {
    const response = await fetch(
     "https://gist.githubusercontent.com/leighhalliday/a994915d8050e90d413515e97babd3b3/raw/a3eaaadcc784168e3845a98931780bd60afb362f/covid19.json"
     );
     const data = await response.json();
     return data;
   });

  React.useEffect(() => {
    if (data) {
      dispatch(
        addDataToMap({
          datasets: {
            info: {
              label: "COVID-19",
              id: "covid19"
            },
            data
          },
          option: {
            centerMap: true,
            readOnly: false
          },
          config: {}
        })
      );
    }
  }, [dispatch, data]);

  return (
    <KeplerGl
      id="covid"
      mapboxApiAccessToken="pk.eyJ1IjoiYWxpcmF6YTcwNSIsImEiOiJjazh5d2hjb3AwOHBqM2VsY21wOHo5eXprIn0.9G5CE4KqfbvU9HQ6WBuo3w"
      width={window.innerWidth}
      height={window.innerHeight}
    />
  );
}

now i want to read data from jason or csv file and plot that data into kepler.gl map .. how can i do this can anyone help me ?..... thanks

Salman Zafar
  • 3,844
  • 5
  • 20
  • 43
Ali Raza
  • 148
  • 2
  • 12

2 Answers2

1

easiest way would be to place your json or csv file beside your code and
import your json file:

const dataJson = require('./data.json');

change your data source to your json:

const data = dataJson
// or dataJson.data depending on your json structure

or if your data is in csv format the fastest way that comes to mind is installing the csv-parse and then:

const data = parse(csvData, {
   //config based on your csv format
   columns: true,
   skip_empty_lines: true
});

hope this is what you are looking for

punjira
  • 818
  • 8
  • 21
1

In React do it like this

import datajson from './yourdata.json';

const data=datajson;
XEnterprise
  • 382
  • 1
  • 6
  • 19