Hi,
I have the below code which shows teo different kml overlays by
pressing the respective button but only the first kml overly is shown
on the map the other is not being shown can you help me please ?
package com.myfirstgooglemapdesigner.MyFirstGoogleMapDesigner.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.maps.client.MapWidget;
import com.google.gwt.maps.client.Maps;
import com.google.gwt.maps.client.control.LargeMapControl;
import com.google.gwt.maps.client.control.MapTypeControl;
import com.google.gwt.maps.client.geom.LatLng;
import com.google.gwt.maps.client.overlay.GeoXmlLoadCallback;
import com.google.gwt.maps.client.overlay.GeoXmlOverlay;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class MyFirstGoogleMapDesigner implements EntryPoint {
private VerticalPanel verticalPanel;
private RootPanel rootPanel;
public MapWidget map;
private GeoXmlOverlay geoXml = null;
private GeoXmlOverlay geoXml1 = null;
private boolean geoXmlShown = false;
private boolean geoXmlShown1 = false;
private Button Show_Scenic;
private Button Show_City_Route;
public void onModuleLoad() {
Maps.loadMapsApi("","2",false,new Runnable() {
public void run() {
LatLng South = LatLng.newInstance(35.87542, 14.50968);
map = new MapWidget(South, 13);
map.setCenter(South);
map.setSize("600px", "700px");
map.addControl(new LargeMapControl());
map.addControl(new MapTypeControl());
map.setDraggable(true);
map.setScrollWheelZoomEnabled(true);
verticalPanel.add(map);
if (!Maps.isLoaded()) {
Window.alert("The Maps API is not installed."
+ " The <script> tag that loads the Maps API may be
missing or your Maps key may be wrong.");
return;
}
if (!Maps.isBrowserCompatible()) {
Window.alert("The Maps API is not compatible with this
browser.");
return;
}
if (Maps.isLoaded()){
Window.alert("Grat, Google Maps are loaded !");
}
}
});
rootPanel = RootPanel.get();
rootPanel.setSize("1200px", "900px");
verticalPanel = new VerticalPanel();
verticalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
verticalPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
rootPanel.add(verticalPanel, 10, 53);
verticalPanel.setSize("600px", "757px");
HorizontalPanel horizontalPanel = new HorizontalPanel();
rootPanel.add(horizontalPanel, 616, 53);
horizontalPanel.setSize("279px", "53px");
DecoratorPanel decoratorPanel = new DecoratorPanel();
horizontalPanel.add(decoratorPanel);
horizontalPanel.setCellVerticalAlignment(decoratorPanel,
HasVerticalAlignment.ALIGN_MIDDLE);
DecoratorPanel decoratorPanel_1 = new DecoratorPanel();
rootPanel.add(decoratorPanel_1, 10, 10);
decoratorPanel_1.setSize("269px", "37px");
Label MapTitle = new Label("My First Google Map");
decoratorPanel_1.setWidget(MapTitle);
MapTitle.setWidth("259px");
MapTitle.setStyleName("MapTitle");
MapTitle.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
MapTitle.setStylePrimaryName("MapTitle");
HorizontalPanel horizontalPanel_1 = new HorizontalPanel();
rootPanel.add(horizontalPanel_1, 616, 112);
horizontalPanel_1.setSize("279px", "53px");
DecoratorPanel decoratorPanel_2 = new DecoratorPanel();
horizontalPanel_1.add(decoratorPanel_2);
//City Route Button
Show_City_Route = new Button("Show City Route");
Show_City_Route.setEnabled(false);
Show_City_Route.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
//To do code here for the city tour button
toggleOverlay1();
}
});
decoratorPanel_2.setWidget(Show_City_Route);
//End City Route Button
//Scenic Route Button
Show_Scenic = new Button("Add/Remove Scenic");
Show_Scenic.setText("Add Scenic Route");
Show_Scenic.setEnabled(false);
Show_Scenic.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
//To do code here for the scenic button
toggleOverlay();
}
});
decoratorPanel.setWidget(Show_Scenic);
//End Scenic Route Button
//GeoXmlOverlay for the City Route.
GeoXmlOverlay.load("URL_ADDRESS2", new GeoXmlLoadCallback(){
@Override
public void onFailure(String url, Throwable e1){
StringBuffer message1 = new StringBuffer("KML File " +
url + " failed to load");
if(e1 != null){
message1.append(e1.toString());
}
Window.alert("Retrieving data for the overlay caused
the following error:\n\n" + e1.getMessage());
Window.alert(message1.toString());
}
@Override
public void onSuccess(String url, GeoXmlOverlay overlay){
if (geoXml1 != null){
return;
}
geoXml1 = overlay;
Show_City_Route.setEnabled(true);
GWT.log("KML File " + url + "loaded successfully",
null);
GWT.log("Default Center =" +
geoXml1.getDefaultCenter(), null);
GWT.log("Default Span =" + geoXml1.getDefaultSpan(),
null);
GWT.log("Default Bounds =" +
geoXml1.getDefaultBounds(), null);
GWT.log("Supports hide =" + geoXml1.supportsHide(),
null);
GWT.log("Is Hidden =" + geoXml1.isHidden(), null);
}
});
//End GeoXmlOverlay for the City Route.
//GeoXmlOverlay for the Scenic Route.
GeoXmlOverlay.load("URL_ADDRESS1", new GeoXmlLoadCallback() {
@Override
public void onFailure (String url, Throwable e){
StringBuffer message = new StringBuffer("KML File " + url
+ " Failed to load");
if (e != null){
message.append(e.toString());
}
Window.alert("Retrieving data for the overlay caused the
following error:\n\n" + e.getMessage());
Window.alert(message.toString());
}
@Override
public void onSuccess(String url, GeoXmlOverlay overlay){
if(geoXml != null){
return;
}
geoXml = overlay;
Show_Scenic.setEnabled(true);
GWT.log("KML File " + url + "loaded successfully", null);
GWT.log("Default Center =" + geoXml.getDefaultCenter(),
null);
GWT.log("Default Span =" + geoXml.getDefaultSpan(), null);
GWT.log("Default Bounds =" + geoXml.getDefaultBounds(),
null);
GWT.log("Supports hide =" + geoXml.supportsHide(), null);
GWT.log("Is hidden =" + geoXml.isHidden(), null);
//geoXml.gotoDefaultViewport(map);
}
});
}
//End GeoXmlOverlay for the Scenic Route.
public void onShow(){
map.clearOverlays();
if(geoXmlShown == false){
toggleOverlay();
}
if(geoXmlShown1 == false){
toggleOverlay1();
}
}
public void toggleOverlay(){
if (geoXml == null){
return;
}
if (geoXmlShown){
Show_Scenic.setText("Add Scenic Route");
map.removeOverlay(geoXml);
geoXmlShown = false;
}
else{
Show_Scenic.setText("Remove Scenic Route");
map.addOverlay(geoXml);
geoXmlShown = true;
}
}
public void toggleOverlay1(){
if (geoXml1 == null){
return;
}
if (geoXmlShown1){
Show_City_Route.setText("Add City Route");
map.removeOverlay(geoXml1);
geoXmlShown1 = false;
}
else{
Show_City_Route.setText("Remove City Route");
map.addOverlay(geoXml1);
geoXmlShown1 = true;
}
}
}
thanks
ronald
--
You received this message because you are subscribed to the Google Groups
"Google Maps API V2" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api?hl=en.