Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>nativescript-carto</name>
<name>ui-carto</name>
<comment>Project nativescript-carto created by Buildship.</comment>
<projects>
</projects>
Expand Down
21 changes: 5 additions & 16 deletions src/ui-carto/core/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,12 @@ import { BaseNative } from '../BaseNative';
import { AltitudeKey, DefaultLatLonKeys, GenericMapPos, LatitudeKey, LongitudeKey, MapVec, ScreenBounds, ScreenPos } from './index.common';
export * from './index.common';

export const ClickType = {
get SINGLE() {
return com.carto.ui.ClickType.CLICK_TYPE_SINGLE;
},
get LONG() {
return com.carto.ui.ClickType.CLICK_TYPE_LONG;
},
get DOUBLE() {
return com.carto.ui.ClickType.CLICK_TYPE_DOUBLE;
},
get DUAL() {
return com.carto.ui.ClickType.CLICK_TYPE_DUAL;
}
};

export class MapBounds<T = DefaultLatLonKeys> extends BaseNative<com.carto.core.MapBounds, {}> {
constructor(public northeast?: GenericMapPos<T>, public southwest?: GenericMapPos<T>, native?: com.carto.core.MapBounds) {
constructor(
public northeast?: GenericMapPos<T>,
public southwest?: GenericMapPos<T>,
native?: com.carto.core.MapBounds
) {
super(undefined, native);
}
createNative() {
Expand Down
8 changes: 8 additions & 0 deletions src/ui-carto/core/index.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ export class ScreenBounds {
min: ScreenPos;
max: ScreenPos;
}

export enum ClickType {
SINGLE,
LONG,
DOUBLE,
DUAL
}

// export namespace MapBounds {
// function fromCoordinates(southwest: MapPos, northeast: MapPos): MapBounds;
// }
Expand Down
13 changes: 5 additions & 8 deletions src/ui-carto/core/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ import { BaseNative } from '../BaseNative';
import { AltitudeKey, DefaultLatLonKeys, GenericMapPos, LatitudeKey, LongitudeKey, MapVec, ScreenBounds, ScreenPos } from './index.common';
export * from './index.common';

export enum ClickType {
SINGLE = NTClickType.T_CLICK_TYPE_SINGLE,
LONG = NTClickType.T_CLICK_TYPE_LONG,
DOUBLE = NTClickType.T_CLICK_TYPE_DOUBLE,
DUAL = NTClickType.T_CLICK_TYPE_DUAL
}

export class MapBounds<T = DefaultLatLonKeys> extends BaseNative<NTMapBounds, {}> {
constructor(public northeast?: GenericMapPos<T>, public southwest?: GenericMapPos<T>, native?: NTMapBounds) {
constructor(
public northeast?: GenericMapPos<T>,
public southwest?: GenericMapPos<T>,
native?: NTMapBounds
) {
super(undefined, native);
}
createNative() {
Expand Down
101 changes: 42 additions & 59 deletions src/ui-carto/ui/index.android.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ClickType,
DefaultLatLonKeys,
MapBounds,
MapPos,
Expand All @@ -16,19 +17,10 @@ import {
import { Layer, TileLayer } from '../layers';
import { IProjection } from '../projections';
import { restrictedPanningProperty } from './cssproperties';
import {
Layers as BaseLayers,
CartoViewBase,
MapClickedEvent,
MapIdleEvent,
MapInteractionEvent,
MapMovedEvent,
MapReadyEvent,
MapStableEvent
} from './index.common';
import { Layers as BaseLayers, CartoViewBase, MapClickedEvent, MapIdleEvent, MapInteractionEvent, MapMovedEvent, MapReadyEvent, MapStableEvent } from './index.common';

import { ImageSource, Property, Utils, booleanConverter } from '@nativescript/core';
import { MapOptions } from '.';
import { MapClickInfo, MapGestureInfo, MapInteractionInfo, MapOptions } from '.';
import { EPSG4326 } from '../projections/epsg4326';
export { MapClickedEvent, MapIdleEvent, MapMovedEvent, MapReadyEvent, MapStableEvent };

Expand Down Expand Up @@ -111,63 +103,54 @@ export class CartoMap<T = DefaultLatLonKeys> extends CartoViewBase {
}
const listener = new com.akylas.carto.additions.AKMapEventListener({
onMapIdle: () => {
if (this.hasListeners(MapIdleEvent)) {
this.sendEvent(MapIdleEvent);
}
this.sendEvent(MapIdleEvent);
},
onMapMoved: (userAction: boolean) => {
if (this.hasListeners(MapMovedEvent)) {
this.sendEvent(MapMovedEvent, { userAction });
}
this.sendEvent<MapGestureInfo>(MapMovedEvent, { userAction });
},
onMapInteraction: (interaction: com.carto.ui.MapInteractionInfo, userAction: boolean) => {
if (this.hasListeners(MapInteractionEvent)) {
this.sendEvent(MapInteractionEvent, {
interaction: {
userAction,
get isAnimationStarted() {
return interaction.isAnimationStarted();
},
get isPanAction() {
return interaction.isPanAction();
},
get isRotateAction() {
return interaction.isRotateAction();
},
get isTiltAction() {
return interaction.isTiltAction();
},
get isZoomAction() {
return interaction.isZoomAction();
}
this.sendEvent<MapInteractionInfo>(MapInteractionEvent, {
userAction,
interaction: {
get isAnimationStarted() {
return interaction.isAnimationStarted();
},
get isPanAction() {
return interaction.isPanAction();
},
get isRotateAction() {
return interaction.isRotateAction();
},
get isTiltAction() {
return interaction.isTiltAction();
},
get isZoomAction() {
return interaction.isZoomAction();
}
});
}
}
});
},
onMapStable: (userAction: boolean) => {
if (this.hasListeners(MapStableEvent)) {
this.sendEvent(MapStableEvent, { userAction });
}
this.sendEvent<MapGestureInfo>(MapStableEvent, { userAction });
},
onMapClicked: (mapClickInfo: com.carto.ui.MapClickInfo) => {
if (this.hasListeners(MapClickedEvent)) {
this.sendEvent(MapClickedEvent, {
android: mapClickInfo,
get clickInfo() {
return {
get duration() {
return mapClickInfo.getClickInfo().getDuration();
}
};
},
get clickType() {
return mapClickInfo.getClickType();
},
get position() {
return fromNativeMapPos(mapClickInfo.getClickPos());
}
});
}
this.sendEvent<MapClickInfo>(MapClickedEvent, {
android: mapClickInfo,
get clickInfo() {
return {
get duration(): number {
return mapClickInfo.getClickInfo().getDuration();
}
};
},
get clickType(): ClickType {
// This will return an integer value that can be compared with the actual enum
return mapClickInfo.getClickType().swigValue();
},
get position() {
return fromNativeMapPos(mapClickInfo.getClickPos());
}
});
}
});
this.nativeViewProtected.listener = listener;
Expand Down
11 changes: 9 additions & 2 deletions src/ui-carto/ui/index.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { CSSType, ContentView } from '@nativescript/core';
import { BaseNative } from '../BaseNative';
import { LatitudeKey, MapPos, fromNativeMapPos } from '../core';
import { Layer } from '../layers';
import { nativeVectorToArray } from '../utils';
import { bearingProperty, focusPosProperty, tiltProperty, zoomProperty } from './cssproperties';
import { MapInfo } from '.';

export const MapReadyEvent = 'mapReady';
export const MapStableEvent = 'mapStable';
Expand Down Expand Up @@ -95,6 +95,13 @@ export abstract class Layers<T = any> extends BaseNative<T, {}> {

@CSSType('CartoMap')
export abstract class CartoViewBase extends ContentView {
public static mapReadyEvent = MapReadyEvent;
public static mapStableEvent = MapStableEvent;
public static mapIdleEvent = MapIdleEvent;
public static mapMovedEvent = MapMovedEvent;
public static mapInteractionEvent = MapInteractionEvent;
public static mapClickedEvent = MapClickedEvent;

public mapReady = false;
nativeProjection: any;
@mapProperty({
Expand All @@ -116,7 +123,7 @@ export abstract class CartoViewBase extends ContentView {
@mapProperty maxZoom: number;
@mapProperty restrictedPanning: boolean;

public sendEvent(eventName: string, data?) {
public sendEvent<T extends MapInfo = MapInfo>(eventName: string, data?: T) {
if (this.hasListeners(eventName)) {
this.notify({
eventName,
Expand Down
71 changes: 55 additions & 16 deletions src/ui-carto/ui/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EventData, ImageSource, Style, View } from '@nativescript/core';
import { DefaultLatLonKeys, GenericMapPos, MapBounds, ScreenBounds, ScreenPos } from '../core';
import { ClickType, DefaultLatLonKeys, GenericMapPos, MapBounds, ScreenBounds, ScreenPos } from '../core';
import { Layer } from '../layers';
import { Projection } from '../projections';
import { Layers } from './index.common';
Expand Down Expand Up @@ -31,27 +31,53 @@ export const MapIdleEvent: string;
export const MapMovedEvent: string;
export const MapClickedEvent: string;

export interface MapInfo {}

export interface MapGestureInfo extends MapInfo {
userAction: boolean;
}

export interface MapInteractionInfo extends MapGestureInfo {
interaction: {
isAnimationStarted: boolean;
isPanAction: boolean;
isRotateAction: boolean;
isTiltAction: boolean;
isZoomAction: boolean;
};
}

export interface MapClickInfo<T = DefaultLatLonKeys> extends MapInfo {
android?: any;
ios?: any;
clickInfo: {
duration: number;
};
clickType: ClickType;
position: GenericMapPos<T>;
}

export interface MapEventData extends EventData {
data: any;
data?: MapInfo;
}
export interface MapPosEventData<T = DefaultLatLonKeys> extends EventData {
MapPos: GenericMapPos<T>;
}

export interface MapClickInfo<T = DefaultLatLonKeys> {
clickType: number,
clickInfo:{
duration:number
},
position: GenericMapPos<T>;
export interface MapMovedEventData extends MapEventData {
data: MapGestureInfo;
}
export interface MapInteractionInfo {
userAction: boolean;
isAnimationStarted: boolean;
isPanAction: boolean;
isRotateAction: boolean;
isTiltAction: boolean;
isZoomAction: boolean;

export interface MapStableEventData extends MapEventData {
data: MapGestureInfo;
}

export interface MapInteractionEventData extends MapEventData {
data: MapInteractionInfo;
}

export interface MapClickedEventData extends MapEventData {
data: MapClickInfo;
}

export class MapOptions {
Expand Down Expand Up @@ -177,7 +203,7 @@ export class MapOptions {
setLongClickDuration(param0: number): void;
getDoubleClickMaxDuration(): number;
setDoubleClickMaxDuration(param0: number): void;
setLayersLabelsProcessedInReverseOrder(enabled: boolean): void;
setLayersLabelsProcessedInReverseOrder(enabled: boolean): void;
isLayersLabelsProcessedInReverseOrder(): boolean;
}

Expand All @@ -192,6 +218,13 @@ interface CartoMapStyle extends Style {
}

export class CartoMap<T = DefaultLatLonKeys> extends View {
public static mapReadyEvent = 'mapReady';
public static mapStableEvent = 'mapStable';
public static mapIdleEvent = 'mapIdle';
public static mapMovedEvent = 'mapMoved';
public static mapInteractionEvent = 'mapInteraction';
public static mapClickedEvent = 'mapClicked';

public static setRunOnMainThread(value: boolean);
public projection: Projection;
focusPos: GenericMapPos<T>;
Expand Down Expand Up @@ -225,4 +258,10 @@ export class CartoMap<T = DefaultLatLonKeys> extends View {
clearPreloadingCaches();
cancelAllTasks();
captureRendering(wait?: boolean): Promise<ImageSource>;

on(event: 'mapReady' | 'mapIdle', callback: (args: EventData) => void, thisArg?: any): void;
on(event: 'mapStable', callback: (args: MapStableEventData) => void, thisArg?: any): void;
on(event: 'mapMoved', callback: (args: MapMovedEventData) => void, thisArg?: any): void;
on(event: 'mapInteraction', callback: (args: MapInteractionEventData) => void, thisArg?: any): void;
on(event: 'mapClicked', callback: (args: MapClickedEventData) => void, thisArg?: any): void;
}
Loading