Reputation: 2828
Ok, so I have used this code to setup a simple program. Basically it just sets points on a map in python. Very basic. The problem now is I have a condition where when that condition happens it refreshes the page with a simple QWebView.setHtml()
. What I want to do now is find a way to get the current zoom and center information of the map and save it. Is there anyway to go into the javascript and grab that information, store it and then write it into the html the same way this code already does before i do the refresh?
Sorry if this is confusing or broad, I just cant think of a way to get the information from the map using python.
Upvotes: 1
Views: 543
Reputation: 14829
There are a number of ways to interact with client-side code from the server (Python). You could set a cookie on the client, send an AJAX request to the server from Javascript, submit a form, or go a more exotic route like WebSockets. Without more information, I'm not sure we can tell you which is the best.
What web framework are you using?
EDIT:
Oh, I see- you're using a scriptable web view... maybe something like zoom = view.evaluateJavaScript('map.getZoom();')
? From what I can see of the library, the difficult part might be getting a reference to the map var in JS.
EDIT:
I don't think this is possible without modifying or extending pymaps, since it scopes the GMap locally in JS and doesn't expose it anywhere. I've done just that in a gist. You can then access the zoom with something similar to the above- maybe zoom = view.evaluateJavaScript("PyMaps[0].gmap.getZoom();")
.
EDIT:
In case this wasn't clear- the gist I included requires that you use MyPyMap
instead of PyMap
.
From another StackOverflow question, I realized you can't do evaluteJavaScript
straight on a view. The subsequent code would look more like this
doc = view.page().mainFrame().documentElement()
zoom_level = doc.evaluateJavaScript("PyMaps[0].gmap.getZoom();")
Upvotes: 1