react-leaflet#CircleMarker TypeScript Examples

The following examples show how to use react-leaflet#CircleMarker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StationMarker.tsx    From metro-fare with MIT License 6 votes vote down vote up
StationMarker = (props: any) => {
  const { station, showPopup = true } = props;
  const { i18n } = useTranslation();
  const stationName = `(${station.id}) ${getStationName(
    station,
    i18n.language
  )}`;

  return (
    <CircleMarker
      center={station.position}
      radius={10}
      color="black"
      weight={1.5}
      fillOpacity={1}
      {...props}
    >
      {showPopup && (
        <StationPopup stationName={stationName} stationId={station.id} />
      )}
      <Tooltip>{stationName}</Tooltip>
    </CircleMarker>
  );
}
Example #2
Source File: GroupRoute.tsx    From project-tauntaun with GNU Lesser General Public License v3.0 4 votes vote down vote up
export function GroupRoute(props: GroupRouteProps) {
  const { selectWaypoint } = SelectionStateContainer.useContainer();
  const colors = React.useContext(ColorContext);

  const { isSelected: isSelectedProp, group, editable, showWaypointNames } = props;

  const isSelected = isSelectedProp ? isSelectedProp : false;
  const positions = group.points.map(point => new LatLng(point.position.lat, point.position.lon));
  const labels = group.points.map((point, i) => ({
    text: `[${i.toString()}] ${point.name}`,
    position: new LatLng(point.position.lat, point.position.lon)
  }));

  const handlePositionInserted = (index: number, pos: LatLng) => {
    const oldPoint = group.points[index];

    gameService.sendRouteInsertAt(group, oldPoint.position, {
      lat: pos.lat,
      lon: pos.lng
    });

    console.log(`Point inserted at [${index}]`);
  };

  const handlePositionModified = (index: number, pos: LatLng) => {
    const oldPoint = group.points[index];

    gameService.sendRouteModify(group, oldPoint.position, {
      ...oldPoint,
      position: {
        lat: pos.lat,
        lon: pos.lng
      }
    });

    console.log('Point modified.');
  };

  const handlePositionRemoved = (index: number) => {
    const oldPoint = group.points[index];

    gameService.sendRouteRemove(group, oldPoint.position);

    console.log(`Point removed ${index}`);
  };

  const handlePositionClicked = (index: number) => {
    // TODO check for isleadofflight / commander -> ableToSelect -> extract to context
    selectWaypoint(index);

    console.log('Point clicked.', index);
  };

  const renderNonEditableWp = (position: LatLng, index: number) => (
    <CircleMarker
      interactive={false}
      key={`WpMarker_${index}`}
      center={position}
      radius={isSelected ? 7 : 4}
      fillOpacity={0}
      color={colors.color}
      weight={1}
    />
  );

  return (
    <React.Fragment>
      <EditablePolyline
        positions={positions}
        color={colors.color}
        stroke={true}
        weight={2}
        opacity={colors.opacity}
        dashArray={colors.dashArray}
        onPositionInserted={handlePositionInserted}
        onPositionModified={handlePositionModified}
        onPositionRemoved={handlePositionRemoved}
        onPositionClicked={handlePositionClicked}
        drawMarkers={editable}
        disableWpZero={true}
      />
      {!editable && positions.map((p, i) => renderNonEditableWp(p, i))}
      {isSelected && <DistanceMarkers positions={positions} />}
      {showWaypointNames &&
        labels.map((v, i) => (
          <TextMarker
            key={`maptext${i}`}
            text={v.text}
            position={v.position}
            color={colors.color}
            backgroundColor={'white'}
          />
        ))}
    </React.Fragment>
  );
}