Jump to content

IE, Google Maps API, and JavaScript help


Recommended Posts

Hello All,

I am looking for a smoother and less intrusive way to complete my task.

My current code does what I need...

Spoiler
#include <IE.au3>
$oIE = _IECreate("about:blank")
_IENavigate($oIE, "http://spp.aaa.com/15.0.14/D2000Map/loadMap.html")
$oIE = _IEAttach("Mapping")
WinWait("Mapping")
WinActivate("Mapping")

;=========================================================== current method to set view to Streets
$oDiv = _IEGetObjById($oIE, "OpenLayers_Control_MaximizeDiv")
Sleep(500)
_IEAction($oDiv, "focus")
Sleep(90)
ControlSend("Mapping", "", "", "{enter}")

$oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
    $sLinkText = _IEPropertyGet($oInput, "outerhtml")
    If StringInStr($sLinkText, "Google Streets") Then
        $oInput.Focus()
        Sleep(500)
        ControlSend("Mapping", "", "", "{enter}")

    EndIf
Next

$oDiv = _IEGetObjById($oIE, "OpenLayers_Control_MinimizeDiv")
Sleep(500)
_IEAction($oDiv, "focus")
Sleep(90)
ControlSend("Mapping", "", "", "{enter}")


;======================================================== current method for centering and zooming map

Sleep(1000)
$oDiv = _IEGetObjById($oIE, "OpenLayers_Control_PanZoomBar_53_zoomout")
Sleep(500)
_IEAction($oDiv, "focus")
Sleep(500)
ControlSend("Mapping", "", "", "{enter}")

$oDiv = _IEGetObjById($oIE, "OpenLayers_Control_PanZoomBar_53_panup")
Sleep(500)
_IEAction($oDiv, "focus")
Sleep(500)
ControlSend("Mapping", "", "", "{enter}")

 

But I am wanting to work more "behind the scenes".

By looking at the JavaScript found at the source, i'm guessing there is a third party program called OpenLayers working with the Google Maps API.

I was wondering if there was a way to manipulate the JavaScript or the Document Object Models in an IE window that I did not create (opened by another program).

I know VERY LITTLE outside of simple AutoIt code and UDFs that I am not even sure if what I just said makes sense.

My 3 days of research and "patchwork" of attempted code created from examples and "trial and error guesses" ended in confusion

and a "crime of passion" (frustratingly erasing ALL attempts because they were wrong, confusing, didn't work, gave me a migraine, resembled Frankenstein's monster,

filled me with anger and hatred and a shame so deep that I stood in a hot shower for 30 minutes trying to wash it away).

I think my main problem is not knowing if this is possible, and the proper syntax for manipulating DOM from within AutoIt.

  • The ACTUAL window I am working with is an Internet Explorer_Server window opened by a program that passes my credentials and other info to it. So I have to stick with IE.
  • The IE page in my example code above is just the source, NOT the window I am tying to automate, it is identical except the bottom bar doesn't seem to send to the server so I'm not sure if it can even be used for testing purposes.

 

Any insight in non-programmer terms or some examples to show me the proper syntax will be greatly appreciated.

:alien:

If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

5 minutes ago, AutoBert said:

are you sure Google maps allow manipulating data in the way you want?

I think that is what the Google Maps API is for, I know you can use it to create your own map overlays the way the program i'm using does.

But I am not creating, I am trying to manipulate an already created map.

I am NOT sure if it works that way, that is why I asked IF it is possible in the first post.

If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

Progress!! Yay!

First, i'm pretty sure the link to the map I gave in my example code in first post is not "live" because I cant get it to accept ANYTHING. Therefore it doesn't seem possible that anyone here will be able to actually test anything.

BUT, I did manage to get something to work on the actual program that i'm using. So this...

$oIE.setCenterAndZoom(30.3144639, -81.67038, 10)

...replaces this...

Spoiler
$oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
    $sLinkText = _IEPropertyGet($oInput, "outerhtml")
    If StringInStr($sLinkText, $sMyString1) Then
        _IEFormElementSetValue($oInput, "8298 Riverview Drive")
    EndIf
Next
$oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
    $sLinkText = _IEPropertyGet($oInput, "outerhtml")
    If StringInStr($sLinkText, $sMyString2) Then
        _IEFormElementSetValue($oInput, "st augustine, FL")
    EndIf
Next
$oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
    $sLinkText = _IEPropertyGet($oInput, "outerhtml")
    If StringInStr($sLinkText, $sMyString3) Then
        _IEAction($oInput, "focus")
        Sleep(90)
        ControlSend("Bing Map", "", "", "{enter}")
    EndIf
Next
Sleep(1000)
$oDiv = _IEGetObjById($oIE, "OpenLayers_Control_PanZoomBar_53_zoomout")
Sleep(500)
_IEAction($oDiv, "focus")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
;ControlSend("Bing Map", "", "", "{enter}")
;Sleep(500)
$oDiv = _IEGetObjById($oIE, "OpenLayers_Control_PanZoomBar_53_panup")
Sleep(500)
_IEAction($oDiv, "focus")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")
Sleep(500)
ControlSend("Bing Map", "", "", "{enter}")

 

 

Now I just need to figure out how to change the view from "Hybrid" to "Street" (or "ROADMAP" as I believe the Google Map API calls it).

The part that irritates me the most about this issue is that Google's default view IS "Street", but for some reason my work program felt the need to purposely change it although the main purpose of my work's map is to show the locations of our service trucks and the service call locations, there is no need for any "greenery" in our work functions.

This new default view just started Friday when they "updated" the program and switched from Bing maps to Google, but they didn't change the Window title if you are wondering why my script says Bing Map.

Edited by alienclone
If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

Ok, one step closer!

Managed to get my script to click the radio button for "Google Streets" without opening and closing the menu (plus sign "+" in top right edge of map).

It shows the radio button selected after the script runs. but it doesn't actually implement the action so the map stays in "Google Hybrid" view.

#include <IE.au3>
$oIE = _IECreate("about:blank")
_IENavigate($oIE, "http://spp.aaa.com/15.0.14/D2000Map/loadMap.html")
_IELoadWait($oIE)

WinWait("Mapping")

; ===> Temp "slow downs" until I can properly solve my premature script continuation issue
Sleep(900)
Do
    sleep(90)
    $url=$oIE.LocationURL
until $url<>""
Sleep(900)
; =========================

$oIE = _IEAttach("Mapping")

$oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
    $sLinkText = _IEPropertyGet($oInput, "outerhtml")
    If StringInStr($sLinkText, "Google Streets") Then
        $oInput.click()

    EndIf
Next

Tried using _IEFormElementRadioSelect to do this but I don't know how without finding an actual "Form" or "Radio Group" that it belongs to. If someone could help me find that, it would probably be the best route for this task, and easier than what I am currently attempting.

Edited by alienclone
shamelessly whispering @DaleHohm in hopes that his ears will ring and he comes to see who is talking about him (and help me find a solution using his magical IE powers)
If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

var myOptions = {
  center: new google.maps.LatLng(39.729001, -94.902342),
  zoom: 3,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
setUpMarker(map);

And here is the api reference:

https://developers.google.com/maps/documentation/javascript/3.22/reference#MapTypeId

Link to comment
Share on other sites

10 hours ago, Juvigy said:
var myOptions = {
  center: new google.maps.LatLng(39.729001, -94.902342),
  zoom: 3,
    mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
setUpMarker(map);

And here is the api reference:

https://developers.google.com/maps/documentation/javascript/3.22/reference#MapTypeId

I really appreciate you taking the time to go through all those JS files, and I am sorry that I didn't explain myself better in the first post.

But I already have all of this information, I just don't know how to integrate it with AutoIt and the proper syntax to call the functions on an existing IE window that has already loaded.

If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

Well I think I have decided to give up.

Not only did I not figure out how to change it to "Google Streets" (ROADMAP), but the one part I did manage to figure out...

$oIE.setCenterAndZoom(30.3144639, -81.67038, 10)

...only wants to work on some of the computers I am working with, and of course it gives no errors when it doesn't work.

I may revisit this project at a later time but an entire week of work to produce ONE unreliable line of code has discouraged me for now.

Thank you to  @AutoBert and @Juvigy for the responses.

If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...