如何在Kivy地图中追踪路径? [英] How to trace a path in Kivy map?

查看:93
本文介绍了如何在Kivy地图中追踪路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实际上想绘制街道,但实际上我想绘制Strets路径(如Google地图).

i am trying to draw the streets actually i want to draw the strets path (like google maps) but this is what i got.enter image description here

    puntoA = self.puntos[0]
    puntoB = self.puntos[1]
    direccionx = puntoA.lon - puntoB.lon
    direcciony = puntoA.lat - puntoB.lat
    distanciax = direccionx/25
    distanciay = direcciony/25
    for i in range(25):
        print i
        puntox = distanciax*i
        puntoy = distanciay*i
        self.mv.add_marker(MapMarker(lat = self.puntos[1].lat + puntoy , lon = self.puntos[1].lon + puntox, source = self.icons + "Entypo_e78b(0)_32.png"))

推荐答案

我在一个Google网上论坛中找到了它,并且有效.

I found this in a google group, and it works.

class LineMapLayer(MapLayer):
def __init__(self, **kwargs):
    super(LineMapLayer, self).__init__(**kwargs)
    self.zoom = 15

    geo_dover   = [18.455750,-69.970347]
    geo_calais  = [18.456259,-69.966334]

    # NOTE: Points must be valid as they're no longer clamped
    self.coordinates = []


def newpointgeo(self,longlat):
    longlatx = (longlat[1],longlat[0])
    self.coordinates.append(longlatx)

def reposition(self):
    mapview = self.parent

    #: Must redraw when the zoom changes 
    #: as the scatter transform resets for the new tiles
    if (self.zoom != mapview.zoom):
        self.draw_line()

def gen_point(self):
    n = len(self.coordinates)
    dx,dy = random.randint(-100,100)/10000.0,random.randint(0,100)/10000.0
    c = (self.coordinates[-1][0]+dx,
         self.coordinates[-1][1]+dy)

    return c

def add_point(self):
    #: Add a random point close to the previous one
    for i in range(len(self.coordinates)):
        self.coordinates.append(self.gen_point())
    self.draw_line()

def get_x(self, lon):
    """Get the x position on the map using this map source's projection
    (0, 0) is located at the top left.
    """
    return clamp(lon, MIN_LONGITUDE, MAX_LONGITUDE)

def get_y(self, lat):
    """Get the y position on the map using this map source's projection
    (0, 0) is located at the top left.
    """
    lat = clamp(-lat, MIN_LATITUDE, MAX_LATITUDE)
    lat = lat * pi / 180.
    return ((1.0 - log(tan(lat) + 1.0 / cos(lat)) / pi))

def draw_line(self, *args):
    mapview = self.parent
    self.zoom = mapview.zoom

    # When zooming we must undo the current scatter transform
    # or the animation distorts it
    scatter = mapview._scatter
    map_source = mapview.map_source
    sx,sy,ss = scatter.x, scatter.y, scatter.scale
    vx,vy,vs = mapview.viewport_pos[0], mapview.viewport_pos[1], mapview.scale

    # Account for map source tile size and mapview zoom
    ms = pow(2.0,mapview.zoom) * map_source.dp_tile_size

    #: Since lat is not a linear transform we must compute manually 
    line_points = []
    for lat,lon in self.coordinates:
        line_points.extend((self.get_x(lon),self.get_y(lat)))
        #line_points.extend(mapview.get_window_xy_from(lat,lon,mapview.zoom))


    with self.canvas:
        # Clear old line
        self.canvas.clear()

        # Undo the scatter animation transform
        Scale(1/ss,1/ss,1)
        Translate(-sx,-sy)

        # Apply the get window xy from transforms
        Scale(vs,vs,1)
        Translate(-vx,-vy)

        # Apply the what we can factor out
        # of the mapsource long,lat to x,y conversion
        Scale(ms/360.0,ms/2.0,1)
        Translate(180,0)

        # Draw new
        Color( 0, 0 , 0 , .8)
        Line(points=line_points , width=4/ms , joint_presicion = 100)#4/ms)#,joint_precision=100)

这篇关于如何在Kivy地图中追踪路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆