forked from hyoo-ru/mam_mol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yandex.view.ts
82 lines (58 loc) · 1.63 KB
/
yandex.view.ts
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
namespace $.$$ {
export class $mol_map_yandex extends $.$mol_map_yandex {
static api() {
return $mol_import.script( `https://api-maps.yandex.ru/2.1/?lang=${ $mol_locale.lang() }` ).ymaps
}
@ $mol_mem
api( next? : any , force? : $mol_mem_force ) : any {
const ymaps = $mol_map_yandex.api()
const load_map = $mol_fiber_sync( ()=> new Promise( done => ymaps.ready( done ) ) )
load_map()
const api = new ymaps.Map( this.dom_node() , {
center : [ 0 , 0 ] ,
zoom : 0 ,
} )
api.copyrights.add( $mol_geo_search_attribution );
api.controls.remove( 'fullscreenControl' )
api.controls.remove( 'typeSelector' )
api.events.add( [ 'actionend' ] , ( event : any )=> {
new $mol_after_frame( $mol_fiber_root( ()=> {
this.update( event )
} ) )
} )
return api
}
update( event? : any ) {
this.zoom( this.api().getZoom() )
this.center( this.api().getCenter() )
}
@ $mol_mem
bounds_updated() {
const box = this.objects()[0]?.box()
if( box ) {
this.api().setBounds([
[box.x.min,box.y.min],
[box.x.max,box.y.max],
])
}
return true
}
@ $mol_mem
center( next? : readonly[number,number] , force? : $mol_mem_force ) {
if ( next !== undefined ) return next
const pos = this.objects()[0]?.pos()
if( pos ) return pos
return [0,0] as readonly[number,number]
}
render() {
const api = this.api()
api.setCenter( this.center() , this.zoom() )
// this.bounds_updated()
api.geoObjects.removeAll()
for( let obj of this.objects() ) {
api.geoObjects.add( obj.object() )
}
this.dom_node_actual()
}
}
}