Skip to content

Commit

Permalink
chore: add RailplusLayer, fetch railplus providers on layer load
Browse files Browse the repository at this point in the history
  • Loading branch information
danji90 committed Oct 18, 2023
1 parent 2554594 commit b5e2c19
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/config/ch.railplus.mitglieder/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import TrafimageMapboxLayer from '../../layers/TrafimageMapboxLayer';
import MapboxStyleLayer from '../../layers/MapboxStyleLayer';
import RailplusLayer from '../../layers/RailplusLayer';

export const netzkarteRailplus = new TrafimageMapboxLayer({
name: 'ch.railplus.mitglieder.data',
visible: true,
zIndex: -1,
style: 'netzkarte_eisenbahninfrastruktur_v3_ch.railplus',
style: 'netzkarte_eisenbahninfrastruktur_v3_ch.railplus.meterspurbahnen',
properties: {
isBaseLayer: true,
},
Expand All @@ -14,7 +14,7 @@ export const netzkarteRailplus = new TrafimageMapboxLayer({
},
});

export const railplusMeterspurbahnen = new MapboxStyleLayer({
export const railplusMeterspurbahnen = new RailplusLayer({
name: 'ch.railplus.mitglieder.meterspur',
visible: true,
mapboxLayer: netzkarteRailplus,
Expand Down
2 changes: 1 addition & 1 deletion src/layers/AusbauLayer/AusbauLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import qs from 'query-string';

/**
* Layer for ausbau
* Extends {@link https://mobility-toolbox-js.netlify.app/api/class/src/ol/layers/MapboxStyleLayer%20js~MapboxStyleLayer}
* Extends {@link https://mobility-toolbox-js.geops.io/doc/class/build/ol/layers/MapboxStyleLayer%20js~MapboxStyleLayer%20html-offset-anchor}
* @private
* @class
* @param {Object} [options] Layer options.
Expand Down
2 changes: 1 addition & 1 deletion src/layers/GeltungsbereicheLayer/GeltungsbereicheLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MapboxStyleLayer } from 'mobility-toolbox-js/ol';

/**
* Layer for GeltungsbereicheLayer
* Extends {@link https://mobility-toolbox-js.netlify.app/api/class/src/ol/layers/MapboxStyleLayer%20js~MapboxStyleLayer%20html-offset-anchor}
* Extends {@link https://mobility-toolbox-js.geops.io/doc/class/build/ol/layers/MapboxStyleLayer%20js~MapboxStyleLayer%20html-offset-anchor}
* @private
* @class
* @param {Object} [options] Layer options.
Expand Down
2 changes: 1 addition & 1 deletion src/layers/PlatformsLayer/PlatformsLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MapboxStyleLayer } from 'mobility-toolbox-js/ol';

/**
* Layer for displaying blue circle on platforms on hover.
* Extends {@link https://mobility-toolbox-js.netlify.app/api/class/src/ol/layers/MapboxStyleLayer%20js~MapboxStyleLayer%20html-offset-anchor}
* Extends {@link https://mobility-toolbox-js.geops.io/doc/class/build/ol/layers/MapboxStyleLayer%20js~MapboxStyleLayer%20html-offset-anchor}
* @private
* @class
* @param {Object} [options] Layer options.
Expand Down
29 changes: 29 additions & 0 deletions src/layers/RailplusLayer/RailplusLayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { MapboxStyleLayer } from 'mobility-toolbox-js/ol';

/**
* Layer for RailplusLayer
* Extends {@link https://mobility-toolbox-js.geops.io/doc/class/build/ol/layers/MapboxStyleLayer%20js~MapboxStyleLayer%20html-offset-anchor}
* @private
* @class
* @param {Object} [options] Layer options.
*/
class RailplusLayer extends MapboxStyleLayer {
onLoad() {
super.onLoad();
this.fetchRailplusProviders();
}

fetchRailplusProviders() {
fetch(
`${this.mapboxLayer.url}/data/ch.railplus.meterspurbahnen.json?key=${this.mapboxLayer.apiKey}`,
)
.then((res) => res.json())
.then((data) => {
this.railplusProviders = data['geops.railplus.tu_info'];
})
// eslint-disable-next-line no-console
.catch((err) => console.error(err));
}
}

export default RailplusLayer;
1 change: 1 addition & 0 deletions src/layers/RailplusLayer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './RailplusLayer';
2 changes: 1 addition & 1 deletion src/layers/StationsLayer/StationsLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MapboxStyleLayer } from 'mobility-toolbox-js/ol';

/**
* Layer for displaying blue stations circle on hover.
* Extends {@link https://mobility-toolbox-js.netlify.app/api/class/src/ol/layers/MapboxStyleLayer%20js~MapboxStyleLayer%20html-offset-anchor}
* Extends {@link https://mobility-toolbox-js.geops.io/doc/class/build/ol/layers/MapboxStyleLayer%20js~MapboxStyleLayer%20html-offset-anchor}
* @private
* @class
* @param {Object} [options] Layer options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const format = new GeoJSON();

/**
* Layer for TarifverbundkarteLayer
* Extends {@link https://mobility-toolbox-js.netlify.app/api/class/src/ol/layers/MapboxStyleLayer%20js~MapboxStyleLayer%20html-offset-anchor}
* Extends {@link https://mobility-toolbox-js.geops.io/doc/class/build/ol/layers/MapboxStyleLayer%20js~MapboxStyleLayer%20html-offset-anchor}
* @private
* @class
* @param {Object} [options] Layer options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GeoJSON } from 'ol/format';

/**
* Layer for zweitausbildung pois
* Extends {@link https://mobility-toolbox-js.netlify.app/api/class/src/ol/layers/MapboxStyleLayer%20js~MapboxStyleLayer%20html-offset-anchor}
* Extends {@link https://mobility-toolbox-js.geops.io/doc/class/build/ol/layers/MapboxStyleLayer%20js~MapboxStyleLayer%20html-offset-anchor}
* @private
* @class
* @param {Object} [options] Layer options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const sourceLayer = 'ch.sbb.zweitausbildung';

/**
* Layer for zweitausbildung highlight routes.
* Extends {@link https://mobility-toolbox-js.netlify.app/api/class/src/ol/layers/MapboxStyleLayer%20js~MapboxStyleLayer%20html-offset-anchor}
* Extends {@link https://mobility-toolbox-js.geops.io/doc/class/build/ol/layers/MapboxStyleLayer%20js~MapboxStyleLayer%20html-offset-anchor}
* @private
* @class
* @param {Object} [options] Layer options.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import getStyleLayers from './getStyleLayers';

/**
* Layer for zweitausbildung routes
* Extends {@link https://mobility-toolbox-js.netlify.app/api/class/src/ol/layers/MapboxStyleLayer%20js~MapboxStyleLayer%20html-offset-anchor}
* Extends {@link https://mobility-toolbox-js.geops.io/doc/class/build/ol/layers/MapboxStyleLayer%20js~MapboxStyleLayer%20html-offset-anchor}
* @private
* @class
* @param {Object} [options] Layer options.
Expand Down
25 changes: 19 additions & 6 deletions src/popups/RailplusPopup/RailplusPopup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import { Divider, Typography, makeStyles } from '@material-ui/core';
import providers from '../../config/ch.railplus.mitglieder/providersMapping';
import PropTypes from 'prop-types';
import { Feature } from 'ol';
import { Typography, makeStyles } from '@material-ui/core';
import RailplusLayer from '../../layers/RailplusLayer';

const useStyles = makeStyles((theme) => ({
dividerRoot: {
Expand All @@ -19,12 +21,16 @@ const useStyles = makeStyles((theme) => ({
},
}));

function RailplusPopup() {
function RailplusPopup({ feature, layer }) {
const classes = useStyles();
const provider = providers[Math.floor(Math.random() * 5)]; // TODO: get info from tiles once style is ready
const isbNummer = feature.get('isb_tu_nummer');
const tuDetails = layer.railplusProviders.find((tu) => !!tu[isbNummer])[
isbNummer
];

return (
<div className={classes.railplusPopup}>
<a
{/* <a
href={provider.url}
target="_blank"
rel="noopener noreferrer"
Expand All @@ -35,11 +41,18 @@ function RailplusPopup() {
<Typography className={classes.providerName}>
{provider.name}
</Typography>
</a>
</a> */}
<Typography className={classes.providerName}>
{tuDetails.long_name}
</Typography>
</div>
);
}

RailplusPopup.hideHeader = () => true;
RailplusPopup.propTypes = {
feature: PropTypes.instanceOf(Feature).isRequired,
layer: PropTypes.instanceOf(RailplusLayer).isRequired,
};

export default RailplusPopup;

0 comments on commit b5e2c19

Please sign in to comment.