-
Notifications
You must be signed in to change notification settings - Fork 47
/
DemoModelBase.kt
63 lines (51 loc) · 1.96 KB
/
DemoModelBase.kt
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
/*
* Copyright (c) 2019. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package jetbrains.livemap.demo
import jetbrains.datalore.base.geometry.DoubleVector
import jetbrains.datalore.base.registration.Registration
import jetbrains.datalore.vis.canvas.CanvasControl
import jetbrains.livemap.DevParams
import jetbrains.livemap.LiveMapFactory
import jetbrains.livemap.LiveMapLocation
import jetbrains.livemap.api.*
import jetbrains.livemap.canvascontrols.LiveMapPresenter
import jetbrains.livemap.projections.ProjectionType
import jetbrains.livemap.ui.Clipboard
abstract class DemoModelBase(private val dimension: DoubleVector) {
fun show(canvasControl: CanvasControl, block: LiveMapBuilder.() -> Unit = {}): Registration {
val liveMap = createLiveMapSpec()
.apply(block)
.run(LiveMapBuilder::build)
.run(::LiveMapFactory)
.run(LiveMapFactory::createLiveMap)
return Registration.from(
LiveMapPresenter().apply { render(canvasControl, liveMap) }
)
}
internal fun basicLiveMap(block: LiveMapBuilder.() -> Unit): LiveMapBuilder {
return liveMapConfig {
size = dimension
tileService = internalTiles()
geocodingService = liveMapGeocoding {
host = "geo.datalore.io"
port = null
}
interactive = true
projection {
kind = ProjectionType.MERCATOR
loopX = true
loopY = false
}
// params(
// DevParams.DEBUG_GRID.key to true,
// DevParams.MICRO_TASK_EXECUTOR.key to "ui_thread",
// DevParams.PERF_STATS.key to true
// )
mapLocationConsumer = { Clipboard.copy(LiveMapLocation.getLocationString(it)) }
}
.apply(block)
}
abstract fun createLiveMapSpec(): LiveMapBuilder
}