From b493a58a54001b860985866ed6812ed7ab1a07ba Mon Sep 17 00:00:00 2001 From: Martin Alzueta Date: Mon, 24 Jun 2024 14:11:08 +0200 Subject: [PATCH 1/3] use source with data property --- src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx b/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx index 46f2b2523..6e9940bad 100644 --- a/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx +++ b/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx @@ -145,8 +145,10 @@ const MlGeoJsonLayer = (props: MlGeoJsonLayerProps) => { mapId: props.mapId, layerId: layerId.current, options: { - source: 'source-' + layerId.current, - ...props.options, + ...(typeof props?.options?.source !== 'undefined' && + typeof props?.options?.source !== 'string' + ? {source: 'source-' + layerId.current,} + : {source: props.options?.source}), paint: { ...(props.paint || getDefaultPaintPropsByType(layerType, props.defaultPaintOverrides)), ...props?.options?.paint, @@ -168,7 +170,10 @@ const MlGeoJsonLayer = (props: MlGeoJsonLayerProps) => { useLayer({ mapId: props.mapId, options: { - source: props.labelProp ? 'source-' + layerId.current : undefined, + ...(typeof props?.options?.source !== 'undefined' && + typeof props?.options?.source !== 'string' + ? {source: 'source-' + layerId.current,} + : {}), id: labelLayerId, type: 'symbol', maxzoom: 24, From cec569b0e56784369e6e6fd15051395f186631f1 Mon Sep 17 00:00:00 2001 From: Martin Alzueta Date: Mon, 24 Jun 2024 14:39:32 +0200 Subject: [PATCH 2/3] useLayar also with options.source undefined --- .../MlGeoJsonLayer/MlGeoJsonLayer.stories.tsx | 13 ++++++++++--- src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx | 14 +++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.tsx b/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.tsx index 4a0ac2b88..c9cec513d 100644 --- a/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.tsx +++ b/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.tsx @@ -21,6 +21,7 @@ import useMap from '../../hooks/useMap'; import useAddProtocol from '../../hooks/useAddProtocol/useAddProtocol'; import geoJsonDecorator from '../../decorators/GeoJsonMapDecorator'; import { OSMProtocolHandler } from '../../protocol_handlers/osm'; +import useSource from '../../hooks/useSource'; const storyoptions = { title: 'MapComponents/MlGeoJsonLayer', @@ -101,6 +102,11 @@ const OsmProtocolSourceDemo = () => { mapHook.map?.jumpTo({ center: [2.651811, 39.571309], zoom: 16.5 }); }, [mapHook.map]); + // useSource({sourceId: "test", source: { + // type: 'geojson', + // data: `osm://osm/palma.osm?completeFeature=true&allFeatures=false&renderTagged=false&excludeWay=false&suppressWay=false`, + // } }) + return ( <> { }, }} options={{ - source: { + source: + { type: 'geojson', data: `osm://osm/palma.osm?completeFeature=true&allFeatures=false&renderTagged=false&excludeWay=false&suppressWay=false`, }, }} labelProp="name" - labelOptions={{ + labelOptions={{ paint: { 'text-color': '#ff0000', }, @@ -505,4 +512,4 @@ DefaultPaintOverrides.args = { geojson: sample_geojson_1, type: 'fill' }; export const CatalogueDemo = catalogueTemplate.bind({}); CatalogueDemo.parameters = {}; -CatalogueDemo.args = {}; \ No newline at end of file +CatalogueDemo.args = {}; diff --git a/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx b/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx index 6e9940bad..a5cf40345 100644 --- a/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx +++ b/src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx @@ -144,11 +144,11 @@ const MlGeoJsonLayer = (props: MlGeoJsonLayerProps) => { useLayer({ mapId: props.mapId, layerId: layerId.current, - options: { + options: { ...(typeof props?.options?.source !== 'undefined' && - typeof props?.options?.source !== 'string' - ? {source: 'source-' + layerId.current,} - : {source: props.options?.source}), + typeof props?.options?.source === 'string' + ? {source: props.options.source} + : {source: 'source-' + layerId.current}), paint: { ...(props.paint || getDefaultPaintPropsByType(layerType, props.defaultPaintOverrides)), ...props?.options?.paint, @@ -171,9 +171,9 @@ const MlGeoJsonLayer = (props: MlGeoJsonLayerProps) => { mapId: props.mapId, options: { ...(typeof props?.options?.source !== 'undefined' && - typeof props?.options?.source !== 'string' - ? {source: 'source-' + layerId.current,} - : {}), + typeof props?.options?.source === 'string' + ? {source: props.options.source} + : {source: 'source-' + layerId.current}), id: labelLayerId, type: 'symbol', maxzoom: 24, From 08ae66a5670908fad4e863c461114df97d32bc74 Mon Sep 17 00:00:00 2001 From: Martin Alzueta Date: Mon, 24 Jun 2024 14:46:39 +0200 Subject: [PATCH 3/3] unused import removed --- src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.tsx b/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.tsx index c9cec513d..f62484ceb 100644 --- a/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.tsx +++ b/src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.tsx @@ -21,7 +21,6 @@ import useMap from '../../hooks/useMap'; import useAddProtocol from '../../hooks/useAddProtocol/useAddProtocol'; import geoJsonDecorator from '../../decorators/GeoJsonMapDecorator'; import { OSMProtocolHandler } from '../../protocol_handlers/osm'; -import useSource from '../../hooks/useSource'; const storyoptions = { title: 'MapComponents/MlGeoJsonLayer',