433 |
def shape_selected(self, layer, shape): |
def shape_selected(self, layer, shape): |
434 |
self.redraw() |
self.redraw() |
435 |
|
|
436 |
def find_shape_at(self, px, py, select_labels = 0): |
def find_shape_at(self, px, py, select_labels = 0, selected_layer = 1): |
437 |
"""Return a tuple shape at point px, py in window coords.""" |
"""Determine the shape at point px, py in window coords |
438 |
|
|
439 |
|
Return the shape and the corresponding layer as a tuple (layer, |
440 |
|
shape). |
441 |
|
|
442 |
|
If the optional parameter select_labels is true (default false) |
443 |
|
search through the labels. If a label is found return it's index |
444 |
|
as the shape and None as the layer. |
445 |
|
|
446 |
|
If the optional parameter selected_layer is true (default), only |
447 |
|
search in the currently selected layer. |
448 |
|
""" |
449 |
map_proj = self.map.projection |
map_proj = self.map.projection |
450 |
if map_proj is not None: |
if map_proj is not None: |
451 |
forward = map_proj.Forward |
forward = map_proj.Forward |
488 |
y = y - height/2 |
y = y - height/2 |
489 |
if x <= px < x + width and y <= py <= y + height: |
if x <= px < x + width and y <= py <= y + height: |
490 |
return None, i |
return None, i |
491 |
|
|
492 |
layers = self.map.Layers() |
if selected_layer: |
493 |
|
layer = self.interactor.SelectedLayer() |
494 |
|
if layer is not None: |
495 |
|
layers = [layer] |
496 |
|
else: |
497 |
|
# no layer selected. Use an empty list to effectively |
498 |
|
# ignore all layers. |
499 |
|
layers = [] |
500 |
|
else: |
501 |
|
layers = self.map.Layers() |
502 |
|
|
503 |
for layer_index in range(len(layers) - 1, -1, -1): |
for layer_index in range(len(layers) - 1, -1, -1): |
504 |
layer = layers[layer_index] |
layer = layers[layer_index] |
505 |
|
|
560 |
|
|
561 |
def SelectShapeAt(self, x, y): |
def SelectShapeAt(self, x, y): |
562 |
layer, shape = self.find_shape_at(x, y) |
layer, shape = self.find_shape_at(x, y) |
563 |
|
# If layer is None, then shape will also be None. We don't want |
564 |
|
# to deselect the currently selected layer, so we simply select |
565 |
|
# the already selected layer again. |
566 |
|
if layer is None: |
567 |
|
layer = self.interactor.SelectedLayer() |
568 |
self.interactor.SelectLayerAndShape(layer, shape) |
self.interactor.SelectLayerAndShape(layer, shape) |
569 |
|
|
570 |
def LabelShapeAt(self, x, y): |
def LabelShapeAt(self, x, y): |