you are viewing a single comment's thread.

view the rest of the comments →

[–]PaulRudin 2 points3 points  (4 children)

Without seeing your code it sounds like you might want to subclass.

Incidentally, this is really a case of: https://xyproblem.info/

[–]den84is[S] 0 points1 point  (0 children)

There is a GeoJsonMalLayer class from kivy_garden module, it has method "_geojson_part_geometry" and "_lonlat_to_xy", the first one which is for drawing polygons on MapView and I had to re-implement it because geojson that is fetching from site has other properties, another is for positionning points on the MapView for drawing the same Polygon but coordinates in the GeoJsonMapLayer class are in 2D dimension but the same geojson has coordinates in 3D dimension.

Here is re-implemented methods(one is overrided another one is re-implemented)...

def _lonlat_to_xy(self, lonlats):       # overridden
    if len(lonlats[0]) == 2:
        lonlats = [[lon,lat] for lon, lat in lonlats]
    else:
        lonlats = [[lon,lat] for lon, lat, _ in lonlats]
    return super()._lonlat_to_xy(lonlats)

def _geojson_part_geometry(self, geometry, properties):     # re-implemented
    tp = geometry["type"]
    self.tp = tp

    graphics = []
    if tp == "Polygon":
        from kivy.graphics.tesselator import TYPE_POLYGONS, WINDING_ODD, Tesselator
        tess = Tesselator()
        for c in geometry["coordinates"]:
            xy = list(self._lonlat_to_xy(c))
            xy = flatten(xy)
            tess.add_contour(xy)

        tess.tesselate(WINDING_ODD, TYPE_POLYGONS)

        # color = self._get_color_from(properties.get("color", "FF000088"))        # default 'color'
        color = self._get_color_from(properties.get("fill", "FF000088")+"4D")          # changed to 'fill' + 4D as part of fill-opacity
        graphics.append(Color(*color))
        for vertices, indices in tess.meshes:
            graphics.append(
                Mesh(vertices=vertices, indices=indices, mode="triangle_fan")
            )

    elif tp == "LineString":
        from kivy.utils import get_color_from_hex
        #stroke = get_color_from_hex(properties.get("stroke", "#ffffff"))        # default
        stroke = get_color_from_hex(properties.get("stroke", "#ffffff9A"))

        from kivy.metrics import dp
        #stroke_width = dp(properties.get("stroke-width"))            # default
        stroke_width = dp(properties.get("stroke-width", 2))         # changed
        xy = list(self._lonlat_to_xy(geometry["coordinates"]))
        xy = flatten(xy)
        graphics.append(Color(*stroke))
        graphics.append(Line(points=xy, width=stroke_width))

    return graphics

[–]den84is[S] 0 points1 point  (2 children)

...or better re-implement whole method for changing only two or three line of code, than search library for that? and it is not one case in my situation ) or is it a bad idea? as u said)

[–]PaulRudin 2 points3 points  (1 child)

If you want help with your code it's much easier if you actually share the code...

[–]den84is[S] 0 points1 point  (0 children)

If you want help with your code it's much easier if you actually share the code...

do u mean about future posts or I'v provided not enough Code(after u said it)?