/** initialize map widget using gwt-openlayers */ void initMapGwtOl() { MapOptions defaultMapOptions = new MapOptions(); defaultMapOptions.setNumZoomLevels(16); // // defaultMapOptions.setProjection("EPSG:4326"); defaultMapOptions.setMaxExtent(new Bounds(-180, -90, 180, 90)); defaultMapOptions.setRestrictedExtent(new Bounds(-180, -90, 180, 90)); defaultMapOptions.setUnits("degrees"); mapWidget = new MapWidget("500px", "500px", defaultMapOptions); /*GoogleV3Options gNormalOptions = new GoogleV3Options(); gNormalOptions.setIsBaseLayer(true); gNormalOptions.setType(GoogleV3MapType.G_NORMAL_MAP); GoogleV3 gNormal = new GoogleV3("Google Normal", gNormalOptions);*/ // Create a WMS layer as base layer WMSParams wmsParams = new WMSParams(); wmsParams.setFormat("image/png"); wmsParams.setLayers("basic"); wmsParams.setStyles(""); WMSOptions wmsLayerParams = new WMSOptions(); wmsLayerParams.setUntiled(); wmsLayerParams.setTransitionEffect(TransitionEffect.RESIZE); String wmsUrl = EUOSMEGWT.wmsEndpoint; WMS wmsLayer = new WMS("Basic WMS", wmsUrl, wmsParams, wmsLayerParams); // Add the WMS to the map final Map map = mapWidget.getMap(); // map.addLayer(gNormal); map.addLayer(wmsLayer); /*OSM osm_1 = OSM.Mapnik("Mapnik"); OSM osm_2 = OSM.CycleMap("CycleMap"); osm_1.setIsBaseLayer(true); osm_2.setIsBaseLayer(true); map.addLayer(osm_1); map.addLayer(osm_2);*/ // Lets add some default controls to the map map.addControl( new LayerSwitcher()); // + sign in the upperright corner to display the layer switcher map.addControl(new ScaleLine()); // Display the scaleline map.addControl(new MousePosition()); // Center and zoom to a location LonLat lonLat = new LonLat(6.95, 50.94); lonLat.transform( DEFAULT_PROJECTION.getProjectionCode(), map.getProjection()); // transform lonlat to OSM coordinate system map.setCenter(lonLat, 3); /*map.addMapClickListener(new MapClickListener() { public void onClick(MapClickListener.MapClickEvent mapClickEvent) { LonLat lonLat = mapClickEvent.getLonLat(); lonLat.transform(map.getProjection(), DEFAULT_PROJECTION.getProjectionCode()); //transform lonlat to more readable format Window.alert("LonLat = (" + lonLat.lon() + " ; " + lonLat.lat() + ")"); } });*/ FeatureAddedListener listener = new FeatureAddedListener() { public void onFeatureAdded(VectorFeature vf) { Polygon aoi = Polygon.narrowToPolygon(vf.getGeometry().getJSObject()); LinearRing[] rings = aoi.getComponents(); if (rings != null) { rings[0].getComponents(); } Geometry geo = vf.getGeometry(); // Window.alert("Feature of class " + geo.getClassName() + " added with bounds " + // geo.getBounds().toString()); double north = Math.floor(geo.getBounds().getUpperRightY() * 100000) / 100000; double east = Math.floor(geo.getBounds().getUpperRightX() * 100000) / 100000; double south = Math.floor(geo.getBounds().getLowerLeftY() * 100000) / 100000; double west = Math.floor(geo.getBounds().getLowerLeftX() * 100000) / 100000; geoBoundsObj.newTextBoxNorth.setValue("" + north); geoBoundsObj.newTextBoxEast.setValue("" + east); geoBoundsObj.newTextBoxSouth.setValue("" + south); geoBoundsObj.newTextBoxWest.setValue("" + west); map.zoomToExtent(geo.getBounds()); } }; Vector boxLayer = new Vector("Box Layer"); DrawFeatureOptions drawRegularPolygonFeatureOptions = new DrawFeatureOptions(); drawRegularPolygonFeatureOptions.onFeatureAdded(listener); RegularPolygonHandlerOptions regularPolygonHandlerOptions = new RegularPolygonHandlerOptions(); regularPolygonHandlerOptions.setSides(4); regularPolygonHandlerOptions.setIrregular(true); regularPolygonHandlerOptions.setPersist(true); drawRegularPolygonFeatureOptions.setHandlerOptions(regularPolygonHandlerOptions); final DrawFeature drawRegularPolygon = new DrawFeature(boxLayer, new RegularPolygonHandler(), drawRegularPolygonFeatureOptions); map.addControl(drawRegularPolygon); drawRegularPolygon.activate(); }
@Override public void buildPanel() { // create some MapOptions MapOptions defaultMapOptions = new MapOptions(); defaultMapOptions.setNumZoomLevels(16); // create a MapWidget MapWidget mapWidget = new MapWidget("500px", "500px", defaultMapOptions); contentPanel.add(new HTML("<p>This example shows the use of the click handler.</p>")); contentPanel.add( new InfoPanel( "<p>Don't forget to add the following line to your HTML if you want to use Google V3. :</p>" + "<p><b><script src=\"http://maps.google.com/maps/api/js?v=3&sensor=false\"></script></b></p>")); HorizontalPanel horizontalPanel = new HorizontalPanel(); horizontalPanel.setSize("800px", "500px"); outputPanel.setSize("300px", "475px"); horizontalPanel.add(mapWidget); VerticalPanel eventConsole = new VerticalPanel(); listBox.setSize("300px", "25px"); eventConsole.add(listBox); eventConsole.add(this.outputPanel); horizontalPanel.add(eventConsole); contentPanel.add(horizontalPanel); // create some Google Layers GoogleV3Options gNormalOptions = new GoogleV3Options(); gNormalOptions.setIsBaseLayer(true); gNormalOptions.setType(GoogleV3MapType.G_NORMAL_MAP); GoogleV3 gNormal = new GoogleV3("Google Normal", gNormalOptions); // and add them to the map final Map map = mapWidget.getMap(); map.addLayer(gNormal); // lets add some default controls to the map map.addControl( new LayerSwitcher()); // + sign in the upperright corner to display the layer switcher map.addControl(new OverviewMap()); // + sign in the lowerright to display the overviewmap map.addControl(new ScaleLine()); // Display the scaleline final String singleKey = "single"; ClickControl singleClickControl = new ClickControl(this.createClickHandlerOptions(true, false, false, false, 0, singleKey)); map.addControl(singleClickControl); this.clickControls.put(singleKey, singleClickControl); listBox.addItem("single only", singleKey); final String doubleKey = "double"; ClickControl doubleClickControl = new ClickControl(this.createClickHandlerOptions(false, true, false, false, 0, doubleKey)); map.addControl(doubleClickControl); this.clickControls.put(doubleKey, doubleClickControl); this.listBox.addItem("double only", doubleKey); final String bothKey = "both"; ClickControl bothClickControl = new ClickControl(this.createClickHandlerOptions(true, true, false, false, 0, bothKey)); map.addControl(bothClickControl); this.clickControls.put(bothKey, bothClickControl); this.listBox.addItem("both", bothKey); final int tolerance = 200; final String dragKey = "drag"; ClickControl dragClickControl = new ClickControl( this.createClickHandlerOptions(true, false, false, false, tolerance, dragKey)); map.addControl(dragClickControl); this.clickControls.put(dragKey, dragClickControl); this.listBox.addItem("drag ( tolerance: " + tolerance + " )", dragKey); final String singleStopKey = "singlestop"; ClickControl singleStopClickControl = new ClickControl( this.createClickHandlerOptions(true, false, true, false, 0, singleStopKey)); map.addControl(singleStopClickControl); this.clickControls.put(singleStopKey, singleStopClickControl); listBox.addItem("single with stop", singleStopKey); final String doubleStopKey = "doublestop"; ClickControl doubleStopClickControl = new ClickControl( this.createClickHandlerOptions(false, true, false, true, 0, doubleStopKey)); map.addControl(doubleStopClickControl); this.clickControls.put(doubleStopKey, doubleStopClickControl); this.listBox.addItem("double with stop", doubleStopKey); final String bothStopKey = "bothstop"; ClickControl bothStopClickControl = new ClickControl(this.createClickHandlerOptions(true, true, true, true, 0, bothStopKey)); map.addControl(bothStopClickControl); this.clickControls.put(bothStopKey, bothStopClickControl); this.listBox.addItem("both with stop", bothStopKey); // center and zoom to a location LonLat lonLat = new LonLat(13.4, 52.51); lonLat.transform( DEFAULT_PROJECTION.getProjectionCode(), map.getProjection()); // transform lonlat to OSM coordinate system map.setCenter(lonLat, 12); initWidget(contentPanel); mapWidget .getElement() .getFirstChildElement() .getStyle() .setZIndex(0); // force the map to fall behind popups this.listBox.addChangeHandler( new ChangeHandler() { @Override public void onChange(ChangeEvent event) { activateControl(); } }); this.activateControl(); }
@Override public void buildPanel() { // create some MapOptions MapOptions defaultMapOptions = new MapOptions(); defaultMapOptions.setNumZoomLevels(16); // create a MapWidget MapWidget mapWidget = new MapWidget("500px", "500px", defaultMapOptions); contentPanel.add(new HTML( "<p>This example shows the use of the handler with a key mask.</p>" + "<p>" + "<li>Choose the keys you want to check with the checkboxes.</li>" + "<li>Press an hold the buttons you have choosen and click in the map.</li>")); contentPanel.add( new InfoPanel( "<p>Don't forget to add the following line to your HTML if you want to use Google V3. :</p>" + "<p><b><script src=\"http://maps.google.com/maps/api/js?v=3&sensor=false\"></script></b></p>")); HorizontalPanel keyChooserPanel = new HorizontalPanel(); this.keyAltCheckBox = new CheckBox("Alt"); this.keyShiftCheckBox = new CheckBox("Shift"); keyChooserPanel.add(this.keyAltCheckBox); keyChooserPanel.add(this.keyShiftCheckBox); ValueChangeHandler<Boolean> changeHandler = new ValueChangeHandler<Boolean>() { @Override public void onValueChange(ValueChangeEvent<Boolean> event) { int keyCodes = Handler.MOD_NONE; if(keyAltCheckBox.getValue()) { keyCodes |= Handler.MOD_ALT; } if(keyShiftCheckBox.getValue()) { keyCodes |= Handler.MOD_SHIFT; } keyMaskControl.setKeyMask(keyCodes); } }; this.keyShiftCheckBox.addValueChangeHandler(changeHandler); this.keyAltCheckBox.addValueChangeHandler(changeHandler); this.keyShiftCheckBox.addValueChangeHandler(changeHandler); contentPanel.add(mapWidget); contentPanel.add(keyChooserPanel); // create some Google Layers GoogleV3Options gNormalOptions = new GoogleV3Options(); gNormalOptions.setIsBaseLayer(true); gNormalOptions.setType(GoogleV3MapType.G_NORMAL_MAP); GoogleV3 gNormal = new GoogleV3("Google Normal", gNormalOptions); // and add them to the map final Map map = mapWidget.getMap(); map.addLayer(gNormal); // lets add some default controls to the map map.addControl(new LayerSwitcher()); //+ sign in the upperright corner to display the layer switcher map.addControl(new OverviewMap()); //+ sign in the lowerright to display the overviewmap map.addControl(new ScaleLine()); //Display the scaleline map.addControl(keyMaskControl); keyMaskControl.activate(); // center and zoom to a location LonLat lonLat = new LonLat(13.4, 52.51); lonLat.transform(DEFAULT_PROJECTION.getProjectionCode(), map.getProjection()); //transform lonlat to OSM coordinate system map.setCenter(lonLat, 12); initWidget(contentPanel); mapWidget.getElement().getFirstChildElement().getStyle().setZIndex(0); //force the map to fall behind popups }