From 4f111976f842b9a63363181ad2182091bb810c46 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Fri, 27 Mar 2020 18:53:47 +0100 Subject: Fix support for default images (markers) in the maps module. --- .../src/main/kotlin/pl/treksoft/kvision/KVManagerMaps.kt | 11 +++++++++++ .../src/main/kotlin/pl/treksoft/kvision/maps/Maps.kt | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'kvision-modules/kvision-maps/src/main/kotlin/pl') 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 = 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 = 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 } -- cgit