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

Implement ShapeSource.features and throw if source is not yet available #911

Merged
merged 2 commits into from
Jun 9, 2020

Conversation

mfazekas
Copy link
Contributor

@mfazekas mfazekas commented Jun 9, 2020

Closes: #905

@mfazekas mfazekas force-pushed the fix-point-ann-remove-from-map branch from eb3710e to 6000aa3 Compare June 9, 2020 15:08
@mfazekas mfazekas changed the title Fix point ann remove from map Implement ShapeSource.features and throw if source is not yet available Jun 9, 2020
@mfazekas
Copy link
Contributor Author

mfazekas commented Jun 9, 2020

Example to reprot the null source with features

import React from 'react';
import {Button} from 'react-native';
import {
  MapView,
  ShapeSource,
  SymbolLayer,
  CircleLayer,
  Camera,
  Images,
} from '@react-native-mapbox-gl/maps';

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() {
    return (
      <>
        <Button
          title="Grow"
          onPress={() => this.setState({radius: this.state.radius + 20})}
        />
        <MapView style={{flex: 1}}>
          <Camera centerCoordinate={[-74.00597, 40.71427]} zoomLevel={14} />
          <ShapeSource
            id={'shape-source-id-0'}
            shape={features}
            ref={async (ref) => {
              if (ref) {
                try {
                  let features = await ref.features();
                  console.log('Features', features);
                } catch (e) {
                  console.log('[E]', e.name, 'msg', e.message);
                }
              }
            }}>
            <CircleLayer
              id={'circle-layer'}
              style={{
                circleRadius: this.state.radius,
                circleRadiusTransition: {duration: 5000},
                circleColor: '#ff0000',
              }}
            />
            <SymbolLayer
              id="symbol-id"
              style={{
                iconImage: ['get', 'icon'],
              }}
            />
          </ShapeSource>
        </MapView>
      </>
    );
  }
}

export default BugReportExample;

@mfazekas mfazekas merged commit 6b70715 into rnmapbox:master Jun 9, 2020
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