GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — mapview/examples/test_kdbush.py at develop · dengbolin1/mapview Expand file tree/ Copy pathtest_kdbush.pyMore file actions 80 lines (60 loc) · 2.12 KB / Copy pathtest_kdbush.pyFile metadata and controls80 lines (60 loc) · 2.12 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 """ Demonstrate the speed of the KD-tree (KDBush) implementation The green circle will indicate the selection zone, the blue rectangle indicate the selected red dot. """ from random import random from kivy.app import App from kivy.graphics import Canvas, Color, Ellipse, Rectangle from kivy.uix.widget import Widget from kivy_garden.mapview.clustered_marker_layer import KDBush, Marker # creating markers points = [] for i in range(10000): points.append(Marker(lon=random() * 360 - 180, lat=random() * 180 - 90)) # test kdbush kdbush = KDBush(points, 64) class TestWidget(Widget): selection = [] selection_center = None radius = 0.1 canvas_points = None def build(self): radius = self.radius if not self.canvas_points: self.canvas_points = Canvas() self.canvas.add(self.canvas_points) with self.canvas_points: Color(1, 0, 0) for marker in points: Rectangle(pos=(marker.x * 600, marker.y * 600), size=(2, 2)) self.canvas.before.clear() with self.canvas.before: if self.selection_center: Color(0, 1, 0, 0.5) x, y = self.selection_center r = radius * 600 r2 = r * 2 Ellipse(pos=(x - r, y - r), size=(r2, r2)) if self.selection: Color(0, 0, 1) for m_id in self.selection: # x = kdbush.coords[m_id * 2] # y = kdbush.coords[m_id * 2 + 1] marker = points[m_id] x = marker.x y = marker.y Rectangle(pos=(x * 600 - 4, y * 600 - 4), size=(8, 8)) def on_touch_down(self, touch): self.select(*touch.pos) def on_touch_move(self, touch): self.select(*touch.pos) def select(self, x, y): self.selection_center = (x, y) self.selection = kdbush.within(x / 600.0, y / 600.0, self.radius) self.build() class TestApp(App): def build(self): self.root = TestWidget() self.root.build() TestApp().run() |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |