-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
yandex.view.ts
90 lines (65 loc) · 1.79 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
83
84
85
86
87
88
89
90
namespace $.$$ {
/**
* Simple [Yandex Maps](https://tech.yandex.ru/maps/doc/jsapi/2.1/) wrapper.
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_map_yandex_demo
*/
export class $mol_map_yandex extends $.$mol_map_yandex {
static api_key() {
return ""
}
static api() {
return $mol_import.script( `https://api-maps.yandex.ru/2.1/?apikey=${this.api_key()}&lang=${ $mol_locale.lang() }` ).ymaps
}
wait_ready( ymaps: any ) {
return new Promise( done => ymaps.ready( done ) )
}
@ $mol_mem
api( next? : any ) : any {
const ymaps = $mol_map_yandex.api()
$mol_wire_sync( this ).wait_ready( ymaps )
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' ] , $mol_wire_async( ( event : any )=> {
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] ) {
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()
}
}
}