Unfortunately, when I upgraded the GWT to version 2.4, it didn't display the image.
It works fine with web page but not image.
So I searched in Google, but there is no one having problem like I did.
Since the static map is an image, so I decided to use image object in GWT and it can be loaded from URL. That's nice and easy solution for me.
Here is the new code :
package com.vcari.jscadav2.client;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.Image;
public class SiteMapStaticMapPanel extends SiteMapPanel {
public SiteMapStaticMapPanel(){
super();
}
Frame frame = new Frame("http://google.com");
final Image image = new Image();
@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
//setLayout(new FitLayout());
setBorders(false);
image.setWidth("640");
image.setHeight("430");
image.setVisible(true);
add(image);
}
/**
* Set map center to the defined latitude and longitude
* @param latitude
* @param longitude
*/
public void setMapCenter(Double latitude, Double longitude, int zoomLevel) {
Integer width=this.getWidth();
Integer height=this.getHeight();
String url="http://maps.google.com/maps/api/staticmap?center={0},{1}&zoom={2}&size={3}x{4}&maptype=roadmap&sensor=false";
url+="&markers=color:red7C%{0},{1}";
//url=String.format(url, latitude,longitude,zoomLevel,width,height);
url=url.replace("{0}", latitude.toString());
url=url.replace("{1}", longitude.toString());
url=url.replace("{2}", String.valueOf(zoomLevel));
url=url.replace("{3}", width.toString());
url=url.replace("{4}", height.toString());
url=url.replace("{5}", Application.areaName);
image.setUrl(url);
}
}
0 comments:
Post a Comment