Skip to content

On click overlapping elements, both area triggered #265

@ramonmsp

Description

@ramonmsp

Hey!
I am trying to select a Polygon overlapping other. As a result I got both triggered. How can I trigger just the small one?

 const handleInternalClick = (e) => {
    console.log("internal");
  };

  const handleExternalClick = (e) => {
    console.log("external");
  };
 <React.Fragment>
      <RMap
        className="example-map"
        initial={{ center: fromLonLat(coords.origin), zoom: 9 }}
      >
        <ROSM />
        <RLayerVector zIndex={10}>
          <RFeature
            geometry={
              new Polygon([
                [
                  fromLonLat(coords.PlaceDItalie),
                  fromLonLat(coords.Bastille),
                  fromLonLat(coords.point),
                  fromLonLat(coords.TourEiffel),
                ],
              ])
            }
            onClick={handleExternalClick}
          >
            <RStyle>
              <RStroke color="yellow" width={4} />
              <RFill color="#FFFf004D" />
            </RStyle>

            <RFeature geometry={new Point(fromLonLat(coords.Montmartre))}>
              <RStyle>
                <RIcon src={locationIcon} />
              </RStyle>
            </RFeature>
          </RFeature>
          <RLayerVector zIndex={100}>
            <RFeature
              geometry={
                new Polygon([
                  [
                    fromLonLat(internalCoords.coord1),
                    fromLonLat(internalCoords.coord2),
                    fromLonLat(internalCoords.coord3),
                    fromLonLat(internalCoords.coord4),
                    fromLonLat(internalCoords.coord5),
                    fromLonLat(internalCoords.coord6),
                  ],
                ])
              }
              onClick={handleInternalClick}
            >
              <RStyle>
                <RStroke color="red" width={4} />
                <RFill color="#d1001f4D" />
              </RStyle>
            </RFeature>
          </RLayerVector>
        </RLayerVector>
      </RMap>
    </React.Fragment>

rlayers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions