0

I am trying to call my GWT function from external js.But i am getting error ****window.myFunction** is not a function**

my js file is

 function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
    center : {
        lat : 34.149486,
        lng : -117.257317
    },
    zoom : 13
});
var geocoder = geocoder = new google.maps.Geocoder();

var card = document.getElementById('pac-card');
var input = document.getElementById('pac-input');
var types = document.getElementById('type-selector');
var strictBounds = document.getElementById('strict-bounds-selector');

map.controls[google.maps.ControlPosition.TOP_RIGHT].push(card);

var autocomplete = new google.maps.places.Autocomplete(input);

// Bind the map's bounds (viewport) property to the autocomplete object,
// so that the autocomplete requests use the current map bounds for the
// bounds option in the request.
autocomplete.bindTo('bounds', map);

var infowindow = new google.maps.InfoWindow();
var infowindowContent = document.getElementById('infowindow-content');
infowindow.setContent(infowindowContent);
var marker = new google.maps.Marker({
    position : {
        lat : 34.149486,
        lng : -117.257317
    },
    map : map,
    draggable : true,
    anchorPoint : new google.maps.Point(0, -29)
});

google.maps.event
        .addListener(
                marker,
                "dragend",
                function(e) {
                    var lat, lng, address;

                    geocoder
                            .geocode(
                                    {
                                        'latLng' : marker.getPosition()
                                    },
                                    function(results, status) {
                                        document
                                                .getElementById('pac-input').value = results[0].formatted_address;
                                        myfunction1()
                                    });
                });

autocomplete.addListener('place_changed', function() {
    infowindow.close();
    marker.setVisible(false);
    var place = autocomplete.getPlace();
    if (!place.geometry) {
        // User entered the name of a Place that was not suggested and
        // pressed the Enter key, or the Place Details request failed.
        window
                .alert("No details available for input: '" + place.name
                        + "'");
        return;
    }

    // If the place has a geometry, then present it on a map.
    if (place.geometry.viewport) {
        map.fitBounds(place.geometry.viewport);
    } else {
        map.setCenter(place.geometry.location);
        map.setZoom(17); // Why 17? Because it looks good.
    }
    marker.setPosition(place.geometry.location);
    marker.setVisible(true);

    var address = '';
    if (place.address_components) {
        address = [
                (place.address_components[0]
                        && place.address_components[0].short_name || ''),
                (place.address_components[1]
                        && place.address_components[1].short_name || ''),
                (place.address_components[2]
                        && place.address_components[2].short_name || '') ]
                .join(' ');
    }

    infowindowContent.children['place-icon'].src = place.icon;
    infowindowContent.children['place-name'].textContent = place.name;
    infowindowContent.children['place-address'].textContent = address;
    infowindow.open(map, marker);
});

// Sets a listener on a radio button to change the filter type on Places
// Autocomplete.
function setupClickListener(id, types) {
    var radioButton = document.getElementById(id);
    radioButton.addEventListener('click', function() {
        autocomplete.setTypes(types);
    });
}
    setupClickListener('changetype-address', [ 'address' ]);
  }
     function myfunction1() {
         window.myFunction();
     }

my java file is :

  package biz.kaar.service.client.shuttle;

  public class Trips extends MyPopup{

     Frame f = new Frame("js/location.html")

     public popupPanel(){
         super() ;
         exportMyFunction1() ;
         /* some other code line*/
      }
     //other methods.object of this class is created while loading

     public static native void exportMyFunction1() /*-{
      $wnd.myFunction =
             $entry(@biz.kaar.service.client.shuttle.Trips::myFunction());
     }-*/;

     public static void myFunction(){
         ErrorHandler.logInConsole("working");
        }

}

my location.html file

 <!DOCTYPE html>
 <html>
 <head>
  <title>Place Autocomplete</title>
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
   <meta charset="utf-8">
  </head>
  <body>
   <div class="pac-card" id="pac-card">
  <div>
    <div id="title">
      Autocomplete search
    </div>
    <div id="type-selector" class="pac-controls">

      <input type="radio" name="type" id="changetype-address" value="mykaarma">
      <label for="changetype-address">Addresses</label>

      <input type="radio" name="type" id="changetype-geocode">
      <label for="changetype-geocode">Geocodes</label>
    </div>

  </div>
  <div id="pac-container">
    <input id="pac-input" type="text"
        placeholder="Enter a location" value = "St Marys Rd Sydney NSW 2000 Australia">
  </div>
</div>
<div id="map"></div>
<div id="infowindow-content">
  <img src="" width="16" height="16" id="place-icon">
  <span id="place-name"  class="title"></span><br>
  <span id="place-address"></span>
</div>

<script src = "location.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places&callback=initMap"
    async defer></script>

Have i missed something in my code ?

Thanks.

2
  • Have you tried calling $wnd.myFunction(); instead of window.myFunction();? GWT's documentation uses the first version. Commented Apr 11, 2017 at 7:32
  • getting $wnd is not defined on using $wnd.myFunction() Commented Apr 11, 2017 at 17:25

1 Answer 1

1

Your JS code is inside an iframe (Frame widget), and your function is exported on the parent window, so it'd be window.parent.myFunction().

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.