-
I'm hoping I could get some guidance on accomplishing something like this:
What I expect to happen is for maplibre to place a map within the div associated with the Maplibre component. How can I create an empty div and then build some Javascript code that modifies the div? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
@kerrycobb since latest commit use it please: import happyx
import jsffi
type
Map* = ref object of JsObject
MapOptions* = ref object of JsObject
proc newMapOptions*(): MapOptions {.importcpp: "Object.create(null)".}
proc `container=`*(opts: MapOptions, container: cstring) {.importcpp: "#.container = #".}
proc `style=`*(opts: MapOptions, style: cstring) {.importcpp: "#.style = #".}
proc newMap*(options: MapOptions): Map {.importcpp: "new maplibregl.Map(@)".}
component Maplibre:
html:
tDiv(class = "w-full", id="map")
@created:
buildJs:
let opts = newMapOptions()
opts.container = "map"
opts.style = "https://demotiles.maplibre.org/style.json"
var map = newMap(opts)
var mapElement = document.querySelector("#map") or this: import happyx
import jsffi
type
Map* = ref object of JsObject
MapOptions* = ref object of JsObject
proc newMapOptions*(): MapOptions {.importcpp: "Object.create(null)".}
proc `container=`*(opts: MapOptions, container: cstring) {.importcpp: "#.container = #".}
proc `style=`*(opts: MapOptions, style: cstring) {.importcpp: "#.style = #".}
proc newMap*(options: MapOptions): Map {.importcpp: "new maplibregl.Map(@)".}
component Maplibre:
html:
tDiv(class = "w-full", id="map")
@created:
{.emit: """//js
let opts = newMapOptions()
opts.container = "map"
opts.style = "https://demotiles.maplibre.org/style.json"
var map = newMap(opts)
""".}
let mapElement = document.querySelector("#map")
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the help! Unfortunately I was not able to make it work using commit 8d583fd. I started with a fresh project using the create command and changed only
That doesn't produce the map. But if I compile that code with |
Beta Was this translation helpful? Give feedback.
-
Thanks! I also needed to remove the Working example for anyone finding this: import jsffi
import happyx
proc newMapOptions*(): JsObject {.importcpp: "Object.create(null)".}
proc `container=`*(opts: JsObject, container: cstring) {.importcpp: "#.container = #".}
proc `style=`*(opts: JsObject, style: cstring) {.importcpp: "#.style = #".}
proc newMap*(options: JsObject): JsObject {.importcpp: "new maplibregl.Map(@)".}
component HelloWorld:
html:
tDiv(id=nu"map")
@created:
let opts = newMapOptions()
opts.container = "map"
opts.style = "https://demotiles.maplibre.org/style.json"
var map = newMap(opts) |
Beta Was this translation helpful? Give feedback.
yea ... please, try