0

I am trying to graph a very simple data here https://raw.githubusercontent.com/pennytalalak/road-crash-data/master/src/data/output.geojson

But it wouldn't display the data on the map. Not sure if it is my geojson file or my code as my console said enter image description here

Here is my code:

import React, { Component } from "react";
import { StaticMap } from "react-map-gl";
import DeckGL, { GeoJsonLayer } from "deck.gl";

//Mapbox Token
const MAPBOX_TOKEN =
  "###########################";

//Geojson Data URL
const DATA =
  "https://raw.githubusercontent.com/pennytalalak/road-crash-data/master/src/data/output.geojson";

const LIGHT_SETTINGS = {
  lightsPosition: [-125, 50.5, 5000, -122.8, 48.5, 8000],
  ambientRatio: 0.2,
  diffuseRatio: 0.5,
  specularRatio: 0.3,
  lightsStrength: [2.0, 0.0, 1.0, 0.0],
  numberOfLights: 2
};

const INITIAL_VIEW_STATE = {
  latitude: -35.280937,
  longitude: 149.130005,
  zoom: 13,
  pitch: 0,
  bearing: 0
};

export default class Map extends Component {
  renderLayer() {
    const { data = DATA } = this.props;

    return [
      new GeoJsonLayer({
        id: "geoJson",
        data,
        filled: true,
        lightSettings: LIGHT_SETTINGS
      })
    ];
  }

  render() {
    const { viewState, baseMap = true } = this.props;

    return (
      <DeckGL
        layers={this.renderLayer()}
        initialViewState={INITIAL_VIEW_STATE}
        viewState={viewState}
        controller={true}
      >
        {baseMap && (
          <StaticMap
            mapStyle="mapbox://styles/mapbox/dark-v9"
            preventStyleDiffing={true}
            mapboxApiAccessToken={MAPBOX_TOKEN}
          />
        )}
      </DeckGL>
    );
  }
}
Penny Pang
  • 535
  • 2
  • 8
  • 23
  • https://raw.githubusercontent.com/pennytalalak/road-crash-data/master/src/data/output.geojson is invalid. It has lots of special characters that are invisible in browser but break parsing. – UjinT34 Feb 04 '19 at 11:41
  • I think your app is validating the geoJSON before it's finished loading, as it is a humungous file. Maybe give this a try? https://www.npmjs.com/package/geojson-stream – stever Feb 04 '19 at 22:17

0 Answers0