aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kvision-modules/kvision-maps/src/main/kotlin/pl/treksoft/kvision/KVManagerMaps.kt11
-rw-r--r--kvision-modules/kvision-maps/src/main/kotlin/pl/treksoft/kvision/maps/Maps.kt6
2 files changed, 16 insertions, 1 deletions
diff --git a/kvision-modules/kvision-maps/src/main/kotlin/pl/treksoft/kvision/KVManagerMaps.kt b/kvision-modules/kvision-maps/src/main/kotlin/pl/treksoft/kvision/KVManagerMaps.kt
index 5fb39d42..b5925901 100644
--- a/kvision-modules/kvision-maps/src/main/kotlin/pl/treksoft/kvision/KVManagerMaps.kt
+++ b/kvision-modules/kvision-maps/src/main/kotlin/pl/treksoft/kvision/KVManagerMaps.kt
@@ -21,6 +21,8 @@
*/
package pl.treksoft.kvision
+import pl.treksoft.kvision.utils.obj
+
internal val kVManagerMapsInit = KVManagerMaps.init()
/**
@@ -34,5 +36,14 @@ internal object KVManagerMaps {
internal val leaflet = require("leaflet/dist/leaflet.js")
+ init {
+ leaflet.Icon.Default.imagePath = "./"
+ leaflet.Icon.Default.mergeOptions(obj {
+ iconRetinaUrl = require("leaflet/dist/images/marker-icon-2x.png")
+ iconUrl = require("leaflet/dist/images/marker-icon.png")
+ shadowUrl = require("leaflet/dist/images/marker-shadow.png")
+ })
+ }
+
internal fun init() {}
}
diff --git a/kvision-modules/kvision-maps/src/main/kotlin/pl/treksoft/kvision/maps/Maps.kt b/kvision-modules/kvision-maps/src/main/kotlin/pl/treksoft/kvision/maps/Maps.kt
index cf68fd2e..cb98fb8a 100644
--- a/kvision-modules/kvision-maps/src/main/kotlin/pl/treksoft/kvision/maps/Maps.kt
+++ b/kvision-modules/kvision-maps/src/main/kotlin/pl/treksoft/kvision/maps/Maps.kt
@@ -35,12 +35,14 @@ import pl.treksoft.kvision.utils.obj
* @param lat initial latitude value
* @param lng initial longitude value
* @param zoom initial zoom
+ * @param showMarker show marker in the initial position
* @param classes a set of CSS class names
*/
open class Maps(
val lat: Number,
val lng: Number,
val zoom: Number,
+ val showMarker: Boolean = false,
classes: Set<String> = setOf(),
init: (Maps.() -> Unit)? = null
) : Widget(classes) {
@@ -63,6 +65,7 @@ open class Maps(
this.center = arrayOf(lat, lng)
this.zoom = zoom
})
+ KVManagerMaps.leaflet.marker(arrayOf(lat, lng)).addTo(jsMaps)
KVManagerMaps.leaflet.tileLayer(
"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
obj {
@@ -86,10 +89,11 @@ fun Container.maps(
lat: Number,
lng: Number,
zoom: Number,
+ showMarker: Boolean = false,
classes: Set<String> = setOf(),
init: (Maps.() -> Unit)? = null
): Maps {
- val maps = Maps(lat, lng, zoom, classes, init)
+ val maps = Maps(lat, lng, zoom, showMarker, classes, init)
this.add(maps)
return maps
}