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 support for using SDF template images #640

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

Buthrakaur
Copy link

style.addImages supports sdf flag on both Android and iOS but React Native didn't support it - this PR adds the support so it's possible to use SDF template images on the map by settings the sdf flag to true along with relevant icon re-coloring styles e.g. iconColor. Code sample:

const images = {  x: { uri: 'https://example.com/1.png', sdf: true } };
...
<Images images={images} />

@KiwiKilian
Copy link
Collaborator

@Buthrakaur could you give an example here too? Thanks!

@Buthrakaur
Copy link
Author

@KiwiKilian

import { Images, MapView, ShapeSource, SymbolLayer } from '@maplibre/maplibre-react-native';
import React, { useEffect, useMemo, useState } from 'react';

export function BugReport() {
  const featuresCollection: GeoJSON.FeatureCollection = useMemo(() => {
    const features: GeoJSON.Feature[] = [];

    for (let i = 1; i <= 10; i++) {
      features.push({
        type: 'Feature',
        id: i,
        properties: {
          icon: 'icon1',
          title: `POI ${i}`,
        },
        geometry: {
          type: 'Point',
          coordinates: [14.4282 + i * 0.02, 50.0806125],
        },
      });
    }

    return { type: 'FeatureCollection', features };
  }, []);

  const images = useMemo(
    () => ({
      icon1: { uri: 'https://placehold.co/32/orange/white/png', sdf: true },
    }),
    []
  );

  return (
    <MapView style={{ flex: 1 }}>
      <Images images={images} />
      <ShapeSource id="ss-1" shape={featuresCollection}>
        <SymbolLayer id="sl-1" style={{ iconImage: ['get', 'icon'], iconSize: 1 / 2, iconColor: 'pink' }} />
      </ShapeSource>
    </MapView>
  );
}

@KiwiKilian
Copy link
Collaborator

Thanks, I still have this on my radar. Hoping to have some time soon. Thanks for your patience!

Copy link
Collaborator

@KiwiKilian KiwiKilian left a comment

Choose a reason for hiding this comment

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

What's your use-case for SDF images? I think SDFs in general in MapLibre are a sub-optimal feature, due to the limitations in quality.

If you want to proceed with this please address the issues and rebase your branch. Sorry for the conflicts now due to the reformatting. If you are struggling to fix these by yourself, you can move the branch to a personal repository, create a new PR and allow maintainers to push into it, then I could help you with fixing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

These changes have to be made within scripts/templates/MLRNStyle.m.ejs. Then run yarn run codegen which writes this file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like you still have to run yarn run codegen and commit these changes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Buthrakaur please run yarn run codegen in the root of your branch and commit the changes.

@KiwiKilian
Copy link
Collaborator

Here is an example with an actual SDF image:

import {
  Images,
  MapView,
  ShapeSource,
  SymbolLayer,
} from "@maplibre/maplibre-react-native";

export function BugReport() {
  return (
    <MapView style={{ flex: 1 }}>
      <Images
        images={{
          "example-icon": {
            uri: "https://docs.mapbox.com/help/demos/using-recolorable-images-in-mapbox-maps/shop-15.png",
            sdf: true,
          },
        }}
      />
      <ShapeSource id="ss-1" shape={{ type: "Point", coordinates: [0, 0] }}>
        <SymbolLayer
          id="sl-1"
          style={{
            iconImage: "example-icon",
            iconColor: "red",
          }}
        />
      </ShapeSource>
    </MapView>
  );
}

jakub-oone and others added 6 commits March 18, 2025 17:36
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…libre#723)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@Buthrakaur Buthrakaur requested a review from KiwiKilian March 20, 2025 09:43
@Buthrakaur
Copy link
Author

Hello @KiwiKilian , could you please help us resolve the failing checks? We don't understand the build process completely thus don't understand what's wrong here.

@tyrauber
Copy link
Collaborator

Hey @Buthrakaur, I could be wrong, but I think it may be because you committed changes to the yarn.lock without changes to a package.json?

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.

4 participants