Skip to content

Commit

Permalink
LongPress functionality for android and ios #266
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Oct 11, 2018
1 parent 05606a2 commit af02a0a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 26 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ exports.onMapReady = onMapReady;
```

The methods you can invoke like this from an XML-declared map are:
`addMarkers`, `setViewport`, `removeMarkers`, `getCenter`, `setCenter`, `getZoomLevel`, `setZoomLevel`, `getViewport`, `getTilt`, `setTilt`, `setMapStyle`, `animateCamera`, `addPolygon`, `removePolygons`, `addPolyline`, `removePolylines`, `getUserLocation`, `trackUser`, `setOnMapClickListener` and `destroy`.
`addMarkers`, `setViewport`, `removeMarkers`, `getCenter`, `setCenter`, `getZoomLevel`, `setZoomLevel`, `getViewport`, `getTilt`, `setTilt`, `setMapStyle`, `animateCamera`, `addPolygon`, `removePolygons`, `addPolyline`, `removePolylines`, `getUserLocation`, `trackUser`, `setOnMapClickListener`, `setOnMapLongClickListener` and `destroy`.

Check out the usage details on the functions below.

Expand Down Expand Up @@ -571,6 +571,15 @@ Add a listener to retrieve lat and lng of where the user taps the map (not a mar
});
```

### setOnMapLongClickListener
Add a listener to retrieve lat and lng of where the user longpresses the map (not a marker).

```typescript
mapbox.setOnMapLongClickListener((point: LatLng) => {
console.log("Map longpressed at latitude: " + point.lat + ", longitude: " + point.lng);
});
```

### setOnScrollListener
Add a listener to retrieve lat and lng of where the user scrolls to on the map.

Expand Down
2 changes: 2 additions & 0 deletions demo/app/main-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ function onMapReady(args) {

map.setOnMapClickListener((point: LatLng) => console.log(`Map tapped: ${JSON.stringify(point)}`));

map.setOnMapLongClickListener((point: LatLng) => console.log(`Map longpressed: ${JSON.stringify(point)}`));

// this works perfectly fine, but generates a lot of noise
// map.setOnScrollListener((point?: LatLng) => console.log(`Map scrolled: ${JSON.stringify(point)}`));

Expand Down
2 changes: 2 additions & 0 deletions demo/app/main-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export class HelloWorldModel extends Observable {

this.mapbox.setOnMapClickListener(point => console.log(`>> Map clicked: ${JSON.stringify(point)}`));

this.mapbox.setOnMapLongClickListener(point => console.log(`>> Map longpressed: ${JSON.stringify(point)}`));

this.mapbox.setOnScrollListener((point: LatLng) => {
// console.log(`>> Map scrolled: ${JSON.stringify(point)}`);
});
Expand Down
1 change: 1 addition & 0 deletions src/mapbox.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,7 @@ class MapLongPressHandlerImpl extends NSObject {
"longPress": {returns: interop.types.void, params: [interop.types.id]}
};
}

class MapPanHandlerImpl extends NSObject {
private _owner: WeakRef<Mapbox>;
private _listener: (data?: LatLng) => void;
Expand Down
48 changes: 24 additions & 24 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-mapbox",
"version": "4.3.0",
"version": "4.3.1",
"description": "Native Maps, by Mapbox.",
"main": "mapbox",
"typings": "index.d.ts",
Expand Down

0 comments on commit af02a0a

Please sign in to comment.