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

feat: Models and ModelLayer #3209

Merged
merged 5 commits into from
Nov 29, 2023
Merged

feat: Models and ModelLayer #3209

merged 5 commits into from
Nov 29, 2023

Conversation

mfazekas
Copy link
Contributor

@mfazekas mfazekas commented Nov 29, 2023

Sample component:

import React from 'react';
import { Button } from 'react-native';
import {
  Images,
  MapView,
  ShapeSource,
  SymbolLayer,
  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: {
        icon: 'example',
      },
      geometry: {
        type: 'Point',
        coordinates: [-74.00697, 40.72427],
      },
    },
  ],
};

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

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

    return (
      <>
        <Button
          title="Grow"
          onPress={() => this.setState({ radius: this.state.radius + 20 })}
        />
        <MapView
          style={styles.mapView}
          styleURL="mapbox://styles/mapbox/standard-beta"
        >
          <Camera centerCoordinate={[-74.00597, 40.71427]} zoomLevel={14} />
          <Images images={{ example: require('../assets/example.png') }} />
          <Models models={{ car: require('../assets/sportcar.glb') }} />
          <ShapeSource id={'shape-source-id-0'} shape={features}>
            <CircleLayer
              id={'circle-layer'}
              style={circleLayerStyle}
              slot={'bottom'}
            />
            <SymbolLayer
              id="symbol-id"
              style={{
                iconImage: ['get', 'icon'],
              }}
              slot={'middle'}
            />
            <ModelLayer
              id="model-layer-id"
              style={{
                modelId: 'car',
                modelScale: [50, 50, 50],
              }}
            />
          </ShapeSource>
        </MapView>
      </>
    );
  }
}

export default BugReportExample;

image

image
image

@mfazekas mfazekas force-pushed the model-layer branch 5 times, most recently from 76e9a5c to 2278f03 Compare November 29, 2023 20:59
@mfazekas mfazekas marked this pull request as ready for review November 29, 2023 21:00
@mfazekas mfazekas merged commit 983bfcf into main Nov 29, 2023
9 checks passed
@mfazekas mfazekas deleted the model-layer branch November 29, 2023 22:45
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.

1 participant