python - OpenLayers Geolocation in PyQt 5.9 -


i've implemented website geolocation function , button.

this webpage gets displayed fine in qwebengineview (osm map too). webpage loaded

def __init__(self, parent=none):         super(maingui, self).__init__(parent)         self.ui = uic.loadui("gps.ui", self)         self.ui.w3view.load(qtcore.qurl('file:///map.html')) 

all native openlayers buttons (zoom in , out) working fine.

i created new custom button display geolocation on openlayers map.

this function im using geolocate me:

var handlegeolocation = function() {        var coordinates;       var geolocation = new ol.geolocation({         projection: view.getprojection(),         tracking: true       });       // handle geolocation error.       geolocation.on('error', function (error) {         var info = document.getelementbyid('info');         info.innerhtml = error.message;         info.style.display = '';       });        var accuracyfeature = new ol.feature();       geolocation.on('change:accuracygeometry', function () {         accuracyfeature.setgeometry(geolocation.getaccuracygeometry());       });        var positionfeature = new ol.feature();       positionfeature.setstyle(new ol.style.style({         image: new ol.style.circle({           radius: 6,           fill: new ol.style.fill({             color: '#3399cc'           }),           stroke: new ol.style.stroke({             color: '#fff',             width: 2           })         })       }));        geolocation.once('change:position', function () {         coordinates = geolocation.getposition();         positionfeature.setgeometry(coordinates ?           new ol.geom.point(coordinates) : null);         map.getview().setcenter(coordinates);         map.getview().setzoom(17);       });        new ol.layer.vector({         map: map,         source: new ol.source.vector({           features: [accuracyfeature, positionfeature]         })       });     } 

i created button here.

the whole webpage looks this:

<!doctype html> <html>   <head>     <title>accessible map</title>     <link rel="stylesheet" href="https://openlayers.org/en/v4.2.0/css/ol.css" type="text/css">     <!-- line below needed old environments internet explorer , android 4.x -->     <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestanimationframe,element.prototype.classlist,url"></script>     <script src="https://openlayers.org/en/v4.2.0/build/ol-debug.js"></script>    <style>       a.skiplink {         position: absolute;         clip: rect(1px, 1px, 1px, 1px);         padding: 0;         border: 0;         height: 1px;         width: 1px;         overflow: hidden;       }       a.skiplink:focus {         clip: auto;         height: auto;         width: auto;         background-color: #fff;         padding: 0.3em;       }       #map:focus {         outline: #4a74a8 solid 0.15em;       }       map{           max-width: 760 px;           max-height: 50 px;       }        .geobutton {         top: 80px;         left: .5em;       }     </style>   </head>   <body>     <div id="map" class="map" tabindex="0"></div>     <script>       window.app = {};       var app = window.app;         view = new ol.view({         center: [0, 0],         zoom: 2       });        app.getlocation = function(opt_options) {         var options = opt_options || {};          var geobutton = document.createelement('button');         geobutton.innerhtml = 'l';          var handlegeolocation = function() {           /*    var ismobile =  {               android: function () {                 return navigator.useragent.match(/android/i);               },               blackberry: function () {                 return navigator.useragent.match(/blackberry/i);               },               ios: function () {                 return navigator.useragent.match(/iphone|ipod|ipad/i);               },               opera: function () {                 return navigator.useragent.match(/opera mini/i);               },               windows: function () {                 return navigator.useragent.match(/iemobile/i);               },               any: function () {                 return ((ismobile.android() || ismobile.blackberry() || ismobile.ios() || ismobile.opera() || ismobile.windows()));               }             };              if (ismobile.any()){               geolocation.settrackingoptions(enablehighaccuracy );             } */            var coordinates;           var geolocation = new ol.geolocation({             projection: view.getprojection(),             tracking: true           });           // handle geolocation error.           geolocation.on('error', function (error) {             var info = document.getelementbyid('info');             info.innerhtml = error.message;             info.style.display = '';           });            var accuracyfeature = new ol.feature();           geolocation.on('change:accuracygeometry', function () {             accuracyfeature.setgeometry(geolocation.getaccuracygeometry());           });            var positionfeature = new ol.feature();           positionfeature.setstyle(new ol.style.style({             image: new ol.style.circle({               radius: 6,               fill: new ol.style.fill({                 color: '#3399cc'               }),               stroke: new ol.style.stroke({                 color: '#fff',                 width: 2               })             })           }));            geolocation.once('change:position', function () {             coordinates = geolocation.getposition();             positionfeature.setgeometry(coordinates ?               new ol.geom.point(coordinates) : null);             map.getview().setcenter(coordinates);             map.getview().setzoom(17);           });            new ol.layer.vector({             map: map,             source: new ol.source.vector({               features: [accuracyfeature, positionfeature]             })           });         }          geobutton.addeventlistener('click', handlegeolocation, false);         geobutton.addeventlistener('touchstart', handlegeolocation, false);          var element = document.createelement('div');         element.classname = 'ol-unselectable ol-control geobutton';         element.appendchild(geobutton);          ol.control.control.call(this, {           element: element,           target: options.target         });        };        ol.inherits(app.getlocation, ol.control.control);       //standard initialisierung         // geolocation function          var map = new ol.map({         layers: [           new ol.layer.tile({             source: new ol.source.osm()           })         ],         target: 'map',         controls: ol.control.defaults({           attributionoptions: /** @type {olx.control.attributionoptions} */ ({             collapsible: false           })         }).extend([new app.getlocation()]),         view: view       });        //display input datastream     </script>   </body> </html> 

inside normal browser it's working fine not inside pyqt app. after clicking custom button nothing happens.

what doing wrong or not possible?

the main problem enable permissions, if run in browser firefox, chrome, etc. show popup asking accept or not geolocation permission.

in case must enabled code, qwebenginepage emits signal every time authorization required, through signal featurepermissionrequested, connect slot , enable permission function setfeaturepermission().

    self.ui.w3view..page().featurepermissionrequested.connect(self.onfeaturepermissionrequested)  def onfeaturepermissionrequested(self, securityorigin, feature):     self.sender().setfeaturepermission(securityorigin,                                      qwebenginepage.geolocation,                                      qwebenginepage.permissiongrantedbyuser) 

note: in linux still have problems geoclude provider, error message follows:

failed set geoclue positioning requirements. geoclue error: org.qtproject.qtdbus.error.invalidobjectpath


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -