예제 #1
0
class OSMInfotool(QgsMapTool):
  def __init__(self, iface):
    QgsMapTool.__init__(self, iface.mapCanvas())
    self.result_renderer = RubberBandResultRenderer()
    
    self.canvas = iface.mapCanvas()
    #self.emitPoint = QgsMapToolEmitPoint(self.canvas)
    self.iface = iface

    self.cursor = QCursor(QPixmap(":/plugins/osminfo/icons/cursor.png"), 1, 1)
    #self.visibilityChanged.connect(self.result_renderer.clear)
    
    self.docWidgetResults = ResultsDialog("OSM Info", self.result_renderer, self.iface.mainWindow())
    self.docWidgetResults.setVisible(False)
    self.docWidgetResults.setFloating(True)
    self.docWidgetResults.visibilityChanged.connect(self.docWidgetResultsVisChange)

  def __del__(self):
    self.clearCanvas()

  def clearCanvas(self):
    self.result_renderer.clear()
    self.result_renderer.clear_feature()
  
  def docWidgetResultsVisChange(self, vis):
    if vis is False:
        self.clearCanvas()

  def activate(self):
    self.canvas.setCursor(self.cursor)

  def deactivate(self):
    if self.docWidgetResults.isFloating():
        self.docWidgetResults.setVisible(False)

  def canvasReleaseEvent(self, event):

    crsSrc = self.canvas.mapRenderer().destinationCrs()
    crsWGS = QgsCoordinateReferenceSystem(4326)

    QApplication.setOverrideCursor(Qt.WaitCursor)
    x = event.pos().x()
    y = event.pos().y()
    point = self.canvas.getCoordinateTransform().toMapCoordinates(x, y)

    xform = QgsCoordinateTransform(crsSrc, crsWGS)
    point = xform.transform(QgsPoint(point.x(), point.y()))
    QApplication.restoreOverrideCursor()

    xx = str(point.x())
    yy = str(point.y())

    self.result_renderer.clear()
    self.result_renderer.clear_feature()
    self.result_renderer.show_point(point, False)
    self.canvas.update()

    self.docWidgetResults.getInfo(xx, yy)
    self.docWidgetResults.setVisible(True)
예제 #2
0
class QuickGeocodingToolbox(QDockWidget, FORM_CLASS):
    def __init__(self, iface):
        QDockWidget.__init__(self, iface.mainWindow())
        self.setupUi(self)

        self.iface = iface
        self.search_threads = None  # []
        self.result_renderer = RubberBandResultRenderer(iface)

        if hasattr(self.txtSearch, 'setPlaceholderText'):
            self.txtSearch.setPlaceholderText(self.tr("Address..."))

        self.txtSearch.textChanged.connect(self.start_geocode)
        self.cmbGeocoder.currentIndexChanged.connect(self.start_geocode)

        geocoders = GeocoderFactory.get_geocoders_names()
        geocoders.sort()
        for geocoder_name in geocoders:
            icon_path = GeocoderFactory.get_geocoder(geocoder_name).icon_path
            self.cmbGeocoder.addItem(QIcon(icon_path), geocoder_name)

        self.lstSearchResult.currentItemChanged.connect(self.result_selected)
        self.lstSearchResult.itemDoubleClicked.connect(self.result_selected)

        self.visibilityChanged.connect(self.result_renderer.clear)

    def __del__(self):
        self.result_renderer.clear()

    def start_geocode(self):
        search_text = unicode(self.txtSearch.text())
        if not search_text:
            self.lstSearchResult.clear()
            return

        geocoder_name = self.cmbGeocoder.currentText()

        if 1 == 1 and self.search_threads:
            print 'Kill ', self.search_threads
            self.search_threads.terminate()
            self.search_threads.wait()

        self.show_progress()
        searcher = SearchThread(search_text, geocoder_name,
                                self.iface.mainWindow())
        searcher.data_downloaded.connect(self.show_result)
        searcher.error_occurred.connect(self.show_error)
        self.search_threads = searcher  # .append(searcher)
        searcher.start()

    def show_progress(self):
        self.lstSearchResult.clear()
        self.lstSearchResult.addItem(self.tr('Searching...'))

    def show_result(self, results):
        self.lstSearchResult.clear()
        if results:
            for (pt, desc) in results:
                new_item = QListWidgetItem()
                new_item.setText(unicode(desc))
                new_item.setData(Qt.UserRole, pt)
                self.lstSearchResult.addItem(new_item)
        else:
            new_item = QListWidgetItem()
            new_item.setText(self.tr('No results!'))
            new_item.setData(Qt.UserRole, None)
            self.lstSearchResult.addItem(new_item)

        self.lstSearchResult.update()

    def show_error(self, error_text):
        #print error_text
        self.lstSearchResult.clear()
        self.lstSearchResult.addItem(error_text)

    def result_selected(self, current=None, previous=None):
        self.result_renderer.clear()
        if current:
            point = current.data(Qt.UserRole)
            if isinstance(point, QgsPoint) and (point.x() != 0
                                                and point.y() != 0):
                self.result_renderer.show_point(point, True)

    # for Settings
    def get_active_geocoder_name(self):
        return self.cmbGeocoder.currentText()

    def set_active_geocoder(self, geocoder_name):
        item_index = self.cmbGeocoder.findText(geocoder_name)
        if item_index >= 0:
            self.cmbGeocoder.setCurrentIndex(item_index)
예제 #3
0
class OSMInfotool(QgsMapTool):
    def __init__(self, iface):
        QgsMapTool.__init__(self, iface.mapCanvas())
        self.result_renderer = RubberBandResultRenderer()

        self.canvas = iface.mapCanvas()
        #self.emitPoint = QgsMapToolEmitPoint(self.canvas)
        self.iface = iface

        self.cursor = QCursor(QPixmap(":/plugins/osminfo/icons/cursor.png"), 1,
                              1)
        #self.visibilityChanged.connect(self.result_renderer.clear)

        self.docWidgetResults = ResultsDialog("OSM Info", self.result_renderer,
                                              self.iface.mainWindow())
        self.docWidgetResults.setVisible(False)
        self.docWidgetResults.setFloating(True)
        self.docWidgetResults.visibilityChanged.connect(
            self.docWidgetResultsVisChange)

    def __del__(self):
        self.clearCanvas()

    def clearCanvas(self):
        self.result_renderer.clear()
        self.result_renderer.clear_feature()

    def docWidgetResultsVisChange(self, vis):
        if vis is False:
            self.clearCanvas()

    def activate(self):
        self.canvas.setCursor(self.cursor)

    def deactivate(self):
        if self.docWidgetResults.isFloating():
            self.docWidgetResults.setVisible(False)

    def canvasReleaseEvent(self, event):

        crsSrc = self.canvas.mapRenderer().destinationCrs()
        crsWGS = QgsCoordinateReferenceSystem(4326)

        QApplication.setOverrideCursor(Qt.WaitCursor)
        x = event.pos().x()
        y = event.pos().y()
        point = self.canvas.getCoordinateTransform().toMapCoordinates(x, y)

        xform = QgsCoordinateTransform(crsSrc, crsWGS)
        point = xform.transform(QgsPoint(point.x(), point.y()))
        QApplication.restoreOverrideCursor()

        xx = str(point.x())
        yy = str(point.y())

        self.result_renderer.clear()
        self.result_renderer.clear_feature()
        self.result_renderer.show_point(point, False)
        self.canvas.update()

        self.docWidgetResults.getInfo(xx, yy)
        self.docWidgetResults.setVisible(True)
class QuickGeocodingToolbox(QDockWidget, Ui_QuickGeocodingToolbox):
    def __init__(self, iface):
        QDockWidget.__init__(self, iface.mainWindow())
        self.setupUi(self)
        
        self.iface = iface
        self.search_threads = None  # []
        self.result_renderer = RubberBandResultRenderer(iface)

        if hasattr(self.txtSearch, 'setPlaceholderText'):
            self.txtSearch.setPlaceholderText(self.tr("Address..."))

        self.txtSearch.textChanged.connect(self.start_geocode)
        self.cmbGeocoder.currentIndexChanged.connect(self.start_geocode)
        self.cmbGeocoder.addItems(GeocoderFactory.get_geocoders_names())

        self.lstSearchResult.currentItemChanged.connect(self.result_selected)
        self.lstSearchResult.itemDoubleClicked.connect(self.result_selected)

        self.visibilityChanged.connect(self.result_renderer.clear)

    def __del__(self):
        self.result_renderer.clear()

    def start_geocode(self):
        search_text = unicode(self.txtSearch.text())
        if not search_text:
            self.lstSearchResult.clear()
            return
        
        geocoder_name = self.cmbGeocoder.currentText()
        
        if 1 == 1 and self.search_threads:
            print 'Kill ', self.search_threads
            self.search_threads.terminate()
            self.search_threads.wait()
            
        self.show_progress()
        searcher = SearchThread(search_text, geocoder_name, self.iface.mainWindow())
        searcher.data_downloaded.connect(self.show_result)
        searcher.error_occurred.connect(self.show_error)
        self.search_threads = searcher  # .append(searcher)
        searcher.start()

    def show_progress(self):
        self.lstSearchResult.clear()
        self.lstSearchResult.addItem(self.tr('Searching...'))
        
    def show_result(self, results):
        self.lstSearchResult.clear()
        if results:
            for (pt, desc) in results:
                new_item = QListWidgetItem()
                new_item.setText(unicode(desc))
                new_item.setData(Qt.UserRole, pt)
                self.lstSearchResult.addItem(new_item)
        else:
            new_item = QListWidgetItem()
            new_item.setText(self.tr('No results!'))
            new_item.setData(Qt.UserRole, None)
            self.lstSearchResult.addItem(new_item)

        self.lstSearchResult.update()
            
    def show_error(self, error_text):
        #print error_text
        self.lstSearchResult.clear()
        self.lstSearchResult.addItem(error_text)

    def result_selected(self, current=None, previous=None):
        self.result_renderer.clear()
        if current:
            point = current.data(Qt.UserRole)
            if isinstance(point, QgsPoint) and (point.x() != 0 and point.y() != 0):
                self.result_renderer.show_point(point, True)

    # for Settings
    def get_active_geocoder_name(self):
        return self.cmbGeocoder.currentText()

    def set_active_geocoder(self, geocoder_name):
        item_index = self.cmbGeocoder.findText(geocoder_name)
        if item_index >= 0:
            self.cmbGeocoder.setCurrentIndex(item_index)