Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/components/MlGeoJsonLayer/MlGeoJsonLayer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,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 (
<>
<MlGeoJsonLayer
Expand All @@ -112,13 +117,14 @@ const OsmProtocolSourceDemo = () => {
},
}}
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',
},
Expand Down Expand Up @@ -505,4 +511,4 @@ DefaultPaintOverrides.args = { geojson: sample_geojson_1, type: 'fill' };

export const CatalogueDemo = catalogueTemplate.bind({});
CatalogueDemo.parameters = {};
CatalogueDemo.args = {};
CatalogueDemo.args = {};
13 changes: 9 additions & 4 deletions src/components/MlGeoJsonLayer/MlGeoJsonLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,11 @@ const MlGeoJsonLayer = (props: MlGeoJsonLayerProps) => {
useLayer({
mapId: props.mapId,
layerId: layerId.current,
options: {
source: 'source-' + layerId.current,
...props.options,
options: {
...(typeof props?.options?.source !== 'undefined' &&
typeof props?.options?.source === 'string'
? {source: props.options.source}
: {source: 'source-' + layerId.current}),
paint: {
...(props.paint || getDefaultPaintPropsByType(layerType, props.defaultPaintOverrides)),
...props?.options?.paint,
Expand All @@ -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' &&
Copy link
Member

Choose a reason for hiding this comment

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

props.labelProp must still be checked and in case it is undefined options.source prop of label/symbol useLayer hook must be set to undefined to prevent its initialization.

typeof props?.options?.source === 'string'
? {source: props.options.source}
: {source: 'source-' + layerId.current}),
id: labelLayerId,
type: 'symbol',
maxzoom: 24,
Expand Down