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

fix(v11,ios): implement filter and sourceId for v11 layers #3390

Merged
merged 1 commit into from Feb 23, 2024

Conversation

mfazekas
Copy link
Contributor

@mfazekas mfazekas commented Feb 22, 2024

In V11 sourceLayer source and filter properties moved from base Layer to applicable Layer subclasses. So setOptions no longer applies those settings:

#if !RNMBX_11
if let sourceLayerID = sourceLayerID {
layer.sourceLayer = sourceLayerID
}
if let sourceID = sourceID {
if !(existingLayer && sourceID == DEFAULT_SOURCE_ID) && hasSource() {
layer.source = sourceID
}
}
if let filter = filter, filter.count > 0 {
do {
let data = try JSONSerialization.data(withJSONObject: filter, options: .prettyPrinted)
let decodedExpression = try JSONDecoder().decode(Expression.self, from: data)
layer.filter = decodedExpression
} catch {
Logger.log(level: .error, message: "parsing filters failed for layer \(optional: id): \(error.localizedDescription)")
}
}
#endif

See https://github.com/mapbox/mapbox-maps-ios/blob/main/CHANGELOG.md

Remove source, sourceLayer, filter properties from the Layer protocol requirement.

Used the following component to test:

import React from 'react';
import {
  MapView,
  ShapeSource,
  CircleLayer,
  Camera,
  Models,
  ModelLayer,
} from '@rnmapbox/maps';

const styles = {
  mapView: { flex: 1 },
  circleLayer: {
    circleRadiusTransition: { duration: 5000, delay: 0 },
    circleColor: '#ff0000',
  },
};

const features = {
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      id: 'a-feature',
      properties: {
        icon: 'example',
        text: 'example-icon-and-label',
      },
      geometry: {
        type: 'Point',
        coordinates: [-74.00597, 40.71427],
      },
    },
    {
      type: 'Feature',
      id: 'b-feature',
      properties: {
        text: 'just-label',
      },
      geometry: {
        type: 'Point',
        coordinates: [-74.001097, 40.71527],
      },
    },
    {
      type: 'Feature',
      id: 'c-feature',
      properties: {
        shown: 'visible',
        icon: 'example',
      },
      geometry: {
        type: 'Point',
        coordinates: [-74.00697, 40.72427],
      },
    },
  ],
};

const modelLayerStyle = {
  modelId: 'car',
  modelScale: [50, 50, 50],
};

const models = {
  car: require('../../assets/sportcar.glb'),
};

class SimpleModelLayer extends React.Component {
  state = {
    radius: 20,
  };

  render() {
    const circleLayerStyle = {
      ...styles.circleLayer,
      ...{ circleRadius: this.state.radius },
    };

    return (
      <>
        <MapView style={styles.mapView}>
          <Camera
            defaultSettings={{
              centerCoordinate: [-74.00597, 40.71427],
              zoomLevel: 14,
            }}
          />
          <Models models={models} />
          <ShapeSource id={'shape-source-id-0'} shape={features}>
            <CircleLayer
              id={'circle-layer'}
              filter={['==', ['get', 'shown'], 'visible']}
              style={circleLayerStyle}
              slot={'bottom'}
            />
            <ModelLayer
              id="model-layer-id"
              style={modelLayerStyle}
              filter={['==', ['get', 'shown'], 'visible']}
            />
          </ShapeSource>
        </MapView>
      </>
    );
  }
}

export default SimpleModelLayer;

image

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.

None yet

1 participant