pygeobox 1.0.0__py3-none-any.whl → 1.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pygeobox/map.py CHANGED
@@ -1,858 +1,858 @@
1
- from typing import Dict, List, Optional, Union, TYPE_CHECKING
2
- from urllib.parse import urljoin, urlencode
3
-
4
- from .base import Base
5
- from .utils import clean_data
6
- from .model3d import Model
7
-
8
- if TYPE_CHECKING:
9
- from . import GeoboxClient
10
- from .user import User
11
- from .task import Task
12
-
13
-
14
- class Map(Base):
15
-
16
- BASE_ENDPOINT = 'maps/'
17
-
18
- def __init__(self,
19
- api: 'GeoboxClient',
20
- uuid: str,
21
- data: Optional[Dict] = {}):
22
- """
23
- Initialize a Map instance.
24
-
25
- Args:
26
- api (GeoboxClient): The GeoboxClient instance for making requests.
27
- name (str): The name of the map.
28
- uuid (str): The unique identifier for the map.
29
- data (Dict, optional): The data of the map.
30
- """
31
- self.map_layers = {
32
- 'layers': []
33
- }
34
- super().__init__(api, uuid=uuid, data=data)
35
-
36
-
37
- @classmethod
38
- def get_maps(cls, api: 'GeoboxClient', **kwargs) -> Union[List['Map'], int]:
39
- """
40
- Get list of maps with optional filtering and pagination.
41
-
42
- Args:
43
- api (GeoboxClient): The GeoboxClient instance for making requests.
44
-
45
- Keyword Args:
46
- q (str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
47
- search (str): search term for keyword-based searching among search_fields or all textual fields if search_fields does not have value. NOTE: if q param is defined this param will be ignored.
48
- search_fields (str): comma separated list of fields for searching.
49
- order_by (str): comma separated list of fields for sorting results [field1 A|D, field2 A|D, …]. e.g. name A, type D. NOTE: "A" denotes ascending order and "D" denotes descending order.
50
- return_count (bool): Whether to return total count. default is False.
51
- skip (int): Number of items to skip. default is 0.
52
- limit (int): Number of items to return. default is 10.
53
- user_id (int): Specific user. privileges required.
54
- shared (bool): Whether to return shared maps. default is False.
55
-
56
- Returns:
57
- List[Map] | int: A list of Map instances or the total number of maps.
58
-
59
- Example:
60
- >>> from geobox import GeoboxClient
61
- >>> from geobox.map import Map
62
- >>> client = GeoboxClient()
63
- >>> maps = Map.get_maps(client, q="name LIKE '%My Map%'")
64
- or
65
- >>> maps = client.get_maps(q="name LIKE '%My Map%'")
66
- """
67
- params = {
68
- 'f': 'json',
69
- 'q': kwargs.get('q'),
70
- 'search': kwargs.get('search'),
71
- 'search_fields': kwargs.get('search_fields'),
72
- 'order_by': kwargs.get('order_by'),
73
- 'return_count': kwargs.get('return_count', False),
74
- 'skip': kwargs.get('skip', 0),
75
- 'limit': kwargs.get('limit', 10),
76
- 'user_id': kwargs.get('user_id'),
77
- 'shared': kwargs.get('shared', False)
78
- }
79
- return super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: Map(api, item['uuid'], item))
80
-
81
-
82
- @classmethod
83
- def create_map(cls,
84
- api: 'GeoboxClient',
85
- name: str,
86
- display_name: str = None,
87
- description: str = None,
88
- extent: List[float] = None,
89
- thumbnail: str = None,
90
- style: Dict = None,
91
- user_id: int = None) -> 'Map':
92
- """
93
- Create a new map.
94
-
95
- Args:
96
- api (GeoboxClient): The GeoboxClient instance for making requests.
97
- name (str): The name of the map.
98
- display_name (str, optional): The display name of the map.
99
- description (str, optional): The description of the map.
100
- extent (List[float], optional): The extent of the map.
101
- thumbnail (str, optional): The thumbnail of the map.
102
- style (Dict, optional): The style of the map.
103
- user_id (int, optional): Specific user. privileges required.
104
-
105
- Returns:
106
- Map: The newly created map instance.
107
-
108
- Raises:
109
- ValidationError: If the map data is invalid.
110
-
111
- Example:
112
- >>> from geobox import GeoboxClient
113
- >>> from geobox.map import Map
114
- >>> client = GeoboxClient()
115
- >>> map = Map.create_map(client, name="my_map", display_name="My Map", description="This is a description of my map", extent=[10, 20, 30, 40], thumbnail="https://example.com/thumbnail.png", style={"type": "style"})
116
- or
117
- >>> map = client.create_map(name="my_map", display_name="My Map", description="This is a description of my map", extent=[10, 20, 30, 40], thumbnail="https://example.com/thumbnail.png", style={"type": "style"})
118
- """
119
- data = {
120
- "name": name,
121
- "display_name": display_name,
122
- "description": description,
123
- "extent": extent,
124
- "thumbnail": thumbnail,
125
- "style": style,
126
- "user_id": user_id,
127
- }
128
- return super()._create(api, cls.BASE_ENDPOINT, data, factory_func=lambda api, item: Map(api, item['uuid'], item))
129
-
130
-
131
- @classmethod
132
- def get_map(cls, api: 'GeoboxClient', uuid: str, user_id: int = None) -> 'Map':
133
- """
134
- Get a map by its UUID.
135
-
136
- Args:
137
- api (GeoboxClient): The GeoboxClient instance for making requests.
138
- uuid (str): The UUID of the map to get.
139
- user_id (int, optional): Specific user. privileges required.
140
-
141
- Returns:
142
- Map: The map object.
143
-
144
- Raises:
145
- NotFoundError: If the map with the specified UUID is not found.
146
-
147
- Example:
148
- >>> from geobox import GeoboxClient
149
- >>> from geobox.map import Map
150
- >>> client = GeoboxClient()
151
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
152
- or
153
- >>> map = client.get_map(uuid="12345678-1234-5678-1234-567812345678")
154
- """
155
- params = {
156
- 'f': 'json',
157
- 'user_id': user_id,
158
- }
159
- return super()._get_detail(api, cls.BASE_ENDPOINT, uuid, params, factory_func=lambda api, item: Map(api, item['uuid'], item))
160
-
161
-
162
- @classmethod
163
- def get_map_by_name(cls, api: 'GeoboxClient', name: str, user_id: int = None) -> Union['Map', None]:
164
- """
165
- Get a map by name
166
-
167
- Args:
168
- api (GeoboxClient): The GeoboxClient instance for making requests.
169
- name (str): the name of the map to get
170
- user_id (int, optional): specific user. privileges required.
171
-
172
- Returns:
173
- Map | None: returns the map if a map matches the given name, else None
174
-
175
- Example:
176
- >>> from geobox import GeoboxClient
177
- >>> from geobox.map import Map
178
- >>> client = GeoboxClient()
179
- >>> map = Map.get_map_by_name(client, name='test')
180
- or
181
- >>> map = client.get_map_by_name(name='test')
182
- """
183
- maps = cls.get_maps(api, q=f"name = '{name}'", user_id=user_id)
184
- if maps and maps[0].name == name:
185
- return maps[0]
186
- else:
187
- return None
188
-
189
-
190
- def update(self, **kwargs) -> Dict:
191
- """
192
- Update the map.
193
-
194
- Keyword Args:
195
- name (str): The name of the map.
196
- display_name (str): The display name of the map.
197
- description (str): The description of the map.
198
- extent (List[float]): The extent of the map.
199
- thumbnail (str): The thumbnail of the map.
200
- style (Dict): The style of the map.
201
-
202
- Returns:
203
- Dict: The updated map data.
204
-
205
- Raises:
206
- ValidationError: If the map data is invalid.
207
-
208
- Example:
209
- >>> from geobox import GeoboxClient
210
- >>> from geobox.map import Map
211
- >>> client = GeoboxClient()
212
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
213
- >>> map.update(display_name="New Display Name")
214
- """
215
- data = {
216
- "name": kwargs.get('name'),
217
- "display_name": kwargs.get('display_name'),
218
- "description": kwargs.get('description'),
219
- "extent": kwargs.get('extent'),
220
- "thumbnail": kwargs.get('thumbnail'),
221
- "style": kwargs.get('style'),
222
- }
223
- return super()._update(self.endpoint, data)
224
-
225
-
226
- def delete(self) -> None:
227
- """
228
- Delete the map.
229
-
230
- Returns:
231
- None
232
-
233
- Example:
234
- >>> from geobox import GeoboxClient
235
- >>> from geobox.map import Map
236
- >>> client = GeoboxClient()
237
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
238
- >>> map.delete()
239
- """
240
- super().delete(self.endpoint)
241
-
242
-
243
- @property
244
- def style(self) -> Dict:
245
- """
246
- Get the style of the map.
247
-
248
- Returns:
249
- Dict: The style of the map.
250
-
251
- Example:
252
- >>> from geobox import GeoboxClient
253
- >>> from geobox.map import Map
254
- >>> client = GeoboxClient()
255
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
256
- >>> map.style
257
- """
258
- endpoint = urljoin(self.endpoint, 'style/')
259
- response = self.api.get(endpoint)
260
- return response
261
-
262
-
263
- @property
264
- def thumbnail(self) -> str:
265
- """
266
- Get the thumbnail URL of the map.
267
-
268
- Returns:
269
- str: The thumbnail of the map.
270
-
271
- Example:
272
- >>> from geobox import GeoboxClient
273
- >>> from geobox.map import Map
274
- >>> client = GeoboxClient()
275
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
276
- >>> map.thumbnail
277
- 'https://example.com/thumbnail.png'
278
- """
279
- endpoint = f"{self.api.base_url}{self.endpoint}thumbnail.png"
280
- return endpoint
281
-
282
-
283
- def set_readonly(self, readonly: bool) -> None:
284
- """
285
- Set the readonly status of the map.
286
-
287
- Args:
288
- readonly (bool): The readonly status of the map.
289
-
290
- Returns:
291
- None
292
-
293
- Example:
294
- >>> from geobox import GeoboxClient
295
- >>> from geobox.map import Map
296
- >>> client = GeoboxClient()
297
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
298
- >>> map.set_readonly(True)
299
- """
300
- data = clean_data({
301
- 'readonly': readonly
302
- })
303
- endpoint = urljoin(self.endpoint, 'setReadonly/')
304
- response = self.api.post(endpoint, data, is_json=False)
305
- self._update_properties(response)
306
-
307
-
308
- def set_multiuser(self, multiuser: bool) -> None:
309
- """
310
- Set the multiuser status of the map.
311
-
312
- Args:
313
- multiuser (bool): The multiuser status of the map.
314
-
315
- Returns:
316
- None
317
-
318
- Example:
319
- >>> from geobox import GeoboxClient
320
- >>> from geobox.map import Map
321
- >>> client = GeoboxClient()
322
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
323
- >>> map.set_multiuser(True)
324
- """
325
- data = clean_data({
326
- 'multiuser': multiuser
327
- })
328
- endpoint = urljoin(self.endpoint, 'setMultiuser/')
329
- response = self.api.post(endpoint, data, is_json=False)
330
- self._update_properties(response)
331
-
332
-
333
-
334
- def wmts(self, scale: int = None) -> str:
335
- """
336
- Get the WMTS URL of the map.
337
-
338
- Args:
339
- scale (int): The scale of the map. value are: 1, 2
340
-
341
- Returns:
342
- str: The WMTS URL of the map.
343
-
344
- Example:
345
- >>> from geobox import GeoboxClient
346
- >>> from geobox.map import Map
347
- >>> client = GeoboxClient()
348
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
349
- >>> map.wmts(scale=1)
350
- """
351
- endpoint = urljoin(self.api.base_url, f'{self.endpoint}wmts/')
352
- if scale:
353
- endpoint = f"{endpoint}?scale={scale}"
354
- return endpoint
355
-
356
-
357
- def share(self, users: List['User']) -> None:
358
- """
359
- Shares the map with specified users.
360
-
361
- Args:
362
- users (List[User]): The list of user objects to share the map with.
363
-
364
- Returns:
365
- None
366
-
367
- Example:
368
- >>> from geobox import GeoboxClient
369
- >>> from geobox.map import Map
370
- >>> client = GeoboxClient()
371
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
372
- >>> users = client.search_users(search='John')
373
- >>> map.share(users=users)
374
- """
375
- super()._share(self.endpoint, users)
376
-
377
-
378
- def unshare(self, users: List['User']) -> None:
379
- """
380
- Unshares the map with specified users.
381
-
382
- Args:
383
- users (List[User]): The list of user objects to unshare the map with.
384
-
385
- Returns:
386
- None
387
-
388
- Example:
389
- >>> from geobox import GeoboxClient
390
- >>> from geobox.map import Map
391
- >>> client = GeoboxClient()
392
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
393
- >>> users = client.search_users(search='John')
394
- >>> map.unshare(users=users)
395
- """
396
- super()._unshare(self.endpoint, users)
397
-
398
-
399
- def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
400
- """
401
- Retrieves the list of users the map is shared with.
402
-
403
- Args:
404
- search (str, optional): The search query.
405
- skip (int, optional): The number of users to skip.
406
- limit (int, optional): The maximum number of users to retrieve.
407
-
408
- Returns:
409
- List[User]: The list of shared users.
410
-
411
- Example:
412
- >>> from geobox import GeoboxClient
413
- >>> from geobox.map import Map
414
- >>> client = GeoboxClient()
415
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
416
- >>> map.get_shared_users(search='John', skip=0, limit=10)
417
- """
418
- params = {
419
- 'search': search,
420
- 'skip': skip,
421
- 'limit': limit
422
- }
423
- return super()._get_shared_users(self.endpoint, params)
424
-
425
-
426
- def seed_cache(self,
427
- from_zoom: int = None,
428
- to_zoom: int = None,
429
- extent: List[float] = None,
430
- workers: int = 1,
431
- user_id: int = None,
432
- scale: int = None) -> List['Task']:
433
- """
434
- Seed the cache of the map.
435
-
436
- Args:
437
- from_zoom (int, optional): The zoom level to start caching from.
438
- to_zoom (int, optional): The zoom level to stop caching at.
439
- extent (List[float], optional): The extent of the map.
440
- workers (int, optional): The number of workers to use. default is 1.
441
- user_id (int, optional): Specific user. privileges required.
442
- scale (int, optional): The scale of the map.
443
-
444
- Returns:
445
- List[Task]: The task instance of the cache seeding operation.
446
-
447
- Raises:
448
- ValueError: If the workers is not in [1, 2, 4, 8, 12, 16, 20, 24].
449
- ValueError: If the cache seeding fails.
450
-
451
- Example:
452
- >>> from geobox import GeoboxClient
453
- >>> from geobox.map import Map
454
- >>> client = GeoboxClient()
455
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
456
- >>> task = map.seed_cache(from_zoom=0, to_zoom=10, extent=[10, 20, 30, 40], workers=1, scale=1)
457
- """
458
- data = {
459
- 'from_zoom': from_zoom,
460
- 'to_zoom': to_zoom,
461
- 'extent': extent,
462
- 'workers': workers,
463
- 'user_id': user_id,
464
- 'scale': scale
465
- }
466
- return super()._seed_cache(self.endpoint, data)
467
-
468
-
469
- def update_cache(self,
470
- from_zoom: int = None,
471
- to_zoom: int = None,
472
- extent: List[float] = None,
473
- user_id: int = None,
474
- scale: int = None) -> List['Task']:
475
- """
476
- Update the cache of the map.
477
-
478
- Args:
479
- from_zoom (int, optional): The zoom level to start caching from.
480
- to_zoom (int, optional): The zoom level to stop caching at.
481
- extent (List[float], optional): The extent of the map.
482
- user_id (int, optional): Specific user. privileges required.
483
- scale (int, optional): The scale of the map.
484
-
485
- Returns:
486
- List[Task]: The task instance of the cache updating operation.
487
-
488
- Raises:
489
- ValueError: If the cache updating fails.
490
-
491
- Example:
492
- >>> from geobox import GeoboxClient
493
- >>> from geobox.map import Map
494
- >>> client = GeoboxClient()
495
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
496
- >>> map.update_cache(from_zoom=0, to_zoom=10, extent=[10, 20, 30, 40], scale=1)
497
- """
498
- data = {
499
- 'from_zoom': from_zoom,
500
- 'to_zoom': to_zoom,
501
- 'extent': extent,
502
- 'user_id': user_id,
503
- 'scale': scale
504
- }
505
- return super()._update_cache(self.endpoint, data)
506
-
507
-
508
- def clear_cache(self) -> None:
509
- """
510
- Clear the cache of the map.
511
-
512
- Returns:
513
- None
514
-
515
- Example:
516
- >>> from geobox import GeoboxClient
517
- >>> from geobox.map import Map
518
- >>> client = GeoboxClient()
519
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
520
- >>> map.clear_cache()
521
- """
522
- return super()._clear_cache(self.endpoint)
523
-
524
-
525
- @property
526
- def cache_size(self) -> int:
527
- """
528
- Get the size of the cache of the map.
529
-
530
- Returns:
531
- int: The size of the cache of the map.
532
-
533
- Example:
534
- >>> from geobox import GeoboxClient
535
- >>> from geobox.map import Map
536
- >>> client = GeoboxClient()
537
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
538
- >>> map.cache_size
539
- """
540
- return super()._cache_size(self.endpoint)
541
-
542
-
543
- @property
544
- def settings(self) -> Dict:
545
- """
546
- Get the settings of the map
547
-
548
- Returns:
549
- Dict: the settings of the map.
550
-
551
- Example:
552
- >>> from geobox import GeoboxClient
553
- >>> from geobox.map import Map
554
- >>> client = GeoboxClient()
555
- >>> map = Map.get_map(uuid="12345678-1234-5678-1234-567812345678")
556
- >>> map.settings
557
- """
558
- return self.json.get('settings', {
559
- 'general_settings': {},
560
- 'edit_settings': {},
561
- 'snap_settings': {},
562
- 'controls': [],
563
- 'search_settings': {},
564
- 'marker_settings': {},
565
- 'terrain_settings': {},
566
- 'grid_settings': {},
567
- 'view_settings': {},
568
- 'toc_settings': []
569
- })
570
-
571
-
572
- def set_settings(self, **kwargs) -> Dict:
573
- """
574
- Set the settings of the map.
575
-
576
- Keyword Args:
577
- map_unit (str): 'latlng' | 'utm'.
578
- base_map (str): 'OSM' | 'google' | 'blank'.
579
- flash_color (str): 'rgb(255,0,0)' (rgb color or rgba color or hex color ).
580
- highlight_color (str): 'rgb(255,0,0)' (rgb color or rgba color or hex color ).
581
- selection_color (str): 'rgb(255,0,0)' (rgb color or rgba color or hex color ).
582
- selectable_layers (str): 'ALL' | null | Comma separated list of layers.
583
- calendar_type (str): The type of the calendar.
584
- edit_settings (dict): The settings of the edit.
585
- snap_tolerance (int): number of pixels for snap tolerance.
586
- snap_unit (str): pixels.
587
- snap_mode (str): 'both' | 'edge' | 'vertex'.
588
- snap_cache (int): number of total features for snap cache.
589
- controls (List[str]): The controls of the map.
590
- search_mode (str): 'both' | 'markers' | 'layers'.
591
- search_layers (str): 'ALL' | null | Comma separated list of layers.
592
- geosearch (bool): The geosearch of the map.
593
- remove_unused_tags (bool): The remove unused tags of the map.
594
- terrain_layer (str): The terrain layer of the map.
595
- exaggeration (int): The exaggeration of the terrain.
596
- enable_grid (bool): The enable grid of the map.
597
- grid_unit (str): The unit of the grid.
598
- grid_width (int): The width of the grid.
599
- grid_height (int): The height of the grid.
600
- grid_minzoom (int): The minzoom of the grid.
601
- grid_maxzoom (int): The maxzoom of the grid.
602
- bearing (int): The bearing of the map.
603
- pitch (int): The pitch of the map.
604
- center (List[float]): The center of the map.
605
- zoom (int): The zoom of the map.
606
- toc_settings (List): The settings of the toc.
607
- custom_basemaps (List[str]): The custom basemaps of the map.
608
- show_maptip_on (str): 'ALL' | null | Comma separated list of layers.
609
- snappable_layers (str): 'ALL' | null | Comma separated list of layers.
610
-
611
- Returns:
612
- Dict: The response of the API.
613
- """
614
- general_settings = {'map_unit', 'base_map', 'flash_color', 'highlight_color',
615
- 'selection_color', 'selectable_layers', 'calendar_type', 'custom_basemaps', 'show_maptip_on'}
616
- edit_settings = {'editable_layers', 'target_layer'}
617
- snap_settings = {'snap_tolerance', 'snap_unit', 'snap_mode', 'snap_cache', 'snappable_layers'}
618
- search_settings = {'search_mode', 'search_layers', 'geosearch'}
619
- marker_settings = {'remove_unused_tags'}
620
- terrain_settings = {'terrain_layer', 'exaggeration'}
621
- grid_settings = {'enable_grid', 'grid_unit', 'grid_width', 'grid_height', 'grid_minzoom', 'grid_maxzoom'}
622
- view_settings = {'bearing', 'pitch', 'center', 'zoom'}
623
-
624
- for key, value in kwargs.items():
625
- if key in general_settings:
626
- self.settings['general_settings'][key] = value
627
- elif key in edit_settings:
628
- self.settings['edit_settings'][key] = value
629
- elif key in snap_settings:
630
- self.settings['snap_settings'][key] = value
631
- elif key == 'controls':
632
- self.settings['controls'] = value
633
- elif key in search_settings:
634
- self.settings['search_settings'][key] = value
635
- elif key in marker_settings:
636
- self.settings['marker_settings'][key] = value
637
- elif key in terrain_settings:
638
- self.settings['terrain_settings'][key] = value
639
- elif key in grid_settings:
640
- self.settings['grid_settings'][key] = value
641
- elif key in view_settings:
642
- self.settings['view_settings'][key] = value
643
- elif key == 'toc_settings':
644
- self.settings['toc_settings'] = value
645
-
646
- endpoint = urljoin(self.endpoint, 'settings/')
647
- self.api.put(endpoint, self.settings)
648
-
649
-
650
- def get_markers(self) -> Dict:
651
- """
652
- Get the markers of the map.
653
-
654
- Returns:
655
- Dict: The markers of the map.
656
-
657
- Example:
658
- >>> from geobox import GeoboxClient
659
- >>> from geobox.map import Map
660
- >>> client = GeoboxClient()
661
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
662
- >>> map.get_markers()
663
- """
664
- endpoint = urljoin(self.endpoint, 'markers/')
665
- return self.api.get(endpoint)
666
-
667
-
668
- def set_markers(self, data: Dict) -> Dict:
669
- """
670
- Set the markers of the map.
671
-
672
- Args:
673
- data (dict): The data of the markers.
674
-
675
- Returns:
676
- Dict: The response of the API.
677
-
678
- Example:
679
- >>> from geobox import GeoboxClient
680
- >>> from geobox.map import Map
681
- >>> client = GeoboxClient()
682
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
683
- >>> data = {
684
- ... 'tags': {
685
- ... '#general': {
686
- ... 'color': '#ff0000',
687
- ... }
688
- ... },
689
- ... 'locations': [
690
- ... {
691
- ... 'id': 1,
692
- ... 'tag': '#general',
693
- ... 'name': 'test',
694
- ... 'geometry': [
695
- ... 51.13162784422988,
696
- ... 35.766603814763045
697
- ... ],
698
- ... 'description': 'string'
699
- ... }
700
- ... ]
701
- ... }
702
- >>> map.set_markers(data)
703
- """
704
- endpoint = urljoin(self.endpoint, 'markers/')
705
- response = self.api.put(endpoint, data)
706
- return response
707
-
708
-
709
- def get_models(self, json=False) -> Union[List['Model'], Dict]:
710
- """
711
- Get the map models.
712
-
713
- Args:
714
- json (bool, optional): If True, return the response as a dictionary.
715
-
716
- Returns:
717
- List[Model] | Dict: map models objects or the response.
718
-
719
- Example:
720
- >>> from geobox import GeoboxClient
721
- >>> from geobox.map import Map
722
- >>> client = GeoboxClient()
723
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
724
- >>> map.get_models(json=True)
725
- """
726
- endpoint = urljoin(self.endpoint, 'models/')
727
- response = self.api.get(endpoint)
728
- if not response or json:
729
- return response
730
- else:
731
- return [Model(self.api, model['obj'], model) for model in response['objects']]
732
-
733
-
734
- def set_models(self, data: Dict) -> List['Model']:
735
- """
736
- Set multiple models on the map.
737
-
738
- Args:
739
- data (Dict): the data of the models and their location on the map. check the example for the data structure.
740
-
741
- Returns:
742
- List[Model]: the map models objects
743
-
744
- Example:
745
- >>> from geobox import GeoboxClient
746
- >>> from geobox.map inport Map
747
- >>> client = GeoboxClient()
748
- >>> map = Map.get_map(uuid="12345678-1234-5678-1234-567812345678")
749
- >>> data = {'objects': [
750
- ... {
751
- ... "name": "transmission_tower",
752
- ... "alias": None,
753
- ... "desc": None,
754
- ... "obj": "12345678-1234-5678-1234-567812345678",
755
- ... "loc": [53.1859045261684, 33.37762747390032, 0.0],
756
- ... "rotation": [0.0, 0.0, 0.0],
757
- ... "scale": 1.0,
758
- ... "min_zoom": 0,
759
- ... "max_zoom": 22
760
- ... }
761
- ... ]}
762
- >>> map.set_models(data)
763
- """
764
- endpoint = urljoin(self.endpoint, 'models/')
765
- response = self.api.put(endpoint, data)
766
- return [Model(self.api, model['obj'], model) for model in response['objects']]
767
-
768
-
769
- def add_model(self,
770
- model: 'Model',
771
- location: List[float],
772
- rotation: List[float] = [0.0, 0.0, 0.0],
773
- scale: float = 1.0,
774
- min_zoom: int = 0,
775
- max_zoom: int = 22,
776
- alias: str = None,
777
- description: str = None) -> List['Model']:
778
- """
779
- Add a model the map.
780
-
781
- Args:
782
- model (Model): The model object.
783
- location (List[float]): location of the model on the map. a list with three float values.
784
- rotation (List[float], optional): rotation of the model on the map. a list with three float vlaues. default is [0.0, 0.0, 0.0].
785
- scale (float, optional): the scale of the model on the map.
786
- min_zoom (int, optional): minimum zoom level.
787
- max_zoom (int, optional): maximum zoom level.
788
- alias (str, optional): alias of the model on the map.
789
- description (str, optional): the description of the model on the map.
790
-
791
- Returns:
792
- List['Model']: The map model objects
793
-
794
- Example:
795
- >>> from geobox import GeoboxClient
796
- >>> from geobox.map import Map
797
- >>> client = GeoboxClient()
798
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
799
- >>> model = client.get_model(uuid="12345678-1234-5678-1234-567812345678")
800
- >>> map.add_model(model=model,
801
- ... location=[53.53, 33.33, 0.0],
802
- ... rotation=[0.0, 0.0, 0.0],
803
- ... scale=1.0,
804
- ... min_zoom=0,
805
- ... max_zoom=22,
806
- ... alias=None,
807
- ... description=None)
808
- """
809
- data = self.get_models(json=True)
810
- if data and data.get('objects') and isinstance(data['objects'], list):
811
- data.get('objects').append({
812
- 'name': model.name,
813
- 'alias': alias,
814
- 'desc': description,
815
- 'obj': model.uuid,
816
- 'loc': location,
817
- 'rotation': rotation,
818
- 'scale': scale,
819
- 'min_zoom': min_zoom,
820
- 'max_zoom': max_zoom
821
- })
822
- else:
823
- data = {'objects':[
824
- {
825
- 'name': model.name,
826
- 'alias': alias,
827
- 'desc': description,
828
- 'obj': model.uuid,
829
- 'loc': location,
830
- 'rotation': rotation,
831
- 'scale': scale,
832
- 'min_zoom': min_zoom,
833
- 'max_zoom': max_zoom
834
- }
835
- ]
836
- }
837
-
838
- endpoint = urljoin(self.endpoint, 'models/')
839
- response = self.api.put(endpoint, data)
840
- return [Model(self.api, model['obj'], model) for model in response['objects']]
841
-
842
-
843
- def image_tile_url(self, x: str = '{x}', y: str = '{y}', z: str = '{z}', format='.png') -> str:
844
- """
845
- Get map image tile url
846
-
847
- Returns:
848
- str: the image tile url
849
-
850
- Example:
851
- >>> from geobox import GeoboxClient
852
- >>> from geobox.map import Map
853
- >>> client = GeoboxClient()
854
- >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
855
- >>> map.image_tile_url()
856
- >>> map.image_tile_url(x=1, y=2, z=3, format='.pbf')
857
- """
858
- return f"{self.BASE_ENDPOINT}{self.endpoint}{z}/{x}/{y}{format}"
1
+ from typing import Dict, List, Optional, Union, TYPE_CHECKING
2
+ from urllib.parse import urljoin, urlencode
3
+
4
+ from .base import Base
5
+ from .utils import clean_data
6
+ from .model3d import Model
7
+
8
+ if TYPE_CHECKING:
9
+ from . import GeoboxClient
10
+ from .user import User
11
+ from .task import Task
12
+
13
+
14
+ class Map(Base):
15
+
16
+ BASE_ENDPOINT = 'maps/'
17
+
18
+ def __init__(self,
19
+ api: 'GeoboxClient',
20
+ uuid: str,
21
+ data: Optional[Dict] = {}):
22
+ """
23
+ Initialize a Map instance.
24
+
25
+ Args:
26
+ api (GeoboxClient): The GeoboxClient instance for making requests.
27
+ name (str): The name of the map.
28
+ uuid (str): The unique identifier for the map.
29
+ data (Dict, optional): The data of the map.
30
+ """
31
+ self.map_layers = {
32
+ 'layers': []
33
+ }
34
+ super().__init__(api, uuid=uuid, data=data)
35
+
36
+
37
+ @classmethod
38
+ def get_maps(cls, api: 'GeoboxClient', **kwargs) -> Union[List['Map'], int]:
39
+ """
40
+ Get list of maps with optional filtering and pagination.
41
+
42
+ Args:
43
+ api (GeoboxClient): The GeoboxClient instance for making requests.
44
+
45
+ Keyword Args:
46
+ q (str): query filter based on OGC CQL standard. e.g. "field1 LIKE '%GIS%' AND created_at > '2021-01-01'"
47
+ search (str): search term for keyword-based searching among search_fields or all textual fields if search_fields does not have value. NOTE: if q param is defined this param will be ignored.
48
+ search_fields (str): comma separated list of fields for searching.
49
+ order_by (str): comma separated list of fields for sorting results [field1 A|D, field2 A|D, …]. e.g. name A, type D. NOTE: "A" denotes ascending order and "D" denotes descending order.
50
+ return_count (bool): Whether to return total count. default is False.
51
+ skip (int): Number of items to skip. default is 0.
52
+ limit (int): Number of items to return. default is 10.
53
+ user_id (int): Specific user. privileges required.
54
+ shared (bool): Whether to return shared maps. default is False.
55
+
56
+ Returns:
57
+ List[Map] | int: A list of Map instances or the total number of maps.
58
+
59
+ Example:
60
+ >>> from geobox import GeoboxClient
61
+ >>> from geobox.map import Map
62
+ >>> client = GeoboxClient()
63
+ >>> maps = Map.get_maps(client, q="name LIKE '%My Map%'")
64
+ or
65
+ >>> maps = client.get_maps(q="name LIKE '%My Map%'")
66
+ """
67
+ params = {
68
+ 'f': 'json',
69
+ 'q': kwargs.get('q'),
70
+ 'search': kwargs.get('search'),
71
+ 'search_fields': kwargs.get('search_fields'),
72
+ 'order_by': kwargs.get('order_by'),
73
+ 'return_count': kwargs.get('return_count', False),
74
+ 'skip': kwargs.get('skip', 0),
75
+ 'limit': kwargs.get('limit', 10),
76
+ 'user_id': kwargs.get('user_id'),
77
+ 'shared': kwargs.get('shared', False)
78
+ }
79
+ return super()._get_list(api, cls.BASE_ENDPOINT, params, factory_func=lambda api, item: Map(api, item['uuid'], item))
80
+
81
+
82
+ @classmethod
83
+ def create_map(cls,
84
+ api: 'GeoboxClient',
85
+ name: str,
86
+ display_name: str = None,
87
+ description: str = None,
88
+ extent: List[float] = None,
89
+ thumbnail: str = None,
90
+ style: Dict = None,
91
+ user_id: int = None) -> 'Map':
92
+ """
93
+ Create a new map.
94
+
95
+ Args:
96
+ api (GeoboxClient): The GeoboxClient instance for making requests.
97
+ name (str): The name of the map.
98
+ display_name (str, optional): The display name of the map.
99
+ description (str, optional): The description of the map.
100
+ extent (List[float], optional): The extent of the map.
101
+ thumbnail (str, optional): The thumbnail of the map.
102
+ style (Dict, optional): The style of the map.
103
+ user_id (int, optional): Specific user. privileges required.
104
+
105
+ Returns:
106
+ Map: The newly created map instance.
107
+
108
+ Raises:
109
+ ValidationError: If the map data is invalid.
110
+
111
+ Example:
112
+ >>> from geobox import GeoboxClient
113
+ >>> from geobox.map import Map
114
+ >>> client = GeoboxClient()
115
+ >>> map = Map.create_map(client, name="my_map", display_name="My Map", description="This is a description of my map", extent=[10, 20, 30, 40], thumbnail="https://example.com/thumbnail.png", style={"type": "style"})
116
+ or
117
+ >>> map = client.create_map(name="my_map", display_name="My Map", description="This is a description of my map", extent=[10, 20, 30, 40], thumbnail="https://example.com/thumbnail.png", style={"type": "style"})
118
+ """
119
+ data = {
120
+ "name": name,
121
+ "display_name": display_name,
122
+ "description": description,
123
+ "extent": extent,
124
+ "thumbnail": thumbnail,
125
+ "style": style,
126
+ "user_id": user_id,
127
+ }
128
+ return super()._create(api, cls.BASE_ENDPOINT, data, factory_func=lambda api, item: Map(api, item['uuid'], item))
129
+
130
+
131
+ @classmethod
132
+ def get_map(cls, api: 'GeoboxClient', uuid: str, user_id: int = None) -> 'Map':
133
+ """
134
+ Get a map by its UUID.
135
+
136
+ Args:
137
+ api (GeoboxClient): The GeoboxClient instance for making requests.
138
+ uuid (str): The UUID of the map to get.
139
+ user_id (int, optional): Specific user. privileges required.
140
+
141
+ Returns:
142
+ Map: The map object.
143
+
144
+ Raises:
145
+ NotFoundError: If the map with the specified UUID is not found.
146
+
147
+ Example:
148
+ >>> from geobox import GeoboxClient
149
+ >>> from geobox.map import Map
150
+ >>> client = GeoboxClient()
151
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
152
+ or
153
+ >>> map = client.get_map(uuid="12345678-1234-5678-1234-567812345678")
154
+ """
155
+ params = {
156
+ 'f': 'json',
157
+ 'user_id': user_id,
158
+ }
159
+ return super()._get_detail(api, cls.BASE_ENDPOINT, uuid, params, factory_func=lambda api, item: Map(api, item['uuid'], item))
160
+
161
+
162
+ @classmethod
163
+ def get_map_by_name(cls, api: 'GeoboxClient', name: str, user_id: int = None) -> Union['Map', None]:
164
+ """
165
+ Get a map by name
166
+
167
+ Args:
168
+ api (GeoboxClient): The GeoboxClient instance for making requests.
169
+ name (str): the name of the map to get
170
+ user_id (int, optional): specific user. privileges required.
171
+
172
+ Returns:
173
+ Map | None: returns the map if a map matches the given name, else None
174
+
175
+ Example:
176
+ >>> from geobox import GeoboxClient
177
+ >>> from geobox.map import Map
178
+ >>> client = GeoboxClient()
179
+ >>> map = Map.get_map_by_name(client, name='test')
180
+ or
181
+ >>> map = client.get_map_by_name(name='test')
182
+ """
183
+ maps = cls.get_maps(api, q=f"name = '{name}'", user_id=user_id)
184
+ if maps and maps[0].name == name:
185
+ return maps[0]
186
+ else:
187
+ return None
188
+
189
+
190
+ def update(self, **kwargs) -> Dict:
191
+ """
192
+ Update the map.
193
+
194
+ Keyword Args:
195
+ name (str): The name of the map.
196
+ display_name (str): The display name of the map.
197
+ description (str): The description of the map.
198
+ extent (List[float]): The extent of the map.
199
+ thumbnail (str): The thumbnail of the map.
200
+ style (Dict): The style of the map.
201
+
202
+ Returns:
203
+ Dict: The updated map data.
204
+
205
+ Raises:
206
+ ValidationError: If the map data is invalid.
207
+
208
+ Example:
209
+ >>> from geobox import GeoboxClient
210
+ >>> from geobox.map import Map
211
+ >>> client = GeoboxClient()
212
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
213
+ >>> map.update(display_name="New Display Name")
214
+ """
215
+ data = {
216
+ "name": kwargs.get('name'),
217
+ "display_name": kwargs.get('display_name'),
218
+ "description": kwargs.get('description'),
219
+ "extent": kwargs.get('extent'),
220
+ "thumbnail": kwargs.get('thumbnail'),
221
+ "style": kwargs.get('style'),
222
+ }
223
+ return super()._update(self.endpoint, data)
224
+
225
+
226
+ def delete(self) -> None:
227
+ """
228
+ Delete the map.
229
+
230
+ Returns:
231
+ None
232
+
233
+ Example:
234
+ >>> from geobox import GeoboxClient
235
+ >>> from geobox.map import Map
236
+ >>> client = GeoboxClient()
237
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
238
+ >>> map.delete()
239
+ """
240
+ super().delete(self.endpoint)
241
+
242
+
243
+ @property
244
+ def style(self) -> Dict:
245
+ """
246
+ Get the style of the map.
247
+
248
+ Returns:
249
+ Dict: The style of the map.
250
+
251
+ Example:
252
+ >>> from geobox import GeoboxClient
253
+ >>> from geobox.map import Map
254
+ >>> client = GeoboxClient()
255
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
256
+ >>> map.style
257
+ """
258
+ endpoint = urljoin(self.endpoint, 'style/')
259
+ response = self.api.get(endpoint)
260
+ return response
261
+
262
+
263
+ @property
264
+ def thumbnail(self) -> str:
265
+ """
266
+ Get the thumbnail URL of the map.
267
+
268
+ Returns:
269
+ str: The thumbnail of the map.
270
+
271
+ Example:
272
+ >>> from geobox import GeoboxClient
273
+ >>> from geobox.map import Map
274
+ >>> client = GeoboxClient()
275
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
276
+ >>> map.thumbnail
277
+ 'https://example.com/thumbnail.png'
278
+ """
279
+ endpoint = f"{self.api.base_url}{self.endpoint}thumbnail.png"
280
+ return endpoint
281
+
282
+
283
+ def set_readonly(self, readonly: bool) -> None:
284
+ """
285
+ Set the readonly status of the map.
286
+
287
+ Args:
288
+ readonly (bool): The readonly status of the map.
289
+
290
+ Returns:
291
+ None
292
+
293
+ Example:
294
+ >>> from geobox import GeoboxClient
295
+ >>> from geobox.map import Map
296
+ >>> client = GeoboxClient()
297
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
298
+ >>> map.set_readonly(True)
299
+ """
300
+ data = clean_data({
301
+ 'readonly': readonly
302
+ })
303
+ endpoint = urljoin(self.endpoint, 'setReadonly/')
304
+ response = self.api.post(endpoint, data, is_json=False)
305
+ self._update_properties(response)
306
+
307
+
308
+ def set_multiuser(self, multiuser: bool) -> None:
309
+ """
310
+ Set the multiuser status of the map.
311
+
312
+ Args:
313
+ multiuser (bool): The multiuser status of the map.
314
+
315
+ Returns:
316
+ None
317
+
318
+ Example:
319
+ >>> from geobox import GeoboxClient
320
+ >>> from geobox.map import Map
321
+ >>> client = GeoboxClient()
322
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
323
+ >>> map.set_multiuser(True)
324
+ """
325
+ data = clean_data({
326
+ 'multiuser': multiuser
327
+ })
328
+ endpoint = urljoin(self.endpoint, 'setMultiuser/')
329
+ response = self.api.post(endpoint, data, is_json=False)
330
+ self._update_properties(response)
331
+
332
+
333
+
334
+ def wmts(self, scale: int = None) -> str:
335
+ """
336
+ Get the WMTS URL of the map.
337
+
338
+ Args:
339
+ scale (int): The scale of the map. value are: 1, 2
340
+
341
+ Returns:
342
+ str: The WMTS URL of the map.
343
+
344
+ Example:
345
+ >>> from geobox import GeoboxClient
346
+ >>> from geobox.map import Map
347
+ >>> client = GeoboxClient()
348
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
349
+ >>> map.wmts(scale=1)
350
+ """
351
+ endpoint = urljoin(self.api.base_url, f'{self.endpoint}wmts/')
352
+ if scale:
353
+ endpoint = f"{endpoint}?scale={scale}"
354
+ return endpoint
355
+
356
+
357
+ def share(self, users: List['User']) -> None:
358
+ """
359
+ Shares the map with specified users.
360
+
361
+ Args:
362
+ users (List[User]): The list of user objects to share the map with.
363
+
364
+ Returns:
365
+ None
366
+
367
+ Example:
368
+ >>> from geobox import GeoboxClient
369
+ >>> from geobox.map import Map
370
+ >>> client = GeoboxClient()
371
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
372
+ >>> users = client.search_users(search='John')
373
+ >>> map.share(users=users)
374
+ """
375
+ super()._share(self.endpoint, users)
376
+
377
+
378
+ def unshare(self, users: List['User']) -> None:
379
+ """
380
+ Unshares the map with specified users.
381
+
382
+ Args:
383
+ users (List[User]): The list of user objects to unshare the map with.
384
+
385
+ Returns:
386
+ None
387
+
388
+ Example:
389
+ >>> from geobox import GeoboxClient
390
+ >>> from geobox.map import Map
391
+ >>> client = GeoboxClient()
392
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
393
+ >>> users = client.search_users(search='John')
394
+ >>> map.unshare(users=users)
395
+ """
396
+ super()._unshare(self.endpoint, users)
397
+
398
+
399
+ def get_shared_users(self, search: str = None, skip: int = 0, limit: int = 10) -> List['User']:
400
+ """
401
+ Retrieves the list of users the map is shared with.
402
+
403
+ Args:
404
+ search (str, optional): The search query.
405
+ skip (int, optional): The number of users to skip.
406
+ limit (int, optional): The maximum number of users to retrieve.
407
+
408
+ Returns:
409
+ List[User]: The list of shared users.
410
+
411
+ Example:
412
+ >>> from geobox import GeoboxClient
413
+ >>> from geobox.map import Map
414
+ >>> client = GeoboxClient()
415
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
416
+ >>> map.get_shared_users(search='John', skip=0, limit=10)
417
+ """
418
+ params = {
419
+ 'search': search,
420
+ 'skip': skip,
421
+ 'limit': limit
422
+ }
423
+ return super()._get_shared_users(self.endpoint, params)
424
+
425
+
426
+ def seed_cache(self,
427
+ from_zoom: int = None,
428
+ to_zoom: int = None,
429
+ extent: List[float] = None,
430
+ workers: int = 1,
431
+ user_id: int = None,
432
+ scale: int = None) -> List['Task']:
433
+ """
434
+ Seed the cache of the map.
435
+
436
+ Args:
437
+ from_zoom (int, optional): The zoom level to start caching from.
438
+ to_zoom (int, optional): The zoom level to stop caching at.
439
+ extent (List[float], optional): The extent of the map.
440
+ workers (int, optional): The number of workers to use. default is 1.
441
+ user_id (int, optional): Specific user. privileges required.
442
+ scale (int, optional): The scale of the map.
443
+
444
+ Returns:
445
+ List[Task]: The task instance of the cache seeding operation.
446
+
447
+ Raises:
448
+ ValueError: If the workers is not in [1, 2, 4, 8, 12, 16, 20, 24].
449
+ ValueError: If the cache seeding fails.
450
+
451
+ Example:
452
+ >>> from geobox import GeoboxClient
453
+ >>> from geobox.map import Map
454
+ >>> client = GeoboxClient()
455
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
456
+ >>> task = map.seed_cache(from_zoom=0, to_zoom=10, extent=[10, 20, 30, 40], workers=1, scale=1)
457
+ """
458
+ data = {
459
+ 'from_zoom': from_zoom,
460
+ 'to_zoom': to_zoom,
461
+ 'extent': extent,
462
+ 'workers': workers,
463
+ 'user_id': user_id,
464
+ 'scale': scale
465
+ }
466
+ return super()._seed_cache(self.endpoint, data)
467
+
468
+
469
+ def update_cache(self,
470
+ from_zoom: int = None,
471
+ to_zoom: int = None,
472
+ extent: List[float] = None,
473
+ user_id: int = None,
474
+ scale: int = None) -> List['Task']:
475
+ """
476
+ Update the cache of the map.
477
+
478
+ Args:
479
+ from_zoom (int, optional): The zoom level to start caching from.
480
+ to_zoom (int, optional): The zoom level to stop caching at.
481
+ extent (List[float], optional): The extent of the map.
482
+ user_id (int, optional): Specific user. privileges required.
483
+ scale (int, optional): The scale of the map.
484
+
485
+ Returns:
486
+ List[Task]: The task instance of the cache updating operation.
487
+
488
+ Raises:
489
+ ValueError: If the cache updating fails.
490
+
491
+ Example:
492
+ >>> from geobox import GeoboxClient
493
+ >>> from geobox.map import Map
494
+ >>> client = GeoboxClient()
495
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
496
+ >>> map.update_cache(from_zoom=0, to_zoom=10, extent=[10, 20, 30, 40], scale=1)
497
+ """
498
+ data = {
499
+ 'from_zoom': from_zoom,
500
+ 'to_zoom': to_zoom,
501
+ 'extent': extent,
502
+ 'user_id': user_id,
503
+ 'scale': scale
504
+ }
505
+ return super()._update_cache(self.endpoint, data)
506
+
507
+
508
+ def clear_cache(self) -> None:
509
+ """
510
+ Clear the cache of the map.
511
+
512
+ Returns:
513
+ None
514
+
515
+ Example:
516
+ >>> from geobox import GeoboxClient
517
+ >>> from geobox.map import Map
518
+ >>> client = GeoboxClient()
519
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
520
+ >>> map.clear_cache()
521
+ """
522
+ return super()._clear_cache(self.endpoint)
523
+
524
+
525
+ @property
526
+ def cache_size(self) -> int:
527
+ """
528
+ Get the size of the cache of the map.
529
+
530
+ Returns:
531
+ int: The size of the cache of the map.
532
+
533
+ Example:
534
+ >>> from geobox import GeoboxClient
535
+ >>> from geobox.map import Map
536
+ >>> client = GeoboxClient()
537
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
538
+ >>> map.cache_size
539
+ """
540
+ return super()._cache_size(self.endpoint)
541
+
542
+
543
+ @property
544
+ def settings(self) -> Dict:
545
+ """
546
+ Get the settings of the map
547
+
548
+ Returns:
549
+ Dict: the settings of the map.
550
+
551
+ Example:
552
+ >>> from geobox import GeoboxClient
553
+ >>> from geobox.map import Map
554
+ >>> client = GeoboxClient()
555
+ >>> map = Map.get_map(uuid="12345678-1234-5678-1234-567812345678")
556
+ >>> map.settings
557
+ """
558
+ return self.json.get('settings', {
559
+ 'general_settings': {},
560
+ 'edit_settings': {},
561
+ 'snap_settings': {},
562
+ 'controls': [],
563
+ 'search_settings': {},
564
+ 'marker_settings': {},
565
+ 'terrain_settings': {},
566
+ 'grid_settings': {},
567
+ 'view_settings': {},
568
+ 'toc_settings': []
569
+ })
570
+
571
+
572
+ def set_settings(self, **kwargs) -> Dict:
573
+ """
574
+ Set the settings of the map.
575
+
576
+ Keyword Args:
577
+ map_unit (str): 'latlng' | 'utm'.
578
+ base_map (str): 'OSM' | 'google' | 'blank'.
579
+ flash_color (str): 'rgb(255,0,0)' (rgb color or rgba color or hex color ).
580
+ highlight_color (str): 'rgb(255,0,0)' (rgb color or rgba color or hex color ).
581
+ selection_color (str): 'rgb(255,0,0)' (rgb color or rgba color or hex color ).
582
+ selectable_layers (str): 'ALL' | null | Comma separated list of layers.
583
+ calendar_type (str): The type of the calendar.
584
+ edit_settings (dict): The settings of the edit.
585
+ snap_tolerance (int): number of pixels for snap tolerance.
586
+ snap_unit (str): pixels.
587
+ snap_mode (str): 'both' | 'edge' | 'vertex'.
588
+ snap_cache (int): number of total features for snap cache.
589
+ controls (List[str]): The controls of the map.
590
+ search_mode (str): 'both' | 'markers' | 'layers'.
591
+ search_layers (str): 'ALL' | null | Comma separated list of layers.
592
+ geosearch (bool): The geosearch of the map.
593
+ remove_unused_tags (bool): The remove unused tags of the map.
594
+ terrain_layer (str): The terrain layer of the map.
595
+ exaggeration (int): The exaggeration of the terrain.
596
+ enable_grid (bool): The enable grid of the map.
597
+ grid_unit (str): The unit of the grid.
598
+ grid_width (int): The width of the grid.
599
+ grid_height (int): The height of the grid.
600
+ grid_minzoom (int): The minzoom of the grid.
601
+ grid_maxzoom (int): The maxzoom of the grid.
602
+ bearing (int): The bearing of the map.
603
+ pitch (int): The pitch of the map.
604
+ center (List[float]): The center of the map.
605
+ zoom (int): The zoom of the map.
606
+ toc_settings (List): The settings of the toc.
607
+ custom_basemaps (List[str]): The custom basemaps of the map.
608
+ show_maptip_on (str): 'ALL' | null | Comma separated list of layers.
609
+ snappable_layers (str): 'ALL' | null | Comma separated list of layers.
610
+
611
+ Returns:
612
+ Dict: The response of the API.
613
+ """
614
+ general_settings = {'map_unit', 'base_map', 'flash_color', 'highlight_color',
615
+ 'selection_color', 'selectable_layers', 'calendar_type', 'custom_basemaps', 'show_maptip_on'}
616
+ edit_settings = {'editable_layers', 'target_layer'}
617
+ snap_settings = {'snap_tolerance', 'snap_unit', 'snap_mode', 'snap_cache', 'snappable_layers'}
618
+ search_settings = {'search_mode', 'search_layers', 'geosearch'}
619
+ marker_settings = {'remove_unused_tags'}
620
+ terrain_settings = {'terrain_layer', 'exaggeration'}
621
+ grid_settings = {'enable_grid', 'grid_unit', 'grid_width', 'grid_height', 'grid_minzoom', 'grid_maxzoom'}
622
+ view_settings = {'bearing', 'pitch', 'center', 'zoom'}
623
+
624
+ for key, value in kwargs.items():
625
+ if key in general_settings:
626
+ self.settings['general_settings'][key] = value
627
+ elif key in edit_settings:
628
+ self.settings['edit_settings'][key] = value
629
+ elif key in snap_settings:
630
+ self.settings['snap_settings'][key] = value
631
+ elif key == 'controls':
632
+ self.settings['controls'] = value
633
+ elif key in search_settings:
634
+ self.settings['search_settings'][key] = value
635
+ elif key in marker_settings:
636
+ self.settings['marker_settings'][key] = value
637
+ elif key in terrain_settings:
638
+ self.settings['terrain_settings'][key] = value
639
+ elif key in grid_settings:
640
+ self.settings['grid_settings'][key] = value
641
+ elif key in view_settings:
642
+ self.settings['view_settings'][key] = value
643
+ elif key == 'toc_settings':
644
+ self.settings['toc_settings'] = value
645
+
646
+ endpoint = urljoin(self.endpoint, 'settings/')
647
+ self.api.put(endpoint, self.settings)
648
+
649
+
650
+ def get_markers(self) -> Dict:
651
+ """
652
+ Get the markers of the map.
653
+
654
+ Returns:
655
+ Dict: The markers of the map.
656
+
657
+ Example:
658
+ >>> from geobox import GeoboxClient
659
+ >>> from geobox.map import Map
660
+ >>> client = GeoboxClient()
661
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
662
+ >>> map.get_markers()
663
+ """
664
+ endpoint = urljoin(self.endpoint, 'markers/')
665
+ return self.api.get(endpoint)
666
+
667
+
668
+ def set_markers(self, data: Dict) -> Dict:
669
+ """
670
+ Set the markers of the map.
671
+
672
+ Args:
673
+ data (dict): The data of the markers.
674
+
675
+ Returns:
676
+ Dict: The response of the API.
677
+
678
+ Example:
679
+ >>> from geobox import GeoboxClient
680
+ >>> from geobox.map import Map
681
+ >>> client = GeoboxClient()
682
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
683
+ >>> data = {
684
+ ... 'tags': {
685
+ ... '#general': {
686
+ ... 'color': '#ff0000',
687
+ ... }
688
+ ... },
689
+ ... 'locations': [
690
+ ... {
691
+ ... 'id': 1,
692
+ ... 'tag': '#general',
693
+ ... 'name': 'test',
694
+ ... 'geometry': [
695
+ ... 51.13162784422988,
696
+ ... 35.766603814763045
697
+ ... ],
698
+ ... 'description': 'string'
699
+ ... }
700
+ ... ]
701
+ ... }
702
+ >>> map.set_markers(data)
703
+ """
704
+ endpoint = urljoin(self.endpoint, 'markers/')
705
+ response = self.api.put(endpoint, data)
706
+ return response
707
+
708
+
709
+ def get_models(self, json=False) -> Union[List['Model'], Dict]:
710
+ """
711
+ Get the map models.
712
+
713
+ Args:
714
+ json (bool, optional): If True, return the response as a dictionary.
715
+
716
+ Returns:
717
+ List[Model] | Dict: map models objects or the response.
718
+
719
+ Example:
720
+ >>> from geobox import GeoboxClient
721
+ >>> from geobox.map import Map
722
+ >>> client = GeoboxClient()
723
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
724
+ >>> map.get_models(json=True)
725
+ """
726
+ endpoint = urljoin(self.endpoint, 'models/')
727
+ response = self.api.get(endpoint)
728
+ if not response or json:
729
+ return response
730
+ else:
731
+ return [Model(self.api, model['obj'], model) for model in response['objects']]
732
+
733
+
734
+ def set_models(self, data: Dict) -> List['Model']:
735
+ """
736
+ Set multiple models on the map.
737
+
738
+ Args:
739
+ data (Dict): the data of the models and their location on the map. check the example for the data structure.
740
+
741
+ Returns:
742
+ List[Model]: the map models objects
743
+
744
+ Example:
745
+ >>> from geobox import GeoboxClient
746
+ >>> from geobox.map inport Map
747
+ >>> client = GeoboxClient()
748
+ >>> map = Map.get_map(uuid="12345678-1234-5678-1234-567812345678")
749
+ >>> data = {'objects': [
750
+ ... {
751
+ ... "name": "transmission_tower",
752
+ ... "alias": None,
753
+ ... "desc": None,
754
+ ... "obj": "12345678-1234-5678-1234-567812345678",
755
+ ... "loc": [53.1859045261684, 33.37762747390032, 0.0],
756
+ ... "rotation": [0.0, 0.0, 0.0],
757
+ ... "scale": 1.0,
758
+ ... "min_zoom": 0,
759
+ ... "max_zoom": 22
760
+ ... }
761
+ ... ]}
762
+ >>> map.set_models(data)
763
+ """
764
+ endpoint = urljoin(self.endpoint, 'models/')
765
+ response = self.api.put(endpoint, data)
766
+ return [Model(self.api, model['obj'], model) for model in response['objects']]
767
+
768
+
769
+ def add_model(self,
770
+ model: 'Model',
771
+ location: List[float],
772
+ rotation: List[float] = [0.0, 0.0, 0.0],
773
+ scale: float = 1.0,
774
+ min_zoom: int = 0,
775
+ max_zoom: int = 22,
776
+ alias: str = None,
777
+ description: str = None) -> List['Model']:
778
+ """
779
+ Add a model the map.
780
+
781
+ Args:
782
+ model (Model): The model object.
783
+ location (List[float]): location of the model on the map. a list with three float values.
784
+ rotation (List[float], optional): rotation of the model on the map. a list with three float vlaues. default is [0.0, 0.0, 0.0].
785
+ scale (float, optional): the scale of the model on the map.
786
+ min_zoom (int, optional): minimum zoom level.
787
+ max_zoom (int, optional): maximum zoom level.
788
+ alias (str, optional): alias of the model on the map.
789
+ description (str, optional): the description of the model on the map.
790
+
791
+ Returns:
792
+ List['Model']: The map model objects
793
+
794
+ Example:
795
+ >>> from geobox import GeoboxClient
796
+ >>> from geobox.map import Map
797
+ >>> client = GeoboxClient()
798
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
799
+ >>> model = client.get_model(uuid="12345678-1234-5678-1234-567812345678")
800
+ >>> map.add_model(model=model,
801
+ ... location=[53.53, 33.33, 0.0],
802
+ ... rotation=[0.0, 0.0, 0.0],
803
+ ... scale=1.0,
804
+ ... min_zoom=0,
805
+ ... max_zoom=22,
806
+ ... alias=None,
807
+ ... description=None)
808
+ """
809
+ data = self.get_models(json=True)
810
+ if data and data.get('objects') and isinstance(data['objects'], list):
811
+ data.get('objects').append({
812
+ 'name': model.name,
813
+ 'alias': alias,
814
+ 'desc': description,
815
+ 'obj': model.uuid,
816
+ 'loc': location,
817
+ 'rotation': rotation,
818
+ 'scale': scale,
819
+ 'min_zoom': min_zoom,
820
+ 'max_zoom': max_zoom
821
+ })
822
+ else:
823
+ data = {'objects':[
824
+ {
825
+ 'name': model.name,
826
+ 'alias': alias,
827
+ 'desc': description,
828
+ 'obj': model.uuid,
829
+ 'loc': location,
830
+ 'rotation': rotation,
831
+ 'scale': scale,
832
+ 'min_zoom': min_zoom,
833
+ 'max_zoom': max_zoom
834
+ }
835
+ ]
836
+ }
837
+
838
+ endpoint = urljoin(self.endpoint, 'models/')
839
+ response = self.api.put(endpoint, data)
840
+ return [Model(self.api, model['obj'], model) for model in response['objects']]
841
+
842
+
843
+ def image_tile_url(self, x: str = '{x}', y: str = '{y}', z: str = '{z}', format='.png') -> str:
844
+ """
845
+ Get map image tile url
846
+
847
+ Returns:
848
+ str: the image tile url
849
+
850
+ Example:
851
+ >>> from geobox import GeoboxClient
852
+ >>> from geobox.map import Map
853
+ >>> client = GeoboxClient()
854
+ >>> map = Map.get_map(client, uuid="12345678-1234-5678-1234-567812345678")
855
+ >>> map.image_tile_url()
856
+ >>> map.image_tile_url(x=1, y=2, z=3, format='.pbf')
857
+ """
858
+ return f"{self.BASE_ENDPOINT}{self.endpoint}{z}/{x}/{y}{format}"