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

Rewrite debug.html to show and inspect all layers #820

Merged
merged 13 commits into from
Sep 3, 2023

Conversation

sharkAndshark
Copy link
Collaborator

@sharkAndshark sharkAndshark commented Aug 17, 2023

Try to resolve #536, but still it can't show the function source without comment...

  • Show all layers with correct geometry type
  • Inspect feature property
  • Allow to scroll popup content with max-height and a vertical scroll bar
  • Allow to stop the popup showing after click outside
  • It's possible to select text when the popup it's fixed

Maybe we should have an inspect toggle?

@sharkAndshark
Copy link
Collaborator Author

sharkAndshark commented Aug 17, 2023

Some refs.

Core code in mapbox-gl-inspect:

function circleLayer(color, source, vectorLayer) {
  var layer = {
    id: [source, vectorLayer, 'circle'].join('_'),
    source: source,
    type: 'circle',
    paint: {
      'circle-color': color,
      'circle-radius': 2
    },
    filter: ['==', '$type', 'Point']
  };
  if (vectorLayer) {
    layer['source-layer'] = vectorLayer;
  }
  return layer;
}

function polygonLayer(color, outlineColor, source, vectorLayer) {
  var layer = {
    id: [source, vectorLayer, 'polygon'].join('_'),
    source: source,
    type: 'fill',
    paint: {
      'fill-color': color,
      'fill-antialias': true,
      'fill-outline-color': color
    },
    filter: ['==', '$type', 'Polygon']
  };
  if (vectorLayer) {
    layer['source-layer'] = vectorLayer;
  }
  return layer;
}

function lineLayer(color, source, vectorLayer) {
  var layer = {
    id: [source, vectorLayer, 'line'].join('_'),
    source: source,
    layout: {
      'line-join': 'round',
      'line-cap': 'round'
    },
    type: 'line',
    paint: {
      'line-color': color
    },
    filter: ['==', '$type', 'LineString']
  };
  if (vectorLayer) {
    layer['source-layer'] = vectorLayer;
  }
  return layer;
}

 Object.keys(sources).forEach(function (sourceId) {
    var layers = sources[sourceId];

    if (!layers || layers.length === 0) {
      var colors = alphaColors(sourceId);
      circleLayers.push(circleLayer(colors.circle, sourceId));
      lineLayers.push(lineLayer(colors.line, sourceId));
      polyLayers.push(polygonLayer(colors.polygon, colors.polygonOutline, sourceId));
    } else {
      layers.forEach(function (layerId) {
        var colors = alphaColors(layerId);

        circleLayers.push(circleLayer(colors.circle, sourceId, layerId));
        lineLayers.push(lineLayer(colors.line, sourceId, layerId));
        polyLayers.push(polygonLayer(colors.polygon, colors.polygonOutline, sourceId, layerId));
      });
    }
  });

@nyurik
Copy link
Member

nyurik commented Aug 18, 2023

thanks! we ought to find a way to discover available layers... we may even have to add that to MapLibre-web itself

@sharkAndshark sharkAndshark force-pushed the debughtml branch 2 times, most recently from c356820 to a6c3328 Compare August 30, 2023 05:47
@sharkAndshark sharkAndshark marked this pull request as ready for review August 30, 2023 05:48
@sharkAndshark sharkAndshark changed the title Improve debug.html Rewrite debug.html to show and inspect all layers Aug 30, 2023
@sharkAndshark sharkAndshark changed the title Rewrite debug.html to show and inspect all layers Rewrite debug.html to show and inspect all layers Aug 30, 2023
@sharkAndshark sharkAndshark requested a review from nyurik August 30, 2023 06:02
@nyurik
Copy link
Member

nyurik commented Aug 30, 2023

why would we want an inspect toggle? It makes sense for a site that shows all geometries with complex rules (e.g. Maputnik with all the rules). But for the debug screen, we essentially always want to have inspect enabled.

@sharkAndshark
Copy link
Collaborator Author

I was wondering that. But yeah, It's a debug screen. We need the inspect mode all the time.

@nyurik
Copy link
Member

nyurik commented Aug 30, 2023

i did a minor cleanup of the sources - i think you have a similar bug here - see #853

@sharkAndshark
Copy link
Collaborator Author

sharkAndshark commented Aug 30, 2023

Oops. I missed the changes in Future-proof source catalog after rebase

@nyurik
Copy link
Member

nyurik commented Aug 30, 2023

I love this new approach!!! There are a few minor things I think we need to fix before merging:

  • only show tag popup for the enabled layers, not for the base map
  • it should be possible to click on the map to fix the popup in place. If a user clicks while the popup is shown:
    • the popup stops following the mouse
    • new popups should not show until i click outside of the current popup
    • the popup should have maximum height
    • the popup should have a vertical scroll bar
    • it should be possible to select text in the popup while its fixed in place

@nyurik
Copy link
Member

nyurik commented Aug 30, 2023

P.S. do we want to remove color picker here?

@nyurik
Copy link
Member

nyurik commented Aug 30, 2023

P.P.S. some layers are not clickable. Is it because they are polygons? If so, we may want to disable them for now? Show them as grayed out

@sharkAndshark
Copy link
Collaborator Author

sharkAndshark commented Aug 31, 2023

They are unclickable because we don't know the layer info in function source without comment

The reason why previous version debug.html can show them without vector_layer in tilejson is:

  • Name each layer by its source name
  • Display each layer as circle type

But we shouldn't assume that each source has a layer with the same name(though we hard coded same name layers in test/sql files), and we shouldn't assume each layer is circle type.

@sharkAndshark
Copy link
Collaborator Author

What's the expected behavior for color picker here? It's possible to have many layers in one source:

  • Should we change all the related layers' color after the color is picked?
  • Should we nested the layers like a tree in left bar? Then maybe we should set a color picker for each layer

@nyurik
Copy link
Member

nyurik commented Aug 31, 2023

I'm not sure we can do anything meaningful with random colors or color groups. Rather, I think we can just generate random colors on each layer enable -- this way if someone wants different colors, they can disable/re-enable the layer.

@nyurik
Copy link
Member

nyurik commented Aug 31, 2023

I added a few minor cleanups in sharkAndshark#51 please merge if agree.

For some reason your debug.html does not hide popup when I move the mouse away from the point.

@sharkAndshark sharkAndshark marked this pull request as draft September 1, 2023 09:18
@sharkAndshark sharkAndshark marked this pull request as ready for review September 1, 2023 16:54
* change color on each enable
* show color when the button is selected
@nyurik nyurik enabled auto-merge (squash) September 3, 2023 01:38
Copy link
Member

@nyurik nyurik left a comment

Choose a reason for hiding this comment

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

thanks!!!

@nyurik nyurik merged commit d6f3908 into maplibre:main Sep 3, 2023
@sharkAndshark sharkAndshark deleted the debughtml branch September 3, 2023 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve MapLibre demo to show all available lines/points/polygons from all sources
2 participants