Skip to content

Commit

Permalink
Merge pull request #51 from prefeitura-rio/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
lucastavarex authored Sep 12, 2024
2 parents dcdfe28 + 45a8943 commit 8be8e0a
Show file tree
Hide file tree
Showing 52 changed files with 10,353 additions and 2,024 deletions.
6,846 changes: 4,848 additions & 1,998 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@
"@img-comparison-slider/react": "^8.0.0",
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"@turf/along": "^7.1.0",
"@turf/helpers": "^7.1.0",
"@turf/length": "^7.1.0",
"css-loader": "^6.7.1",
"d3": "^7.6.1",
"deck.gl": "^8.8.3",
"file-loader": "^6.2.0",
"gsap": "^3.10.4",
"mapbox-gl": "^2.9.1",
"mapbox-gl": "^3.6.0",
"postcss-loader": "^7.0.1",
"postcss-preset-env": "^7.7.2",
"react": "^17.0.2",
Expand Down
12 changes: 12 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import React, { Suspense, lazy } from "react";
import { HashRouter as Router, Routes, Route } from "react-router-dom";
import { LoadingSEOPDemolicioes } from "./pages/seop-demolicoes/loading";
import { LoadingCivitas } from "./pages/civitas/loading";
import { LoadingObras } from "./pages/obras/loading";
import { LoadingSubsidioSPPO } from "./pages/subsidio-sppo/loading";
import { LoadingSeopCep } from "./pages/seop-cep/loading";
Expand All @@ -27,6 +28,7 @@ const ObrasZO = lazy(() => import("./pages/obras/story"));
const TestLineChart = lazy(() => import("./pages/sandbox/test_linechart"));
const TestMap = lazy(() => import("./pages/sandbox/test_map"));
const SEOPDemolicoes = lazy(() => import("./pages/seop-demolicoes/story"));
const Civitas = lazy(() => import("./pages/civitas/story"));
const PainelAlagamentoPassadoComando = lazy(() =>
import("./pages/painel-alagamento-passado-comando/story")
);
Expand Down Expand Up @@ -140,7 +142,9 @@ const GlobalStyle = createGlobalStyle`
`;

SEOPDemolicoes;
Civitas;
CepSEOP;

function App() {
return (
<div id={"main"}>
Expand Down Expand Up @@ -297,6 +301,14 @@ function App() {
></Route>
</Routes>
</Suspense>
<Suspense fallback={<LoadingCivitas />}>
<Routes>
<Route
path="/civitas"
element={<Civitas />}
></Route>
</Routes>
</Suspense>
<Suspense fallback={<LoadingObras />}>
<Routes>
<Route path="/obras" element={<ObrasZO />}></Route>
Expand Down
50 changes: 25 additions & 25 deletions src/components/maps/multilayer_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,24 @@ class MultilayerMap extends React.Component {
}

// Chamado após o componente ser montado.
componentDidMount() {}
componentDidMount() { }
// CUSTOM: Função auxiliar para montar o view state do mapa.
getViewState(location) {
let viewState = isMobile
? {
center: [location.mobile.center.lon, location.mobile.center.lat],
zoom: location.mobile.zoom,
bearing: location.mobile.bearing,
pitch: location.mobile.pitch,
duration: location.mobile.duration,
}
center: [location.mobile.center.lon, location.mobile.center.lat],
zoom: location.mobile.zoom,
bearing: location.mobile.bearing,
pitch: location.mobile.pitch,
duration: location.mobile.duration,
}
: {
center: [location.desktop.center.lon, location.desktop.center.lat],
zoom: location.desktop.zoom,
bearing: location.desktop.bearing,
pitch: location.desktop.pitch,
duration: location.desktop.duration,
};
center: [location.desktop.center.lon, location.desktop.center.lat],
zoom: location.desktop.zoom,
bearing: location.desktop.bearing,
pitch: location.desktop.pitch,
duration: location.desktop.duration,
};
if (!viewState.duration) {
viewState.duration = 4000;
}
Expand Down Expand Up @@ -193,19 +193,19 @@ class MultilayerMap extends React.Component {
initialViewState={
isMobile
? {
latitude: this.props.location.mobile.center.lat,
longitude: this.props.location.mobile.center.lon,
zoom: this.props.location.mobile.zoom,
bearing: this.props.location.mobile.bearing,
pitch: this.props.location.mobile.pitch,
}
latitude: this.props.location.mobile.center.lat,
longitude: this.props.location.mobile.center.lon,
zoom: this.props.location.mobile.zoom,
bearing: this.props.location.mobile.bearing,
pitch: this.props.location.mobile.pitch,
}
: {
latitude: this.props.location.desktop.center.lat,
longitude: this.props.location.desktop.center.lon,
zoom: this.props.location.desktop.zoom,
bearing: this.props.location.desktop.bearing,
pitch: this.props.location.desktop.pitch,
}
latitude: this.props.location.desktop.center.lat,
longitude: this.props.location.desktop.center.lon,
zoom: this.props.location.desktop.zoom,
bearing: this.props.location.desktop.bearing,
pitch: this.props.location.desktop.pitch,
}
}
{...this.state.mapSettings}
onLoad={({ target }) => {
Expand Down
142 changes: 142 additions & 0 deletions src/pages/civitas/MapboxElevationApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import React, { useEffect, useRef } from 'react';
import mapboxgl from 'mapbox-gl';
import { lineString } from '@turf/helpers';
import along from '@turf/along';
import length from '@turf/length';
import bearing from '@turf/bearing'; // Importing bearing from the correct module
import 'mapbox-gl/dist/mapbox-gl.css';
import pinRouteGeojson from './pinRouteGeojson.json';
import carro from './images/carro.png';

mapboxgl.accessToken = 'pk.eyJ1IjoiZXNjcml0b3Jpb2RlZGFkb3MiLCJhIjoiY2t3bWdmcHpjMmJ2cTJucWJ4MGQ1Mm1kbiJ9.4hHJX-1pSevYoBbja7Pq4w';

const MapboxElevationApp = () => {
const mapContainerRef = useRef(null);
const animationFrameRef = useRef(null);
const containerRef = useRef(null);

useEffect(() => {
(async () => {
const map = new mapboxgl.Map({
container: mapContainerRef.current,
zoom: 14,
center: [-43.36105513587367, -22.864784742263154],
pitch: 50,
bearing: 150,
style: 'mapbox://styles/escritoriodedados/clzu707th00ro01pc69du960f',
interactive: false,
hash: false,
});

await map.once('style.load');

map.setFog({});

const pinRoute = pinRouteGeojson.features[0].geometry.coordinates;

const markerElement = document.createElement('div');
markerElement.style.backgroundImage = `url(${carro})`;
markerElement.style.width = '20px';
markerElement.style.height = '50px';
markerElement.style.backgroundSize = 'contain';
markerElement.style.backgroundRepeat = 'no-repeat';

const marker = new mapboxgl.Marker({
element: markerElement,
draggable: false,
pitchAlignment: '90',
rotationAlignment: 'map',
})
.setLngLat(pinRoute[0])
.addTo(map);

map.addSource('line', {
type: 'geojson',
lineMetrics: true,
data: pinRouteGeojson,
});

map.addLayer({
type: 'line',
source: 'line',
id: 'line',
paint: {
'line-color': 'rgba(0,0,0,0)',
'line-width': 5,
},
layout: {
'line-cap': 'round',
'line-join': 'round',
},
});

await map.once('idle');
const path = lineString(pinRoute);
const pathDistance = length(path);

const updateAnimation = () => {
const containerTop = containerRef.current.getBoundingClientRect().top;
const containerHeight = containerRef.current.offsetHeight;
const scrollProgress = (window.innerHeight - 500 - containerTop) / containerHeight;

const alongPath = along(path, pathDistance * scrollProgress).geometry.coordinates;
const nextAlongPath = along(path, pathDistance * (scrollProgress + 0.0001)).geometry.coordinates;

const lngLat = {
lng: alongPath[0],
lat: alongPath[1],
};

const elevation = Math.floor(
map.queryTerrainElevation(lngLat, { exaggerated: false })
);

// Calculate the bearing between the current position and the next position
const markerBearing = bearing(alongPath, nextAlongPath); // Adjusted bearing

marker.setLngLat(lngLat);
marker.setRotation(markerBearing);

map.setPaintProperty('line', 'line-gradient', [
'step',
['line-progress'],
'#00BFFF',
scrollProgress,
'rgba(255, 0, 0, 0)',
]);

const rotation = 150 - scrollProgress * 40.0;
map.setBearing(rotation % 360);

map.easeTo({
center: lngLat,
bearing: 108.625,
duration: 0,
pitch: 50,
});

animationFrameRef.current = requestAnimationFrame(updateAnimation);
};

window.addEventListener('scroll', updateAnimation);

return () => {
window.removeEventListener('scroll', updateAnimation);
if (animationFrameRef.current) {
cancelAnimationFrame(animationFrameRef.current);
}
};
})();
}, []);

return (
<div ref={containerRef}>
<div ref={mapContainerRef} style={{ position: 'fixed', top: 0, bottom: 0, width: '100%' }} />
<div style={{ height: '1000vh' }}>
{/* animation on scroll */}
</div>
</div>
);
};

export default MapboxElevationApp;
Loading

0 comments on commit 8be8e0a

Please sign in to comment.