Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stop layer to new Debug UI #5602

Merged

Conversation

leonardehrenfried
Copy link
Member

Summary

This adds a vector tile layer for displaying stops in the new debug client. It looks like this:

Screenshot from 2023-12-30 23-20-34

It does this by adding some model classes that make it easy to write the layer style code in Java. This is a little less error prone than writing the JSON "by hand". Still, the domain (vector tile rendering and styling) is complex so you have to familiarise yourself with how Mapbox/Maplibre renders the map in order to write your own.

Issue

#5330

Unit tests

✔️

Documentation

Javadoc.

@leonardehrenfried leonardehrenfried requested a review from a team as a code owner January 2, 2024 15:56
@leonardehrenfried
Copy link
Member Author

@testower I'm a TypeScript noob. Can you give me a hand at getting around the compiler errors?

@testower
Copy link
Contributor

testower commented Jan 2, 2024

I don't understand the need to define the map style in Java, when MapLibre has the style defnition fully typed. Did you look at the "MapStyle" interface?

Copy link

codecov bot commented Jan 2, 2024

Codecov Report

Attention: 54 lines in your changes are missing coverage. Please review.

Comparison is base (75462f0) 67.47% compared to head (cf5d875) 67.55%.
Report is 11 commits behind head on dev-2.x.

Files Patch % Lines
.../vectortiles/GraphInspectorVectorTileResource.java 0.00% 24 Missing ⚠️
...lanner/inspector/vector/stop/StopLayerBuilder.java 0.00% 13 Missing ⚠️
...ntripplanner/apis/vectortiles/model/LayerType.java 0.00% 4 Missing ⚠️
...ripplanner/apis/vectortiles/model/LayerParams.java 0.00% 3 Missing ⚠️
...va/org/opentripplanner/framework/io/HttpUtils.java 0.00% 3 Missing ⚠️
...in/java/org/opentripplanner/apis/APIEndpoints.java 0.00% 2 Missing ⚠️
...nner/apis/vectortiles/model/LayerStyleBuilder.java 95.12% 1 Missing and 1 partial ⚠️
...entripplanner/apis/vectortiles/DebugStyleSpec.java 94.73% 1 Missing ⚠️
...pector/vector/stop/StopLocationPropertyMapper.java 85.71% 0 Missing and 1 partial ⚠️
...entripplanner/standalone/server/GrizzlyServer.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             dev-2.x    #5602      +/-   ##
=============================================
+ Coverage      67.47%   67.55%   +0.08%     
- Complexity     16199    16221      +22     
=============================================
  Files           1862     1865       +3     
  Lines          71213    71204       -9     
  Branches        7406     7398       -8     
=============================================
+ Hits           48048    48102      +54     
+ Misses         20672    20608      -64     
- Partials        2493     2494       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@leonardehrenfried
Copy link
Member Author

I don't understand the need to define the map style in Java, when MapLibre has the style defnition fully typed. Did you look at the "MapStyle" interface?

First of all I didn't know that MapStyle exists. Are you sure that it's fully typed? I can only see the following:

export interface ILayer {
    id: string;
    type: string;
    metadata?: any;
    source?: unknown;
    minzoom?: number;
    maxzoom?: number;
    filter?: any;
    layout?: {
        [property: string]: any;
    };
    paint?: {
        [property: string]: any;
    };
}

Secondly, I was a lot more comfortable writing Java and I suspect other devs will be too.

Thirdly, I wanted the code that generates the data and the code that generates the styling close to each other sharing some identifiers (like layer names). This means that refactoring is a little easier.

I'm happy to debate these points and find a way forward that suits everyone.

@testower
Copy link
Contributor

testower commented Jan 2, 2024

First of all I didn't know that MapStyle exists. Are you sure that it's fully typed? I can only see the following:

Yes you'll find it in the 'react-map-gl' package:

    export interface Style {
        layers: AnyLayer[];
        sources: Sources;

        bearing?: number | undefined;
        center?: number[] | undefined;
        fog?: Fog | undefined;
        glyphs?: string | undefined;
        metadata?: any;
        name?: string | undefined;
        pitch?: number | undefined;
        light?: Light | undefined;
        sprite?: string | undefined;
        terrain?: TerrainSpecification | undefined;
        transition?: Transition | undefined;
        version: number;
        zoom?: number | undefined;
    }

Secondly, I was a lot more comfortable writing Java and I suspect other devs will be too.

Thirdly, I wanted the code that generates the data and the code that generates the styling close to each other sharing some identifiers (like layer names). This means that refactoring is a little easier.

I'm sure there's some tradeoff here. In my view, the styling definition is client/implementation-specific and should live close to the client. I don't think we should offload code to the Java server just because it's more convenient.

Also, exposing the MapLibre / Mapbox styles in the api suggests that they are then officially part of the api? If that should be the case, then I think it makes more sense, but not for convenience.

@leonardehrenfried
Copy link
Member Author

Well, we are not building a style against a generic vector tile schema like https://openmaptiles.org/schema/ but styling some very domain-specific geometries.

Whether you consider that part of "the API" is up for debate.

Next week I'm back at the dev meeting. We can talk about that there or on Gitter.

@leonardehrenfried leonardehrenfried added the OTP Debug UI The OTP bundled client label Jan 2, 2024
@leonardehrenfried leonardehrenfried changed the title Add stop debug layer to debug client Add stop debug layer to new debug client Jan 9, 2024
@leonardehrenfried
Copy link
Member Author

Sorry @testower I made a tiny one-character change at the same time you approved.

Copy link
Contributor

@testower testower left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@leonardehrenfried leonardehrenfried added this to the 2.5 (next release) milestone Jan 9, 2024
client-next/src/components/MapView/MapView.tsx Outdated Show resolved Hide resolved
client-next/src/components/MapView/MapView.tsx Outdated Show resolved Hide resolved
client-next/src/components/MapView/MapView.tsx Outdated Show resolved Hide resolved
if (e.features) {
// if you click on a cluster of map features it's possible that there are multiple
// to select from. we are using the first one instead of presenting a selection UI.
// you can always zoom in closer if you want to make a more specific click.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's neat. A potential improvement could be to instead zoom in one level if you encounter a cluster? Not critical for me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if that would be a good or bad UX but I'm willing to try it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's something I've seen in other map implementations at least.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We agreed that we will implement in an upcoming PR.

@leonardehrenfried leonardehrenfried force-pushed the vector-debug branch 2 times, most recently from a2d58be to d17d9b7 Compare January 11, 2024 13:36
testower
testower previously approved these changes Jan 11, 2024
Copy link
Member

@abyrd abyrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Built locally and tested. UI started with:

cd client-next
npm install
npm run dev

Stop layer is visible and functioning as expected on the map. One comment: click-away from the stop popup closes the popup (in line with many other UIs), but if that click is right on another stop, it only closes the first one and doesn't open the second. The ability to click several stops one after the other to inspect them could be useful (open/close/open/close).

@leonardehrenfried
Copy link
Member Author

Stop layer is visible and functioning as expected on the map. One comment: click-away from the stop popup closes the popup (in line with many other UIs), but if that click is right on another stop, it only closes the first one and doesn't open the second. The ability to click several stops one after the other to inspect them could be useful (open/close/open/close).

I will take a look at this next time I touch the UI code.

@leonardehrenfried leonardehrenfried merged commit a1b7203 into opentripplanner:dev-2.x Jan 11, 2024
6 checks passed
@leonardehrenfried leonardehrenfried deleted the vector-debug branch January 11, 2024 16:03
t2gran pushed a commit that referenced this pull request Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OTP Debug UI The OTP bundled client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants