How do I add a Polyline to the Map object? The lib...
# kvision
j
How do I add a Polyline to the Map object? The library supports the
PolylineOptions
class, but there is no apparent method to create a polyline object. Do I need to extend the existing code?
r
I don't think its supported now so yes, you need to implement the code.
j
How do you suggest I go about that? I thought about duplicating the code into my own project, implement the changes, and later submit a pull request. I’m considering this approach because
io.kvision.MapsModule.leaflet
is internal, so not visible to other modules. What do you think / suggest?
r
You should be building and using your own snapshot, so you can temporarily make it public. Or you can just create your own variable in your app
val leaflet = require("leaflet")
and it should be exactly the same object.
And yes, sometimes I just work with the code inside my test application to explore and test things instantly, and then copy the code into kvision module when I know it works.
j
Great. I did just that and works. To use my own snapshot, I can checkout a local copy and make my changes there. But then how do I share my changes back? Are you accepting pull requests?
r
Oh LOL! Sorry I've been busy today and only watched the slack for a moment and I've connected your question with an earlier thread about extending maps module by @Adam S 🙂
So answering your questions once again: maps module is just a skeleton and a lot of functionality is missing, including polylines support. The only way to make it work is to extend the module. You don't have to build KVision snapshots - you can just make it for your own application (just like you are doing this now). But of course contributions to KVision are welcomed. If you would like to contribute I am accepting PRs.
j
Great! Let me explore how I would extend it and then I will share my code with you. You can then decide what is worth putting into a PR. I worked extensively with maps in the past, in Javascript, Silverlight and WPF, and I have some ideas on what to add…
BTW, I’m loving the experience with your code!
🙏 1
a
thanks for the ping Robert! hey @João Paulo Figueira, I'm working on making the maps API as functional as possible right now, please check out the PR https://github.com/rjaros/kvision/pull/327 I've covered a lot of the ground work, now I'm trying to make a nice DSL and fixing any bugs
I just pushed a new commit with a test for adding Polyline :) https://github.com/rjaros/kvision/pull/327/commits/a4fe1454ed9ea0afc44e97d68726f5ff4390eb12#diff-05d4abada913d4617c08374d8c526120e0a0475717ae233f20a1755e9e033e32R219-R237 (I don't think it works correctly, the line doesn't have any points, but I think it's an easy fix)
j
Hi @Adam S! Thanks for the heads up. I looked at the code and wonder why don’t the
add*
functions return a handle to the created object. One possible use-case for this would be the process of user editing of a geo-fence.
a
mm good point. The
add
functions aren't that useful, they're simple helper functions. I think I'll remove them. the equivalent is
Copy code
configureMap {
    val line = MapsModule
        .createPolyline(
            listOf(
                LatLng(55, 2),
                LatLng(65, 2),
                LatLng(65, 20),
                LatLng(55, 20),
            )
        ) {
            noClip = true
        }
    addLayer(line)
}
the Polyline can be created anywhere, it just needs to be added inside the
configureMap{}
block