Skip to content

Customising MapMarker and MapMarker Popup with canvas to include text. #56

@Codename-Nase

Description

@Codename-Nase

Hi all.
I tried creating a RoundRaisedButton with text, and then use it as a MapMarker and MapMarkerPopup itself instead of using an icon with source.
Creating the Button worked fine as shown below:

`from kivy.lang import Builder
from kivy.uix.behaviors import ButtonBehavior
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.app import MDApp
from kivymd.uix.behaviors import (
CircularRippleBehavior,
FakeCircularElevationBehavior,
)

KV = '''
:
size_hint: None, None
size: "25dp", "25dp"
radius: self.size[0] / 2
md_bg_color: 1, 0, 0, 1
MDLabel:
text: "[b]DC[/b]"
markup: True
halign: "center"
valign: "center"
size: root.size
pos: root.pos
font_size: root.size[0] * .6
theme_text_color: "Custom"
text_color: [1] * 4
MDScreen:

CircularElevationButton:
    pos_hint: {"center_x": .5, "center_y": .6}
    elevation: 4

'''

class CircularElevationButton(
FakeCircularElevationBehavior,
CircularRippleBehavior,
ButtonBehavior,
MDBoxLayout,
):
pass

class Example(MDApp):
def build(self):
return Builder.load_string(KV)

Example().run()`

But after adding it as a child widget under MapView to replace the regular MapMarkerPopup, the text became redundant. I don't know if i am not doing it right, or otherwise.
Below is a code of how I have tried implementing it with MapView, and any helpful pointer towards a better solution will be very much appreciated.

`from kivy.lang import Builder
from kivy.uix.behaviors import ButtonBehavior
from kivy.garden.mapview import MapMarkerPopup
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.app import MDApp
from kivymd.uix.behaviors import (
CircularRippleBehavior,
FakeCircularElevationBehavior,
)

KV = '''
:
size_hint: None, None
size: "25dp", "25dp"
radius: self.size[0] / 2
md_bg_color: 1, 0, 0, 1
MDLabel:
text: "[b]DC[/b]"
markup: True
halign: "center"
valign: "center"
size: root.size
pos: root.pos
font_size: root.size[0] * .6
theme_text_color: "Custom"
text_color: [1] * 4

MapView:
lat: 10
lon: 10
zoom: 5
CircularElevationButton:
lat: 12
lon: 12
elevation: 5
'''

class CircularElevationButton(
MapMarkerPopup,
FakeCircularElevationBehavior,
CircularRippleBehavior,
ButtonBehavior,
MDBoxLayout,
):
pass

class Example(MDApp):
def build(self):
return Builder.load_string(KV)

Example().run()`

Below is an image of what i am trying to replicate as a Marker
Screenshot 2022-05-14 at 09 56 33
.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions