Advertisement
Guest User

Map

a guest
Apr 6th, 2017
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 4.34 KB | None | 0 0
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2015 The Qt Company Ltd.
  4. ** Contact: http://www.qt.io/licensing/
  5. **
  6. ** This file is part of the examples of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:BSD$
  9. ** You may use this file under the terms of the BSD license as follows:
  10. **
  11. ** "Redistribution and use in source and binary forms, with or without
  12. ** modification, are permitted provided that the following conditions are
  13. ** met:
  14. **   * Redistributions of source code must retain the above copyright
  15. **     notice, this list of conditions and the following disclaimer.
  16. **   * Redistributions in binary form must reproduce the above copyright
  17. **     notice, this list of conditions and the following disclaimer in
  18. **     the documentation and/or other materials provided with the
  19. **     distribution.
  20. **   * Neither the name of The Qt Company Ltd nor the names of its
  21. **     contributors may be used to endorse or promote products derived
  22. **     from this software without specific prior written permission.
  23. **
  24. **
  25. ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  26. ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  27. ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  28. ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  29. ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  30. ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  31. ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  32. ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  33. ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  34. ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  35. ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
  36. **
  37. ** $QT_END_LICENSE$
  38. **
  39. ****************************************************************************/
  40.  
  41. //! [Imports]
  42. import QtQuick 2.0
  43. import QtPositioning 5.5
  44. import QtLocation 5.6
  45. //! [Imports]
  46.  
  47. Rectangle {
  48.     width: 720
  49.     height: 480
  50.  
  51.     property double aa: 48.47982347
  52.     property double bb: 35.01630306
  53.     //! [Initialize Plugin]
  54.     Plugin {
  55.         id: myPlugin
  56.         name: "osm"
  57.         //specify plugin parameters if necessary
  58.         //PluginParameter {...}
  59.         //PluginParameter {...}
  60.         //...
  61.     }
  62.     //! [Initialize Plugin]
  63.  
  64.     //! [Current Location]
  65.     PositionSource {
  66.         id: positionSource
  67.         property variant lastSearchPosition: locationOslo
  68.         active: true
  69.         updateInterval: 120000 // 2 mins
  70.         onPositionChanged:  {
  71.             var currentPosition = positionSource.position.coordinate
  72.             map.center = currentPosition
  73.             var distance = currentPosition.distanceTo(lastSearchPosition)
  74.             if (distance > 500) {
  75.                 // 500m from last performed pizza search
  76.                 lastSearchPosition = currentPosition
  77.                 searchModel.searchArea = QtPositioning.circle(currentPosition)
  78.                 searchModel.update()
  79.             }
  80.         }
  81.     }
  82.     //! [Current Location]
  83.     //! [PlaceSearchModel]
  84.     property variant locationOslo: QtPositioning.coordinate(aa, bb)
  85.  
  86.     PlaceSearchModel {
  87.         id: searchModel
  88.  
  89.         plugin: myPlugin
  90.  
  91.         searchTerm: "Pizza"
  92.         searchArea: QtPositioning.circle(locationOslo)
  93.  
  94.         Component.onCompleted: update()
  95.     }
  96.     //! [PlaceSearchModel]
  97.  
  98.  
  99.     //! [Places MapItemView]
  100.     Map {
  101.         id: map
  102.         anchors.fill: parent
  103.         plugin: myPlugin;
  104.         center: locationOslo
  105.         zoomLevel: 13
  106.  
  107.         MapItemView {
  108.             model: searchModel
  109.             delegate: MapQuickItem {
  110.                 coordinate: QtPositioning.coordinate(aa, bb)
  111.  
  112.                 anchorPoint.x: image.width * 0.5
  113.                 anchorPoint.y: image.height
  114.  
  115.                 sourceItem: Column {
  116.                     Image { id: image; source: "marker.png" }
  117.                     Text { text: title; font.bold: true }
  118.                 }
  119.             }
  120.         }
  121.     }
  122.     //! [Places MapItemView]
  123.  
  124.     Connections {
  125.         target: searchModel
  126.         onStatusChanged: {
  127.             if (searchModel.status == PlaceSearchModel.Error)
  128.                 console.log(searchModel.errorString());
  129.         }
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement