1

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.

ageoff
  • 2,798
  • 2
  • 24
  • 39

1 Answers1

1

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();")
Community
  • 1
  • 1
Matt Luongo
  • 14,371
  • 6
  • 53
  • 64
  • This is not a web application. It is a python desktop application. I am only using QWebView to display the google maps because they only support javascript and that is the only way i know how to display the webpage in a python window. – ageoff Dec 28 '12 at 15:46
  • Sorry about that! just caught it. – Matt Luongo Dec 28 '12 at 15:48
  • 1
    Holy cow. That worked perfectly. Only thing is a little typo in the answer. evaluateJavascript should be evaluateJavaScript. Thank you very much for you help. – ageoff Dec 28 '12 at 17:14