How to add Google map for GWT into FormPanel - java

I am new to GWT and face some problem here. I need to show up Google map on a form in my GWT web.
First, there has a windowForm.class which extends FormPanel and I have wrote a mapWindowForm.class which extends this windowForm.class as below.
http://paste.ideaslabs.com/show/Q0ThysUrSF
And the problem is how shall I add this map "final MapWidget map = new MapWidget(Location, 2);" which is a MapWidget into this FormPanel: "mapWindowForm.class"
This system was developed by GWT-2.5.0. The library I have imported is gwt-maps-1.1.1.jar(Maps v2 API 1.1.1), so I give "2" as the second parameter in Maps.loadMapsApi(). Unfortunately, the first time to call mapWindowForm.class, the window.alert showed up, indicated that the Map.loadMapsApi() has not successed. But the second time to call this class, the window.alert didn't show up until I have refresh the web page. When I tried to give "3", it shows the sensor shall be given as true of false. When I tried to use gwt-maps-3.8.1(Maps v3 API), the import were not work.
I have tried some way to add this Map into frompanel as below
add(map);
LayoutContainer lc= new Layoutcontainer();
lc.add(map);
add(lc);
But both doesn't work, it just show a FormPanel with nothing on it.
I am not sure that is the MapWidget doesn't create or the MapWidget doesn't add into the FormPanel succeed
Thanks.
Hi Braj,
Thank you very much for your reply.
I have tried your suggestion in my code, but still face some problem.
mapWindowForm form = new mapWindowForm();
GoogleMap gmap = googleMap.create(form.getElement(), options);
But, I still don't how to add the gMap into my mapWindowForm.
Others form in this project would be code as below:(BaseWindow.java extends Window)
BaseWindow window = new BaseWindow(new mapWindowForm());
window.show();
And I have found this issue Example "Google Maps API v3 for GWT" Project for Eclipse.
As this issue claimed, I need to add <inherits name="com.google.maps.gwt.GoogleMaps" /> in my project.gwt.xml and a script to load map api. But some one also said cannot add script in gwt.xml.
So, I add inherits into gwt.xml and script into my project.html.
But I am bit of confuse, according to https://code.google.com/p/gwt-google-apis/wiki/MapsGettingStarted , it was import com.google.gwt.maps, but in this issue, it import com.google.maps.gwt, what's the different between them?
Thanks again.
I have tried below code(BaseWindow.java extends Window, windowForm.java extends FormPanel)
onClick(){
// MapOptions options = MapOptions.create() ;
// options.setCenter(LatLng.create( latCenter, lngCenter ));
// options.setZoom( 6 ) ;
// options.setMapTypeId( MapTypeId.ROADMAP );
// options.setDraggable(true);
// options.setMapTypeControl(true);
// options.setScaleControl(true) ;
// options.setScrollwheel(true) ;
windowForm panel = new mapWindowForm();
// GoogleMap gMap = GoogleMap.create( panel.getElement(), options ) ;
//BaseWindow(FormPanel formpanel, String ID, String title, int Height, int Weight)
BaseWindow window = new BaseWindow(panel,"Maps","This is Maps", 500, 650);
window.show();
}
This will show a form with title "This is Maps" and nothing in it.
But, when I unmark the toggle, the form will not be showed. Click the button will nothing happen. I am wonder is MapOptions doesn't work(API not load?) correct or some error because GWT container?
After created a new Google web application project and tried as below code:
public class Map implements EntryPoint {
public void onModuleLoad() {
FormPanel panel = new FormPanel();
panel.setWidth("100%");
panel.setHeight("100%");
MapOptions options = MapOptions.create();
options.setCenter(LatLng.create(23,-151));
options.setZoom(2);
options.setMapTypeId(MapTypeId.ROADMAP);
options.setDraggable(true);
options.setMapTypeControl(true);
options.setScaleControl(true);
options.setScrollwheel(true);
Button btn = new Button();
GoogleMap gMap = GoogleMap.create(panel.getElement(), options);
RootPanel.get().add(panel);
RootPanel.get().add(btn);
gMap.addIdleListener(new GoogleMap.IdleHandler() {
public void handle() {
Window.alert("Idle");
}
});
}
}
Also add gwt-map.3.8.1.jar into project and add configuration as below into Map.gwt.xml
<inherits name="com.google.maps.gwt.GoogleMaps" />
<script src="http://maps.google.com/maps/api/js?sensor=false" />
Compile success while with network connection.
But when run as web application, the url http://127.0.0.1:8888/Map.html?gwt.codesvr=127.0.0.1:9997 doesn't show up Google Map.
So, I have added a button, it has been showed. And add a idleListener, the Window.alert showed up, indicated that the map doesn't load.
On the other hand, in my project, add into gwt.xml still compile failed, because it doesn't support script tag, even with network connection. So, I have added script into home_page.html, but still failed to load the map. At the meantime, Window.alert also show up.
Connect to http://maps.google.com/maps/api/js?sensor=false in browser will get information as below
window.google = window.google || {};
google.maps = google.maps || {};
(function() {
function getScript(src) {
document.write('<' + 'script src="' + src + '"' +
' type="text/javascript"><' + '/script>');
}
var modules = google.maps.modules = {};
google.maps.__gjsload__ = function(name, text) {
modules[name] = text;
};
google.maps.Load = function(apiLoad) {
delete google.maps.Load;
apiLoad([0.009999999776482582,[[["http://mt0.googleapis.com/vt?lyrs=m#262000000\u0026src=api\u0026hl=zh-TW\u0026","http://mt1.googleapis.com/vt?lyrs=m#262000000\u0026src=api\u0026hl=zh-TW\u0026"],null,null,null,null,"m#262000000",["https://mts0.google.com/vt?lyrs=m#262000000\u0026src=api\u0026hl=zh-TW\u0026","https://mts1.google.com/vt?lyrs=m#262000000\u0026src=api\u0026hl=zh-TW\u0026"]],[["http://khm0.googleapis.com/kh?v=149\u0026hl=zh-TW\u0026","http://khm1.googleapis.com/kh?v=149\u0026hl=zh-TW\u0026"],null,null,null,1,"149",["https://khms0.google.com/kh?v=149\u0026hl=zh-TW\u0026","https://khms1.google.com/kh?v=149\u0026hl=zh-TW\u0026"]],[["http://mt0.googleapis.com/vt?lyrs=h#262000000\u0026src=api\u0026hl=zh-TW\u0026","http://mt1.googleapis.com/vt?lyrs=h#262000000\u0026src=api\u0026hl=zh-TW\u0026"],null,null,null,null,"h#262000000",["https://mts0.google.com/vt?lyrs=h#262000000\u0026src=api\u0026hl=zh-TW\u0026","https://mts1.google.com/vt?lyrs=h#262000000\u0026src=api\u0026hl=zh-TW\u0026"]],[["http://mt0.googleapis.com/vt?lyrs=t#132,r#262000000\u0026src=api\u0026hl=zh-TW\u0026","http://mt1.googleapis.com/vt?lyrs=t#132,r#262000000\u0026src=api\u0026hl=zh-TW\u0026"],null,null,null,null,"t#132,r#262000000",["https://mts0.google.com/vt?lyrs=t#132,r#262000000\u0026src=api\u0026hl=zh-TW\u0026","https://mts1.google.com/vt?lyrs=t#132,r#262000000\u0026src=api\u0026hl=zh-TW\u0026"]],null,null,[["http://cbk0.googleapis.com/cbk?","http://cbk1.googleapis.com/cbk?"]],[["http://khm0.googleapis.com/kh?v=84\u0026hl=zh-TW\u0026","http://khm1.googleapis.com/kh?v=84\u0026hl=zh-TW\u0026"],null,null,null,null,"84",["https://khms0.google.com/kh?v=84\u0026hl=zh-TW\u0026","https://khms1.google.com/kh?v=84\u0026hl=zh-TW\u0026"]],[["http://mt0.googleapis.com/mapslt?hl=zh-TW\u0026","http://mt1.googleapis.com/mapslt?hl=zh-TW\u0026"]],[["http://mt0.googleapis.com/mapslt/ft?hl=zh-TW\u0026","http://mt1.googleapis.com/mapslt/ft?hl=zh-TW\u0026"]],[["http://mt0.googleapis.com/vt?hl=zh-TW\u0026","http://mt1.googleapis.com/vt?hl=zh-TW\u0026"]],[["http://mt0.googleapis.com/mapslt/loom?hl=zh-TW\u0026","http://mt1.googleapis.com/mapslt/loom?hl=zh-TW\u0026"]],[["https://mts0.googleapis.com/mapslt?hl=zh-TW\u0026","https://mts1.googleapis.com/mapslt?hl=zh-TW\u0026"]],[["https://mts0.googleapis.com/mapslt/ft?hl=zh-TW\u0026","https://mts1.googleapis.com/mapslt/ft?hl=zh-TW\u0026"]],[["https://mts0.googleapis.com/mapslt/loom?hl=zh-TW\u0026","https://mts1.googleapis.com/mapslt/loom?hl=zh-TW\u0026"]]],["zh-TW","US",null,0,null,null,"http://maps.gstatic.com/mapfiles/","http://csi.gstatic.com","https://maps.googleapis.com","http://maps.googleapis.com"],["http://maps.gstatic.com/intl/zh_tw/mapfiles/api-3/16/11","3.16.11"],[662838505],1,null,null,null,null,0,"",null,null,0,"http://khm.googleapis.com/mz?v=149\u0026",null,"https://earthbuilder.googleapis.com","https://earthbuilder.googleapis.com",null,"http://mt.googleapis.com/vt/icon",[["http://mt0.googleapis.com/vt","http://mt1.googleapis.com/vt"],["https://mts0.googleapis.com/vt","https://mts1.googleapis.com/vt"],[null,[[0,"m",262000000]],[null,"zh-TW","US",null,18,null,null,null,null,null,null,[[47],[37,[["smartmaps"]]]]],0],[null,[[0,"m",262000000]],[null,"zh-TW","US",null,18,null,null,null,null,null,null,[[47],[37,[["smartmaps"]]]]],3],[null,[[0,"m",262000000]],[null,"zh-TW","US",null,18,null,null,null,null,null,null,[[50],[37,[["smartmaps"]]]]],0],[null,[[0,"m",262000000]],[null,"zh-TW","US",null,18,null,null,null,null,null,null,[[50],[37,[["smartmaps"]]]]],3],[null,[[4,"t",132],[0,"r",132000000]],[null,"zh-TW","US",null,18,null,null,null,null,null,null,[[5],[37,[["smartmaps"]]]]],0],[null,[[4,"t",132],[0,"r",132000000]],[null,"zh-TW","US",null,18,null,null,null,null,null,null,[[5],[37,[["smartmaps"]]]]],3],[null,null,[null,"zh-TW","US",null,18],0],[null,null,[null,"zh-TW","US",null,18],3],[null,null,[null,"zh-TW","US",null,18],6],[null,null,[null,"zh-TW","US",null,18],0],["https://mts0.google.com/vt","https://mts1.google.com/vt"],"/maps/vt"],2,500,["http://geo0.ggpht.com/cbk?cb_client=maps_sv.uv_api_demo","http://www.gstatic.com/landmark/tour","http://www.gstatic.com/landmark/config","/maps/preview/reveal?authuser=0","/maps/preview/log204","/gen204?tbm=map","http://static.panoramio.com.storage.googleapis.com/photos/"]], loadScriptTime);
};
var loadScriptTime = (new Date).getTime();
getScript("http://maps.gstatic.com/intl/zh_tw/mapfiles/api-3/16/11/main.js");
})();

How to add Google map for GWT into FormPanel?
Here is the code.
Simply call below line and the map is added in formPanel.
GoogleMap gMap = GoogleMap.create(formPanel.getElement(), options);
Some more configuration as defined below:
gwt.xml:
<inherits name="com.google.maps.gwt.GoogleMaps" />
<script src="http://maps.google.com/maps/api/js?sensor=false" />
gwt-maps.jar in build path of the project.
Sample code:
public void onModuleLoad() {
FormPanel formPanel = new FormPanel();
formPanel.setWidth("500px");
formPanel.setHeight("650px");
RootPanel.get().add(formPanel);
MapOptions options = MapOptions.create();
options.setZoom(6);
options.setMapTypeId(MapTypeId.ROADMAP);
options.setDraggable(true);
options.setMapTypeControl(true);
options.setScaleControl(true);
options.setScrollwheel(true);
GoogleMap gMap = GoogleMap.create(formPanel.getElement(), options);
gMap.setCenter(LatLng.create(58.378679, -2.197266));
}
screenshot:

I've been using the branflake API for quite some time, and currently it's working fine one GWT 2.8.
https://mvnrepository.com/artifact/com.github.branflake2267/gwt-maps-api
However, it's no longer maintained, some I'm shopping around for an alternative. In the meantime, I recommend it. The only downside being that it's using the 3.1 API version, which is obsolete. I'll post back if I find a way forward with it, or if I find an alternative.

Related

Getting more data during a Post request using Spring / Thymeleaf

I'm not really sure how to ask the question, but I'm going to try here.
I've got a list of actions that could happen to a subject. The user of my system needs to approve these actions and does so by selecting (checkboxes) these actions and then clicking the Approve button. Some of these action might require extra data, so a new page is presented to the user. The user enters that new data. Then the backend sends the whole package off to the endpoint for modification on the database. Once completed, it will reload the page they were just on.
So this is how I have it setup:
Approve button jumps to the following method:
#PostMapping("ApproveActions")
public RedirectView approveActions(ModelandView mav, #ModelAttribute("pendingActions") PendingActionsForm pendingActions) {
boolean needsDetails = false;
ActionForm actionForm = new ActionForm();
// parse through each of the actions
pendingActions.forEach(action -> {
// verify if the action has been selected by the user.
if (action.isSelected()) {
// if needsDetails hasn't been set to true,
if (!needsDetails) {
// check to see if it is one of the special actions that needs more info
needsDetails = ActionTypes.NeedsDetails(action.typeId());
}
// build the data for the endpoint
actionForm.addActionData(action);
}
});
if (needsDetails) {
// load the new page
rv.setUrl("/extraActionDetails");
return rv; // This is not right, but it does get me to the new page.
// get data
// return to this point with that new data
actionForm.setExtraDetails(???);
}
actionService.ApproveActions(actionForm);
RedirectView rv = new RedirectView();
rv.setUrl("/subjects/" + pendingActions.getSubjectId() + "#actions-pending");
return rv;
}
The problem I'm having is I don't know how to do that part with // load the new page get data and return to this point with that new data. I've got the extra-details.jsp page built out. And it's controller can be called. Does this question make sense? Are there any tutorials out there that address this situation?

Apply Deep linking in flutter app for android and ios

Apply Deep Linking in flutter app to open
a specific page in another app or same app
i want to know to how implement deep links in flutter
or open channel with android native and ios native ?
?
I think it would be the same as in a normal android app. Deeplinking is a configuration thing rather than code.
You need to write some things in your android manifest.
Have a look at the firebase manual for deep linking:
Firebase deeplinking manual
You can use firebase dynamic links for deep linking in a flutter. Refer this link for full implement steps and create and receive a link, https://medium.com/better-programming/deep-linking-in-flutter-with-firebase-dynamic-links-8a4b1981e1eb.
Here is a sample code for receiving a link inside the app and open a new screen.
class MainWidgetState extends State<MainWidget> {
#override
void initState() {
super.initState();
this.initDynamicLinks();
}
initDynamicLinks(BuildContext context) async {
await Future.delayed(Duration(seconds: 3));
var data = await FirebaseDynamicLinks.instance.getInitialLink();
var deepLink = data?.link;
final queryParams = deepLink.queryParameters;
if (queryParams.length > 0) {
var userName = queryParams['userId'];
openNewScreen(userName);
}
FirebaseDynamicLinks.instance.onLink(onSuccess: (dynamicLink)
async {
var deepLink = dynamicLink?.link;
final queryParams = deepLink.queryParameters;
if (queryParams.length > 0) {
var userName = queryParams['userId'];
openNewScreen(userName);
}
debugPrint('DynamicLinks onLink $deepLink');
}, onError: (e) async {
debugPrint('DynamicLinks onError $e');
});
}
openNewScreen(String userName){
Navigator.of(context).pushNamed("routeFormScreen", arguments: {"name": userName});
}
}

Using ICE PDF viewer pdf is not changed inside a jinternal frame

Am using icepdf to show pdf on my swing application. I have external buttons for pdf navigation. I need to navigate so many pdfs, but inside the same panel without closing.
My code for Icepdf:
public static void pdfviewerICE(currentpdfurl) {
filePath = currentpdfurl;
// build a controller
SwingController controller = new SwingController();
// Build a SwingViewFactory configured with the controller
SwingViewBuilder factory = new SwingViewBuilder(controller);
PropertiesManager properties = new PropertiesManager(
System.getProperties(),
ResourceBundle.getBundle(PropertiesManager.DEFAULT_MESSAGE_BUNDLE));
properties.set(PropertiesManager.PROPERTY_DEFAULT_ZOOM_LEVEL, "1.75");
JSplitPane jSplitPane_PDF = factory.buildUtilityAndDocumentSplitPane(true);
controller.openDocument(filePath);
if ((internalFrame.getComponents()!= null) || (internalFrame.isClosed())) {
internalFrame.add(jSplitPane_PDF);
internalFrame.show();
}
}
This is loading same pdf everytime.
Prasath Bala,
you have to make "controller" as public. Then call your controller when you pdf page is changed
Code:
controller.openDocument(currentpdfurl);
I too had the same issue, this will solve your query for sure.

Android Launcher3 - Google Now Page

I downloaded Launcher3 (Google's Kitkat Launcher) from 4.4 Sources.
I imported it into eclipse . I got rid of errors.And my launcher works pretty good.
But something missing. "GOOGLE NOW" page when you scroll to left.
I can't activate google now.Anyway i don't need that. I want to put my own fragment or layout into first page and other pages will work same like normal launcher.
Like a Google's experience Launcher(Kitkat Launcher of google)'s Google Now page ..
Like this :
I added my layout like this :
here is original codes from workspace.java
public long insertNewWorkspaceScreen(long screenId, int insertIndex) {
if (mWorkspaceScreens.containsKey(screenId)) {
throw new RuntimeException("Screen id " + screenId + " already exists!");
}
CellLayout newScreen = (CellLayout)
mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, null);
newScreen.setOnLongClickListener(mLongClickListener);
newScreen.setOnClickListener(mLauncher);
newScreen.setSoundEffectsEnabled(false);
mWorkspaceScreens.put(screenId, newScreen);
mScreenOrder.add(insertIndex, screenId);
addView(newScreen, insertIndex);
return screenId;
}
here is edited codes by me on workspace.java
public long insertNewWorkspaceScreen(long screenId, int insertIndex) {
if (mWorkspaceScreens.containsKey(screenId)) {
throw new RuntimeException("Screen id " + screenId + " already exists!");
}
if (screenId == 2) //Firstscreen/page
{
RelativeLayout newScreen = (RelativeLayout)
mLauncher.getLayoutInflater().inflate(R.layout.blinkfeed, null);
newScreen.setOnClickListener(mLongClickListener);
newScreen.setOnClickListener(mLauncher);
newScreen.setSoundEffectsEnabled(false);
// mWorkspaceScreens.put(screenId, newScreen);
mScreenOrder.add(insertIndex, screenId);
addView(newScreen, insertIndex);
return screenId;
}
else
{
CellLayout newScreen = (CellLayout)
mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, null);
newScreen.setOnLongClickListener(mLongClickListener);
newScreen.setOnClickListener(mLauncher);
newScreen.setSoundEffectsEnabled(false);
mWorkspaceScreens.put(screenId, newScreen);
mScreenOrder.add(insertIndex, screenId);
addView(newScreen, insertIndex);
return screenId;
}
}
as you can see when its first page i changed layout but i'm getting problems on childviews, animations etc,
anyway i cant even access other pages after that.
i putted everywhere try catch when i get errors because of "celllayout cannot bind to relative bla bla .."
my try catch like this
try
{
cell layout stuff its trying to make animations etc.
}
catch (Exception e)
{
//empty
}
i couldn't make it work at the moment like a google now pages :)
does anybody know about adding a fragment/layout into first page ?
Thanks.
If you want to add some fragment or view in the same manner as Google Now, the Launcher3 code supports that. You basically have 2 ways of getting the desired behavior:
Subclass the Launcher class and overwrite hasCustomContentToLeft() to return true and addCustomContentToLeft() where you can create/inflate your view to be added. Make sure you call addToCustomContentPage and implement the CustomContentCallbacks if you want to be notified when the screen is open.
Implement the same methods as described above in the Launcher class directly.
Hope this helps,
Mihai

Open url inside a grid in a new browser window

I have a list of urls in a grid, And I need that when a user click in a url a new browser windows open with the same url
I read some threads but in my case I believe my situation is a little different. In my controller
I'm using the following code
UrlListCollection.generateListUrl();
dataGrid.setRowRenderer(new RowRenderer() {
public void render(Row row, Object data) throws Exception {
UrlObj url = (UrlObj) data;
row.getChildren().add(new Label("Some data"));
row.getChildren().add(new Toolbarbutton(url.getUrlApp())); // url.getUrlApp() will be return a link like http://www.google.com
}
});
In my view(zul) I have
<grid id="dataGrid" width="100%">
<columns>
<column label="Some Data" sort="auto(FIELD_NAME)" width="200px" />
<column label="URL LINK" sort="auto(URL)" width="630px" />
</columns>
</grid>
But the common way to set an event an component in java can be:
Toolbarbutton button = new Toolbarbutton(url.getUrlApp()));
button.addEventListener(Events.ON_CLICK, new EventListener() {
public void onEvent(evt) {
// what I put here to open a Link in another web browser window ????
// and I need to be able to open every object value retrieved by url.getUrlApp() ???
}
});
I don't now what is necessary to make my code works..for me the way to apply a Event to toolbar button inside a grid that use RowRenderer method is strange. I can't see a solution by myself.
You can use the following example,
Executions.getCurrent().sendRedirect("http://www.google.com", "_blank");
Or you may use the A component with the setHref() method instead of the Toolbarbutton component.
This works fine for me, thanks!
UrlObj url = (UrlObj) data;
Toolbarbutton tb = new Toolbarbutton(url.getUrlApp());
tb.setHref(url.getUrlApp());
tb.setTarget("_blank");
row.getChildren().add(new Label("Some data"));
row.getChildren().add(tb);

Categories