-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBasicRaster.svelte
121 lines (113 loc) · 4.36 KB
/
BasicRaster.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<script lang="ts">
import { HTTPTileDataSource } from '@nativescript-community/ui-carto/datasources/http';
import { LocalVectorDataSource } from '@nativescript-community/ui-carto/datasources/vector';
import { RasterTileLayer } from '@nativescript-community/ui-carto/layers/raster';
import { VectorLayer } from '@nativescript-community/ui-carto/layers/vector';
import { CartoMap } from '@nativescript-community/ui-carto/ui';
import { PanningMode } from '@nativescript-community/ui-carto/ui';
import { setShowDebug, setShowError, setShowInfo, setShowWarn } from '@nativescript-community/ui-carto/utils';
import { Line, LineEndType, LineJointType, LineStyleBuilder } from '@nativescript-community/ui-carto/vectorelements/line';
import { Marker, MarkerStyleBuilder } from '@nativescript-community/ui-carto/vectorelements/marker';
import { Point, PointStyleBuilder } from '@nativescript-community/ui-carto/vectorelements/point';
import { goBack } from 'svelte-native';
let cartoMap: CartoMap;
let rasterLayer: RasterTileLayer;
function logEvent(e) {
console.log(e.eventName, Object.keys(e))
}
function onMainMapReady(e) {
cartoMap = e.object as CartoMap;
console.log('onMainMapReady');
const options = cartoMap.getOptions();
options.setRestrictedPanning(true);
options.setPanningMode(PanningMode.PANNING_MODE_STICKY_FINAL);
options.setEnvelopeThreadPoolSize(2);
options.setTileThreadPoolSize(2);
options.setZoomGestures(true);
options.setDoubleClickMaxDuration(0.3);
options.setLongClickDuration(0.5);
options.setKineticRotation(false);
cartoMap.setFocusPos({ longitude: 6, latitude: 45 }, 0);
const dataSource = new HTTPTileDataSource({
minZoom: 0,
maxZoom: 22,
url: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
httpHeaders: {
'User-Agent': 'NSvelteDemo'
}
});
rasterLayer = new RasterTileLayer({
dataSource,
zoomLevelBias: 1
// opacity: 0.5
});
cartoMap.addLayer(rasterLayer);
const localDataSource = new LocalVectorDataSource({
projection: cartoMap.projection
});
const vectorLayer = new VectorLayer({
dataSource: localDataSource,
visibleZoomRange: [0, 24]
});
cartoMap.addLayer(vectorLayer);
const markerStyleBuilder = new MarkerStyleBuilder({
size: 30,
color: '#00FF00'
});
const marker = new Marker({
projection: cartoMap.projection,
styleBuilder: markerStyleBuilder,
position: {
latitude: 45.1887104,
longitude: 5.7013257
}
});
localDataSource.add(marker);
const pointStyleBuilder = new PointStyleBuilder({
size: 30,
color: '#ff0000'
});
const point = new Point({
projection: cartoMap.projection,
styleBuilder: pointStyleBuilder,
position: {
latitude: 45.1887104,
longitude: 5.6813257
}
});
localDataSource.add(point);
const lineStyleBuilder = new LineStyleBuilder({
width: 6,
endType: LineEndType.SQUARE,
joinType: LineJointType.ROUND,
color: '#0000ff'
});
const line = new Line({
projection: cartoMap.projection,
styleBuilder: lineStyleBuilder,
positions: [
{
latitude: 45.1187104,
longitude: 5.6813257
},
{
latitude: 45.1287104,
longitude: 5.3813257
},
{
latitude: 45.1887104,
longitude: 5.6813257
}
]
});
localDataSource.add(line);
}
</script>
<page>
<actionBar title="Basic Pager">
<navigationButton text="Go back" on:tap={() => goBack()} />
</actionBar>
<gridLayout class="page">
<cartomap zoom="10" on:mapReady={onMainMapReady} on:mapMove={logEvent} on:mapStable={logEvent} on:mapIdle={logEvent} on:mapClicked={logEvent} on:mapInteraction={logEvent}/>
</gridLayout>
</page>