Skip to content
This repository was archived by the owner on May 21, 2022. It is now read-only.

Implement ON_MAP_SHAPE_CLICKED and allow title popup for shapes #118

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions HTML/src/MapShapes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
PolylineProps,
PolygonProps,
RectangleProps,
CircleProps
CircleProps,
Popup
} from "react-leaflet";
import { MapShapeType, MapShape, WebViewLeafletEvents } from "./models";

Expand Down Expand Up @@ -46,7 +47,15 @@ class MapShapes extends React.Component<MapMapShapesProps> {
<>
{this.props.mapShapes.map(mapShape => {
const props = { ...mapShape, color: mapShape.color ?? "white" };
return <this.Shape {...props} key={Math.random().toString()} />;
return <this.Shape {...props} key={mapShape.id || Math.random().toString()}
onClick={() => {
this.props.onMapEvent(WebViewLeafletEvents.ON_MAP_SHAPE_CLICKED, {
mapShapeID: mapShape.id
});
}}
>
{mapShape.title && <Popup>{mapShape.title}</Popup>}
</this.Shape>
})}
</>
);
Expand Down
5 changes: 3 additions & 2 deletions HTML/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export enum WebViewLeafletEvents {
ON_ZOOM_START = "onZoomStart",
ON_ZOOM = "onZoom",
ON_MAP_TOUCHED = "onMapClicked",
ON_MAP_MARKER_CLICKED = "onMapMarkerClicked"
// ON_MAP_SHAPE_CLICKED = "onMapShapeClicked" cannot click on shapes yet
ON_MAP_MARKER_CLICKED = "onMapMarkerClicked",
ON_MAP_SHAPE_CLICKED = "onMapShapeClicked"
}

export enum AnimationType {
Expand Down Expand Up @@ -103,6 +103,7 @@ export interface MapLayer {
}

export interface MapShape {
title?: string;
bounds?: LatLng[];
center?: LatLng;
color?: string;
Expand Down
2 changes: 1 addition & 1 deletion HTML/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"forceConsistentCasingInFileNames": false,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
Expand Down
2 changes: 1 addition & 1 deletion WebViewLeaflet/assets/index.html

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions WebViewLeaflet/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export enum WebViewLeafletEvents {
ON_ZOOM_START = "onZoomStart",
ON_ZOOM = "onZoom",
ON_MAP_TOUCHED = "onMapClicked",
ON_MAP_MARKER_CLICKED = "onMapMarkerClicked"
// ON_MAP_SHAPE_CLICKED = "onMapShapeClicked" cannot click on shapes yet
ON_MAP_MARKER_CLICKED = "onMapMarkerClicked",
ON_MAP_SHAPE_CLICKED = "onMapShapeClicked"
}

export enum AnimationType {
Expand Down Expand Up @@ -103,6 +103,7 @@ export interface MapLayer {
}

export interface MapShape {
title?: string;
bounds?: LatLng[];
center?: LatLng;
color?: string;
Expand Down
2 changes: 1 addition & 1 deletion WebViewLeaflet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-webview-leaflet",
"version": "5.0.2",
"version": "5.0.3",
"description": "A React Native component that uses a React Native WebView to provide a Leaflet map.",
"repository": {
"type": "git",
Expand Down