From cb8e564270ba33da158b4a8b6429ef4da9539fdc Mon Sep 17 00:00:00 2001 From: evlist Date: Mon, 16 Jan 2023 16:16:22 +0100 Subject: [PATCH] Dirty display of vector tiles feature properties in Infos.tsx --- src/components/gpx/styles.ts | 40 +++++++++++++------------ src/components/infos/Infos.tsx | 55 ++++++++++++++++++++++++++++++++-- src/components/map/Map.tsx | 2 +- 3 files changed, 74 insertions(+), 23 deletions(-) diff --git a/src/components/gpx/styles.ts b/src/components/gpx/styles.ts index 76f10c4..f1bf2cb 100644 --- a/src/components/gpx/styles.ts +++ b/src/components/gpx/styles.ts @@ -102,7 +102,7 @@ const textFillSel = new Fill({ }); const trksegStroke = new Stroke({ - color: 'blue', + color: [11, 16, 71, 0.8], width: 3, }); @@ -112,7 +112,7 @@ const trksegStrokeSel = new Stroke({ }); const rteStroke = new Stroke({ - color: 'green', + color: [18, 71, 11, 0.8], width: 3, }); @@ -288,16 +288,16 @@ const styles = { }), nwn: new Stroke({ color: [174, 33, 219, 0.8], - width: 4, + width: 5, }), rwn: new Stroke({ color: [174, 33, 219, 0.8], - width: 4, + width: 5, lineDash: [10, 10], }), lwn: new Stroke({ color: [174, 33, 219, 0.8], - width: 2, + width: 3, lineDash: [10, 10], }), }, @@ -332,12 +332,13 @@ const styles = { isSelected: feature.get('isSelected') ?? false, name: feature.get('name'), klass: feature.get('class'), - isHidden: zoom() < 14, + isTextHidden: zoom() < 19, + isHidden: zoom() < 16, }; }, getStyle: memoize((params: any) => { console.log({ caller: 'getStyle', params }); - const { isSelected, name, klass, isHidden } = params; + const { isSelected, name, klass, isHidden, isTextHidden } = params; if (isHidden) { return null; } @@ -352,18 +353,19 @@ const styles = { opacity: 1, // anchor: [0, 0], }), - text: name - ? new Text({ - text: name, - font: 'bold 14px "Open Sans", "Arial Unicode MS", "sans-serif"', - offsetY: +20, - padding: [0, 0, 0, 0], - fill: new Fill({ - color: 'black', - }), - backgroundFill: poiTextFill, - }) - : undefined, + text: + name && !isTextHidden + ? new Text({ + text: name, + font: 'bold 14px "Open Sans", "Arial Unicode MS", "sans-serif"', + offsetY: +40, + padding: [0, 0, 0, 0], + fill: new Fill({ + color: 'black', + }), + backgroundFill: poiTextFill, + }) + : undefined, }); }, memoizeOptions), }, diff --git a/src/components/infos/Infos.tsx b/src/components/infos/Infos.tsx index 1260a79..73056b8 100644 --- a/src/components/infos/Infos.tsx +++ b/src/components/infos/Infos.tsx @@ -21,6 +21,7 @@ const Item = styled(Paper)(({ theme }) => ({ const [open, setOpen] = createSignal(false); let selectedFeatures: Feature[] = []; +let vectorLayerFeatures: Feature[] = []; let hierarchy: any = {}; const level2Key = (feature: Feature) => @@ -39,6 +40,10 @@ export const clickHandler = (event: any) => { } }); selectedFeatures = features.filter((feature: any) => feature.get('context')); + vectorLayerFeatures = features.filter( + (feature: any) => !feature.get('context') + ); + selectedFeatures.sort((f1: Feature, f2: Feature) => { const ctx1 = f1.get('context'); const ctx2 = f2.get('context'); @@ -93,6 +98,7 @@ export const clickHandler = (event: any) => { event, features, hierarchy, + vectorLayerFeatures, }); selectedFeatures.map((feature: Feature) => { const id = feature.get('id'); @@ -108,7 +114,7 @@ export const clickHandler = (event: any) => { // length, }); }); - if (selectedFeatures.length > 0) { + if (selectedFeatures.length > 0 || vectorLayerFeatures.length > 0) { setOpen(true); } }; @@ -118,7 +124,7 @@ const FeaturesTree: Component<{ featuresHierarchy: any }> = ({ }) => { return ( key.startsWith('gpx/')) @@ -143,7 +149,50 @@ const Infos: Component<{}> = (props) => { alignItems='center' sx={{ width: 'calc(100% - 5px)' }} > - + + + + {(feature) => ( + + <> + {console.log({ + caller: 'Infos / vector layer feature', + properties: feature.getProperties(), + })} + + + {(key: string) => ( +
{`${key}: ${ + feature.getProperties()[key] + }`}
+ )} +
+ + } + subTree={undefined} + /> + )} +
+ + } + /> + + + } + /> ); diff --git a/src/components/map/Map.tsx b/src/components/map/Map.tsx index 827d037..38dcfb5 100644 --- a/src/components/map/Map.tsx +++ b/src/components/map/Map.tsx @@ -237,7 +237,7 @@ const Map: Component = () => { const vectorTileSource1 = new VectorTileSource({ format: new MVT(), - url: 'http://localhost:8081/services/aragon/tiles/{z}/{x}/{y}.pbf', + url: 'https://geo.dyomedea.com/services/spain/tiles/{z}/{x}/{y}.pbf', maxZoom: 14, });