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

[Bug]: Onpress only works if layers are nested like jsx components #3042

Closed
BubbleTrouble14 opened this issue Sep 12, 2023 · 7 comments
Closed

Comments

@BubbleTrouble14
Copy link

BubbleTrouble14 commented Sep 12, 2023

Mapbox Implementation

Mapbox

Mapbox Version

10.7.10

Platform

Android

@rnmapbox/maps version

10.0.13

Standalone component to reproduce

import React from 'react';
import {
  MapView,
  ShapeSource,
  LineLayer,
  Camera,
  VectorSource,
  FillLayer,
} from '@rnmapbox/maps';

//The part which is commeted out works, triggers the on press. The other one doesnt though.

class BugReportExample extends React.Component {
  render() {
    return (
      <MapView style={{flex: 1}}>
        <Camera centerCoordinate={[-74.00597, 40.71427]} zoomLevel={14} />
        <ShapeSource
          id="polygonSource"
          onPress={() => {
            console.log('pressed');
          }}
          shape={{
            type: 'Feature',
            properties: {},
            geometry: {
              coordinates: [
                [
                  [4.029480413140874, 49.4026975280301],
                  [4.029480413140874, 46.99045121353802],
                  [11.44274825303006, 46.99045121353802],
                  [11.44274825303006, 49.4026975280301],
                  [4.029480413140874, 49.4026975280301],
                ],
              ],
              type: 'Polygon',
            },
          }}>
          {/* <FillLayer
            id="polygonFill"
            style={{fillOpacity: 0.6, fillColor: 'blue'}}
          /> */}
        </ShapeSource>
        <FillLayer
          id="polygonFill"
          sourceLayerID="polygonSource"
          sourceID="polygonSource"
          style={{fillOpacity: 0.6, fillColor: 'blue'}}
        />
      </MapView>
    );
  }
}

Observed behavior and steps to reproduce

No response

Expected behavior

No response

Notes / preliminary analysis

No response

Additional links and references

No response

@mfazekas
Copy link
Contributor

@BubbleTrouble14 pls do not use tileUrlTemplates={["..."]} as I won't be able to run this component as is.

@BubbleTrouble14
Copy link
Author

Okay, ill edit it to use a geoJson

@BubbleTrouble14
Copy link
Author

Also I am experiencing some bug after v10.0.13 no fill layers are showing anymore. Even the code above doesn't render anything. It works on ios but not on my androids. Not on the emulator or real device. Also tried the latest rc build no luck. So currenlty sticking with v10.0.13.

@BubbleTrouble14
Copy link
Author

RNMapboxMapsImpl = "mapbox"

@mfazekas
Copy link
Contributor

@BubbleTrouble14 pls correct coordinate in your example as right now the camera is different place than the polygons

@mfazekas
Copy link
Contributor

@BubbleTrouble14 I've released 10.0.15-rc.0 that should fix the layer not rendering issue on android. Pls confirm that.

For the onPress only working for nested layers that's the way it works. We should document it, but I don't see it a huge deal for apps otherwise.

func highestZIndex(sources: [RCTMGLInteractiveElement]) -> RCTMGLInteractiveElement? {
var layersToSource : [String:RCTMGLInteractiveElement] = [:]
sources.forEach { source in
source.getLayerIDs().forEach { layerId in
if layersToSource[layerId] == nil {
layersToSource[layerId] = source
}
}
}
let orderedLayers = mapboxMap.style.allLayerIdentifiers
return orderedLayers.lazy.reversed().compactMap { layersToSource[$0.id] }.first ?? sources.first
}

if let source = self.highestZIndex(sources: touchedSources),

override func getLayerIDs() -> [String] {
layers.compactMap {
if let layer = $0 as? RCTMGLLayer {
return layer.id
} else {
return nil
}
}
}

@BubbleTrouble14
Copy link
Author

@mfazekas Ah makes sense, wasn't sure if it was intentional or not. Using queryRenderedFeaturesAtPoint allows me to do what I need. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants