GWT MAP 3.8 (Google API) - Is onResize() needed to hide the "grey background"? - gwt

My problem:
- I display a map inside a popup and I have unloaded tiles (grey background).
- If I zoom out or in, then the map will fill the entire space (no grey background anymore).
My question:
- Have you any idea about my problem (Should I need to resize to hide the "grey background") ?
- I do not know if I should call onResize() inside the Runnable callback (code is above) or not ?
Thanks you,
My actual code: (I am using the javaxLoaderAPI)
// ENTRY POINT
GoogleMap map;
#UiField LayoutPanel gmap;
public void AjaxLoader_MAP() {
AjaxLoaderOptions options = AjaxLoaderOptions.newInstance();
options.setOtherParms("key=***&sensor=false&language=es");
Runnable callback = new Runnable() {
public void run() {
gmap.onResize(); // Should I call onResize() here ?
map = GoogleMap.create(gmap.getElement());
};
}
AjaxLoader.loadApi("maps", "3", callback, options);
}

May be related to the following post - GWT Google Map Api V3 - broken when changing it
I just posted an answer to that unanswered post as well. I believe it answers and sheds insight on this one as well.
I know this is an old post, but let me know if helps!

When calling mapWidget.triggerResize(), it's important to call it with some delay (Timer.schedule()) so that all the widget have been reset and then the map is resized.
This is how I trigger it:
#Override
protected void onReset() {
super.onReset();
Timer timer = new Timer() {
#Override
public void run() {
triggerResize();
}
};
timer.schedule(100);
}
Without timer, I was still getting grey tiles. Hope someone still finds it useful.

Related

I wanna display a TextView after say couple of seconds. No idea how to do it

new to android and I don't know how to display a View after some time. I don't want codes, just want some guidance or resources so I can learn. Already googled it in vain.
You should use handler to post in UI thread . Then set time using postDelayed method of Handler class .
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
//Set the text in your textview here
}
}, TIME_IN_MILLISECONDS);

How to refresh Grid GWT after getting data from database_Now it keeps the Gird in the First call

I am new with GWT_GXT
I use MVP(model-view-Presenter)
In Presenter, i call RPC to get data From database. After that i get a List data -> I set it for view
In view, code is below
#Override
public void setDeleteAllTest(List<DeleteAllTestModel> deleteAllTests) {
final ListStore<DeleteAllTestModel> listStore = new ListStore<DeleteAllTestModel>();
listStore.add(deleteAllTests);
gridView = new PMTGridDeleteAllTest<DeleteAllTestModel>().getPMTGridDeleteAllTest(listStore);
gridView.setAutoWidth(true);
}
#Override
protected void onRender(Element parent, int pos) {
super.onRender(parent, pos);
ContentPanel cp = new ContentPanel();
cp.setBodyBorder(false);
cp.setHeading("");
cp.setButtonAlign(Style.HorizontalAlignment.CENTER.CENTER);
cp.setLayout(new FitLayout());
cp.setSize(1200, 400);
cp.add(gridView);
verticalPanel.add(cp);
verticalPanel.add(nameField);
verticalPanel.add(cancelButton);
add(verticalPanel);
cancelButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
#Override
public void componentSelected(ButtonEvent buttonEvent) {
PolicyDeleteAllTestDialog.this.hide();
}
});
getButtonById("ok").hide();
}
The Problem is that Gird is not refresh and update new data_ It only displays (the first Grid in the first Call) .. It always keep the first View( I use dialog to show grid)..
Help me!
Thanks
I don't exactly remember how it works and it really is what you need. But there is something like gridView.refresh();. I remember I sometime used to use grid.getView().refresh(true); but it's been a while. Also I think there is a concept named ListLoader that might be useful. I am not sure of myself but if I were you I would have a look at listLoader. I hope this will help you one way or another, sorry if it does not.

GWT: How to dynamically load a new image?

I want to fetch an image from a remote server (not my app's server, but I don't think that matters) and display it in an existing Image widget. The existing widget displays its original content, from a ClientBundle ImageResource , OK.
In UiBinder template:
<g:Image ui:field='myImage' resource='{res.anImage}'/>
In code:
#UiField Image myImage;
...
int width = Window.getClientWidth();
int height = Window.getClientHeight();
String url = ...;
myImage.addErrorHandler(new ErrorHandler() {
public void onError(ErrorEvent event) {
Window.alert("Error getting image data: " + event);
}
});
myImage.addLoadHandler(new LoadHandler() {
public void onLoad(LoadEvent event) {
Window.alert("LoadEvent: " + event);
}
});
myImage.setUrlAndVisibleRect(url, 0, 0, width, height);
As far as I can tell setUrlAndVisibleRect is a no-op. FireBug reports no network activity -- no request to the server specified by the URL. What am I overlooking? In my extended thrashing about trying to get this working I have inferred that it may have something to do with myImage not being "logically attached", but I'm not entirely sure what that means and I've no idea how to correct it if that is the problem.
EDIT with SUMMARY of SOLUTION:
My initial hunch was right. Because I had chosen to implement the image code within a second pseudo-widget (...extends Composite) that shared my UiBinder template with the main pseudo-widget that implements most of my app's UI, I got into trouble. I neglected to add this second pseudo-widget to the RootPanel as is normally done in the class that implements EntryPoint. This left my Image widget unattached to the widget chain, because its parent, the second pseudo-widget, was unattached. And an Image widget must be attached to work. What I ended up doing is moving the Image code back into my main app/GUI class, i.e., into the first and now only pseudo-widget and abandoning the special class for the Image code. I did that because it's simpler and the Image code turns out not to be as long as I had originally thought.
Adding image to the DOM is little tricky,the below code which supports all the browsers(setVisibility trick added to support IE also,as It has a different way to image rendering).
I did'nt use setUrlAndVisibleRect before and AFAIK,Image must render to the DOM inorder to resize it.Just try the below codes.
image.addLoadHandler(new LoadHandler() {
#Override
public void onLoad(LoadEvent event) {
//Do your operations on image .//resize ..etc
image.getElement().getStyle().setVisibility
(Style.Visibility.Visible);
}
});
image.getElement().getStyle().setVisibility(Style.Visibility.HIDDEN);
RootPanel.get().add(image);
image.setUrl(url);
You are using ClientBundle ImageResource which is compile time. You cannot change it unless you replace the new image with exact name in the exact position of prev one. One of the possible hack which is possible is, place the image in a div with its ID set ( getElement().setId("your ID") ). Once you get you new image you use RootPanel.get("Your Id") and do your job.

second call of google maps does not show the map in correct size

using gwt-maps-3.8.0 i display a route in a gwt popup. Works when called once but does not work on second call.
What should i do ... some advice to refresh the mapWidget?
When you display the map, trigger its resize event.
From the documentation:
Developers should trigger this event on the map when the div changes size: google.maps.event.trigger(map, 'resize')
It appears the way to do this in GWT is
Event.trigger(mapWidget.getMap(), "resize");
At the moment, the map has zero size as far as the API is concerned, so it's just displaying the buffer of tiles around the single pixel at (0,0). Triggering the resize event causes the API to get the correct size from the browser so the right tiles are fetched for display.
I had the same issue (map shown in a popup; reload the popup and the map was no longer centered).
In the end I managed to fix my problem using the triggerResize method from the GoogleMap class. However it worked only after I triggered this method from an Idle event.
triggerResize will notify the map to show the correct tiles.
setCenter will make sure the map is centered once again.
gMap.addIdleListenerOnce(new IdleHandler() {
#Override
public void handle() {
gMap.triggerResize();
gMap.setCenter(myLatLng);
}
});
Using the GWT-V3-Maps-API it would be done as follows for a case where a div or window resizes:
/*
* Example of how to dynamically resize the map to fit the window - add
* your events
*/
Window.addResizeHandler(new ResizeHandler() {
#Override
public void onResize(ResizeEvent event) {
MapHandlerRegistration.trigger(mapWidget, MapEventType.RESIZE);
GWT.log("Window has been resized!");
}
});
mapWidget.addResizeHandler(new ResizeMapHandler() {
#Override
public void onEvent(ResizeMapEvent event) {
GWT.log("Map has been resized!");
}
});

How can I get the height of a GWT CellTable after it's done rendering?

I am familar with getOffsetHeight and getElement.getClientHeight. The problem is I can't find when to call these methods to get the rendered height of my CellTable. I've tried adding an attach handler, row change handler, and overriding setRowData. I'm basically shooting around in the dark and wondering if any GWT experts can help me find out when to call those methods to get the correct height.
I'm trying to put the CellTable in a G-mail contextual gadget then change the height of the gadget using the dynamic height feature, FYI.
I had a similar issue with a CellList. I managed to solve it listening for load state changes. Basically this code is called every time the list/table is updated:
taskList.addLoadingStateChangeHandler(new LoadingStateChangeEvent.Handler() {
#Override
public void onLoadingStateChanged(LoadingStateChangeEvent event) {
if(event.getLoadingState() == LoadingState.LOADED) {
//Calculate height here
}
}
});
Hope this helps.
You can try to use the scheduleDeferred:
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
public void execute() {
//calculate height
}
});