Skip to content

Commit

Permalink
everything
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Forrest authored and Matt Forrest committed Jan 7, 2020
1 parent bdee257 commit c5d779c
Show file tree
Hide file tree
Showing 29 changed files with 2,093 additions and 106 deletions.
Binary file added .DS_Store
Binary file not shown.
10 changes: 4 additions & 6 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@
<link rel="icon" href="https://carto.com/favicon.ico" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<link rel="stylesheet" href="dist/style.css" />
<link rel="stylesheet" href="https://libs.cartocdn.com/airship-icons/v1.0.2/icons.css">
<link rel="stylesheet" href="https://libs.cartocdn.com/airship-icons/v2.1.0/icons.css">
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.51.0/mapbox-gl.css' rel='stylesheet' />
<script src="https://libs.cartocdn.com/airship-components/v1.0.2/airship.js"></script>
<!-- <script src="https://libs.cartocdn.com/carto-vl/v1.0.0/carto-vl.min.js"></script> -->
<script src="https://libs.cartocdn.com/airship-components/v2.1.1/airship.js"></script>

</head>

<body>
<body class="as-app-body as-app">
<div id="app"></div>
<script src="dist/bundle.js"></script>
</body>

</html>
</html>
Binary file added src/.DS_Store
Binary file not shown.
15 changes: 12 additions & 3 deletions src/components/CARTOMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,17 @@ class CARTOMap extends Component {
layer.on('featureClicked', this.openPopup.bind(this));
}

if(options.featureClickColumns && layerName === 'stores') {
console.log(layerName)
layer.on('featureClicked', this.openPopupStores.bind(this));
}

this.props.client.getLeafletLayer().addTo(this.props.map);

if (other.visible === false) {
layer.hide()
}

return { ...all, [layerName]: { source, style, layer, ...other } };
}, {});

Expand All @@ -105,8 +114,8 @@ class CARTOMap extends Component {
if (!this.popup.isOpen()) {
this.popup.openOn(this.props.map);
render(<InfoWindow {...featureEvent.data} />, this.popup._contentNode);
}
}
}
}

render() {
const { layers } = this.props;
Expand Down Expand Up @@ -134,4 +143,4 @@ const mapDispatchToProps = dispatch => ({
changeCartoBBox: boundingbox => dispatch(changeCartoBBox(boundingbox))
});

export default connect(mapStateToProps, mapDispatchToProps)(CARTOMap);
export default connect(mapStateToProps, mapDispatchToProps)(CARTOMap);
142 changes: 142 additions & 0 deletions src/components/CARTOMapPredict.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import React, { Component } from 'react';
import { render } from 'react-dom';
import L from 'leaflet';
import carto, { filter, source, style, layer } from '@carto/carto.js';
import { connect } from 'react-redux';
import styled from 'styled-components';
import { storeLayers, setMap, setBboxFilter, changeViewport, changeCartoBBox } from '../actions/actions';
// import { Widgets, Legend, AirbnbPopup, MobileTabs } from '../components/components';
import InfoWindow from '../components/InfoWindow'
import layers from '../data/layers';
import C from '../data/C'
import '@carto/airship-style';

// import './index.css';

const { BASEMAP, BASEMAP_LABELS, CENTER, ZOOM } = C;

class CARTOMapPredict extends Component {

constructor(props) {
super(props);
this.state = {
...props
}
}

componentDidMount() {

// look into adding the map up above

const map = L.map('map', { zoomControl: false, maxZoom: 18 }).setView(this.props.viewport.center, this.props.viewport.zoom);

this.props.setMap(map);

L.tileLayer(BASEMAP).addTo(map);

// L.control.zoom({ position: 'bottomleft' }).addTo(map);

this.popup = L.popup({ closeButton: false });

// this.setBbbox(map.getBounds());

const bboxFilter = new carto.filter.BoundingBoxLeaflet(map);
this.props.changeCartoBBox(bboxFilter);

map.on('moveend', event => {
const boundingBox = event.target.getBounds();
const newCenter = event.target.getCenter();
const newZoom = event.target.getZoom();
const newViewport = {
center: newCenter,
zoom: newZoom
}

this.props.setBboxFilter([
boundingBox._northEast.lat,
boundingBox._northEast.lng,
boundingBox._southWest.lat,
boundingBox._southWest.lng
])

this.props.changeViewport(newViewport);
});



}

setupLayers() {
const cartoLayers = Object.keys(layers).reduce((all, layerName) => {
const { options, ...other} = layers[layerName];

const source = new carto.source.SQL(other.query);
const style = new carto.style.CartoCSS(other.cartocss);
const layer = new carto.layer.Layer(source, style, options);

if(options.featureClickColumns) {
layer.on('featureClicked', this.openPopup.bind(this));
}

this.props.client.getLeafletLayer().addTo(this.props.map);

if (other.visible === false) {
layer.hide()
}


return { ...all, [layerName]: { source, style, layer, ...other } };
}, {});

// Add all layers at the same time so it doesn't reload multiple times
this.props.client.addLayers(Object.values(cartoLayers).map(item => item.layer));

// Labels need to be added after the layers
L.tileLayer(BASEMAP_LABELS).addTo(this.props.map);
console.log(cartoLayers)
this.props.storeLayers(cartoLayers)
}

componentDidUpdate(prevProps) {
if (!prevProps.map && this.props.map) {
this.setupLayers();
}
}

openPopup(featureEvent) {
this.popup.setContent('');
this.popup.setLatLng(featureEvent.latLng);

if (!this.popup.isOpen()) {
this.popup.openOn(this.props.map);
render(<InfoWindow {...featureEvent.data} />, this.popup._contentNode);
}
}

render() {
const { layers } = this.props;
const hasLayers = Object.keys(layers).length > 0;

return (
<div id="map"></div>
);
}
}

const mapStateToProps = state => ({
client: state.client,
map: state.map,
layers: state.layers,
viewport: state.viewport,
boundingbox: state.boundingbox
});

const mapDispatchToProps = dispatch => ({
storeLayers: layers => dispatch(storeLayers(layers)),
setMap: map => dispatch(setMap(map)),
setBboxFilter: bbox => dispatch(setBboxFilter(bbox)),
changeViewport: viewport => dispatch(changeViewport(viewport)),
changeCartoBBox: boundingbox => dispatch(changeCartoBBox(boundingbox))
});

export default connect(mapStateToProps, mapDispatchToProps)(CARTOMapPredict);
5 changes: 5 additions & 0 deletions src/components/CARTOVLMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ class CARTOVLMap extends Component {

// this.props.client.getLeafletLayer().addTo(this.props.map);

if (other.visible === false) {
layer.hide()
}


return { ...all, [layerName]: { source, viz, layer, ...other } };
}, {});

Expand Down
9 changes: 5 additions & 4 deletions src/components/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@ import BottomBar from './layout/BottomBar'
import Panel from './layout/Panel'
import '@carto/airship-style';


const Page = () => (
<as-responsive-content>
<body className="as-app-body as-app">
<Header />
<div className="as-content">
<main className="as-main">
<div className="as-map-area">
<CARTOVLMap />
<CARTOMap />
{/* <Panel
vertical='top'
horizontal='left'
background=''
name='Controls'
/> */}
</div>
{/* <BottomBar
<BottomBar
background=''
name='Bottom'
/> */}
/>
</main>
<RightBar
size='l'
Expand All @@ -43,4 +44,4 @@ const Page = () => (
</as-responsive-content>
);

export default Page;
export default Page;
46 changes: 46 additions & 0 deletions src/components/Predict.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';
import CARTOMapPredict from './CARTOMapPredict';
import CARTOVLMap from './CARTOVLMap';
import Header from './layout/Header'
import RightBar from './layout/RightBar'
import LeftBar from './layout/LeftBar'
import BottomBarPredict from './layout/BottomBarPredict'
import Panel from './layout/Panel'
import '@carto/airship-style';

const Page = () => (
<as-responsive-content>
<body className="as-app-body as-app">
<Header />
<div className="as-content">
<main className="as-main">
<div className="as-map-area">
<CARTOMapPredict />
{/* <Panel
vertical='top'
horizontal='left'
background=''
name='Controls'
/> */}
</div>
<BottomBarPredict
background=''
name='Bottom'
/>
</main>
<RightBar
size='l'
background=''
name='Right'
/>
{/* <LeftBar
size='s'
background=''
name='Left'
/> */}
</div>
</body>
</as-responsive-content>
);

export default Page;
Loading

0 comments on commit c5d779c

Please sign in to comment.