@Override
 public void cleanFeatureInfoCache() {
   for (IGPFeatureInfoElement featureInfoElement :
       GeoPlatformUtils.safeCollection(FeatureInfoFlyWeight.getInstance().getCollection())) {
     map.removeControl(featureInfoElement.getElementControl());
     featureInfoElement.getElementControl().deactivate();
   }
   FeatureInfoFlyWeight.getInstance().cleanCache();
 }
 @Override
 public void deactivateFeatureInfoControl() {
   for (IGPFeatureInfoElement featureInfoElement :
       GeoPlatformUtils.safeCollection(FeatureInfoFlyWeight.getInstance().getCollection())) {
     map.removeControl(featureInfoElement.getElementControl());
     featureInfoElement.getElementControl().deactivate();
   }
   this.activated = Boolean.FALSE;
 }
  @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>&lt;script src=\"http://maps.google.com/maps/api/js?v=3&amp;sensor=false\"&gt;&lt;/script&gt;</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() {
    OpenLayers.setProxyHost("olproxy?targetURL=");

    // create some MapOptions
    MapOptions defaultMapOptions = new MapOptions();
    defaultMapOptions.setDisplayProjection(
        new Projection(
            "EPSG:4326")); // causes the mouse popup to display coordinates in this format
    defaultMapOptions.setNumZoomLevels(16);

    // Create a MapWidget
    MapWidget mapWidget = new MapWidget("500px", "500px", defaultMapOptions);
    // 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 = "http://labs.metacarta.com/wms/vmap0";

    WMS wmsLayer = new WMS("Basic WMS", wmsUrl, wmsParams, wmsLayerParams);

    // Add the WMS to the map
    Map map = mapWidget.getMap();
    map.addLayer(wmsLayer);

    // Adds the custom mouse position to the map
    MousePositionOutput mpOut =
        new MousePositionOutput() {
          @Override
          public String format(LonLat lonLat, Map map) {
            String out = "";
            out += "<b>This is the longitude </b> ";
            out += lonLat.lon();
            out += "<b>, and this the latitude</b> ";
            out += lonLat.lat();

            return out;
          }
        };

    MousePositionOptions mpOptions = new MousePositionOptions();
    mpOptions.setFormatOutput(mpOut); // rename to setFormatOutput

    map.addControl(new MousePosition(mpOptions));

    // 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

    // Center and zoom to a location
    map.setCenter(new LonLat(146.7, -41.8), 6);

    contentPanel.add(
        new HTML("<p>This example shows how to add a custom mouse position to the map..</p>"));
    contentPanel.add(mapWidget);

    initWidget(contentPanel);

    mapWidget
        .getElement()
        .getFirstChildElement()
        .getStyle()
        .setZIndex(0); // force the map to fall behind popups
  }
 /**
  * Use this method to merge ... with the map or use setMapDomElementId to create a new map in that
  * dom element.
  *
  * @param map - the map to merge map elements with that are created on the basis of the WMC
  *     document
  */
 public void setMap(Map map) {
   getJSObject().setProperty("map", map.getJSObject());
 }
  @Override
  public void buildPanel() {
    OpenLayers.setProxyHost("olproxy?targetURL=");

    // create some MapOptions
    MapOptions defaultMapOptions = new MapOptions();
    defaultMapOptions.setDisplayProjection(
        new Projection(
            "EPSG:4326")); // causes the mouse popup to display coordinates in this format
    defaultMapOptions.setNumZoomLevels(16);

    // Create a MapWidget
    MapWidget mapWidget = new MapWidget("500px", "500px", defaultMapOptions);
    // 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 = "http://labs.metacarta.com/wms/vmap0";

    WMS wmsLayer = new WMS("Basic WMS", wmsUrl, wmsParams, wmsLayerParams);

    // Add the WMS to the map
    Map map = mapWidget.getMap();
    map.addLayer(wmsLayer);

    // Adds the graticule control
    LineSymbolizerOptions lineOptions = new LineSymbolizerOptions();
    lineOptions.setStrokeColor("#ccccff");
    lineOptions.setStrokeOpacity(0.5);
    lineOptions.setStrokeWidth(1);

    LineSymbolizer line = new LineSymbolizer(lineOptions);

    TextSymbolizerOptions textOptions = new TextSymbolizerOptions();
    textOptions.setFontSize("9px");

    TextSymbolizer text = new TextSymbolizer(textOptions);

    final GraticuleOptions grtOptions = new GraticuleOptions();

    grtOptions.setTargetSize(200);
    grtOptions.setLabelled(true);
    grtOptions.setLineSymbolyzer(line);
    grtOptions.setLabelSymbolizer(text);
    Graticule graticule = new Graticule(grtOptions);

    graticule.setAutoActivate(true);

    map.addControl(graticule);

    // 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

    // Center and zoom to a location
    map.setCenter(new LonLat(146.7, -41.8), 6);

    contentPanel.add(
        new HTML("<p>This example shows how to add a custom mouse position to the map..</p>"));
    contentPanel.add(mapWidget);

    initWidget(contentPanel);

    mapWidget
        .getElement()
        .getFirstChildElement()
        .getStyle()
        .setZIndex(0); // force the map to fall behind popups
  }
  @Override
  public void buildPanel() {

    OpenLayers.setProxyHost("olproxy?targetURL=");

    // create some MapOptions
    MapOptions defaultMapOptions = new MapOptions();
    defaultMapOptions.setNumZoomLevels(16);

    // Create a MapWidget
    MapWidget mapWidget = new MapWidget("500px", "500px", defaultMapOptions);
    // 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 = "http://vmap0.tiles.osgeo.org/wms/vmap0";

    WMS wmsLayer = new WMS("Basic WMS", wmsUrl, wmsParams, wmsLayerParams);

    Map map = mapWidget.getMap();

    // Add some control to the map
    LayerSwitcher layerSwitcher = new LayerSwitcher();
    map.addControl(layerSwitcher); // Display the LayerSwitcher
    map.addControl(new ScaleLine()); // Display the scaleline

    // Add the WMS to the map
    map.addLayer(wmsLayer);

    // Add some vectors
    final Point point = new Point(-110, 45);

    final Vector vectorLayer = new Vector("Features to Transform");

    // Style for the vector
    final Style featureStyle = new Style();
    featureStyle.setFillColor("#eeeeff");
    featureStyle.setStrokeColor("#3300ff");
    featureStyle.setStrokeWidth(2);
    featureStyle.setPointRadius(3);

    // Style for the rotation Handle
    final Style rotationHandlerStyle = new Style();
    rotationHandlerStyle.setFillColor("#eeeeee");
    rotationHandlerStyle.setFillOpacity(1);
    rotationHandlerStyle.setPointRadius(12);

    // create a polygon feature from a linear ring of points
    Point[] pointList = new Point[6];
    for (int p = 0; p < 6; p++) {
      double a = p * (2 * Math.PI) / 7;
      double r = Math.random() + 1;
      Point newPoint =
          new Point(point.getX() + (r * Math.cos(a)), point.getY() + (r * Math.sin(a)));
      pointList[p] = newPoint;
    }
    LinearRing linearRing = new LinearRing(pointList);
    final Polygon polygon = new Polygon(new LinearRing[] {linearRing});

    final VectorFeature polygonFeature =
        new VectorFeature(polygon, featureStyle); // create a VectorFeature from the polygon

    vectorLayer.addFeature(polygonFeature);

    // Create Options For the Transform Control
    TransformFeatureOptions transformFeatureOptions = new TransformFeatureOptions();

    transformFeatureOptions.setRotate(true);
    transformFeatureOptions.setRotation(0);
    transformFeatureOptions.setRederIntent("transform");
    transformFeatureOptions.setRotationHandleSymbolizer(rotationHandlerStyle);

    // Create The Transform Control
    TransformFeature transformFeature = new TransformFeature(vectorLayer, transformFeatureOptions);

    map.setCenter(new LonLat(point.getX(), point.getY()), 7);
    map.addLayer(vectorLayer);
    // Add and activate the control
    map.addControl(transformFeature);
    transformFeature.activate();

    contentPanel.add(new HTML("<p>This example shows the transformation of a Feature.</p>"));

    contentPanel.add(mapWidget);

    initWidget(contentPanel);

    mapWidget
        .getElement()
        .getFirstChildElement()
        .getStyle()
        .setZIndex(0); // force the map to fall behind popups
  }
Esempio n. 8
0
  /** 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() {

    OpenLayers.setProxyHost("olproxy?targetURL=");

    // create some MapOptions
    MapOptions defaultMapOptions = new MapOptions();
    defaultMapOptions.setNumZoomLevels(16);

    // Create a MapWidget
    MapWidget mapWidget = new MapWidget("500px", "500px", defaultMapOptions);
    // 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 = "http://vmap0.tiles.osgeo.org/wms/vmap0";

    WMS wmsLayer = new WMS("Basic WMS", wmsUrl, wmsParams, wmsLayerParams);

    // Add the WMS to the map
    Map map = mapWidget.getMap();
    map.addLayer(wmsLayer);

    // Add some vectors
    final Vector vectorLayer = new Vector("Simple Geometry");
    map.addLayer(vectorLayer);

    // create a point feature
    final Point point =
        new Point(-110, 45); // we need a Point object because this has the rotate method
    Style pointStyle = new Style();
    pointStyle.setFillColor("blue");
    pointStyle.setStrokeColor("blue");
    pointStyle.setStrokeWidth(3);
    pointStyle.setPointRadius(6);
    pointStyle.setFillOpacity(0.6);
    final VectorFeature pointFeature =
        new VectorFeature(point, pointStyle); // create a VectorFeature from the rotatable Polygon
    vectorLayer.addFeature(pointFeature);

    // create a line feature
    Point[] linePoints = {new Point(-120, 40), new Point(-115, 45), new Point(-110, 40)};
    final LineString lineString =
        new LineString(
            linePoints); // we need a LineString object because this has the rotate method
    final Style lineStyle = new Style();
    lineStyle.setStrokeColor("#339933");
    lineStyle.setStrokeWidth(3);
    lineStyle.setPointRadius(6);
    final VectorFeature lineFeature =
        new VectorFeature(
            lineString, lineStyle); // create a VectorFeature from the rotatable LineString
    vectorLayer.addFeature(lineFeature);

    // create a polygon feature from a linear ring of points
    Point[] pointList = new Point[6];
    for (int p = 0; p < 6; p++) {
      double a = p * (2 * Math.PI) / 7;
      double r = Math.random() + 1;
      Point newPoint =
          new Point(point.getX() + (r * Math.cos(a)), point.getY() + (r * Math.sin(a)));
      pointList[p] = newPoint;
    }
    LinearRing linearRing = new LinearRing(pointList);
    final Polygon polygon =
        new Polygon(
            new LinearRing[] {
              linearRing
            }); // we need a Polygon object because this has the rotate method
    final VectorFeature polygonFeature =
        new VectorFeature(polygon, lineStyle); // create a VectorFeature from the rotatable Polygon
    vectorLayer.addFeature(polygonFeature);

    // 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

    // Center and zoom to a location
    map.setCenter(new LonLat(point.getX(), point.getY()), 5);

    // start the actual rotating
    final Point origin = new Point(-111.04, 45.68);

    final Timer t =
        new Timer() // we just use a GWT timer to have animation, no need for special OpenLayer
        // timer stuff...
        {
          @Override
          public void run() {
            polygon.rotate(-360 / 20, origin);
            vectorLayer.drawFeature(polygonFeature, lineStyle);

            lineString.rotate(360 / 40, origin);
            vectorLayer.drawFeature(lineFeature, lineStyle);

            point.rotate(360 / 20, origin);
            vectorLayer.drawFeature(pointFeature, lineStyle);
          }
        };
    t.scheduleRepeating(100);

    contentPanel.add(
        new HTML(
            "<p>This example shows a few features rotating. There is not yet a control built that provides a tool for rotating, but the geometry.rotate method can be accessed to rotate programmatically.</p>"));

    contentPanel.add(mapWidget);

    initWidget(contentPanel);

    mapWidget
        .getElement()
        .getFirstChildElement()
        .getStyle()
        .setZIndex(0); // force the map to fall behind popups
  }
    @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>&lt;script src=\"http://maps.google.com/maps/api/js?v=3&amp;sensor=false\"&gt;&lt;/script&gt;</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


    }
Esempio n. 11
0
  @Override
  public void buildPanel() {
    OpenLayers.setProxyHost("olproxy?targetURL=");

    // create some MapOptions
    MapOptions defaultMapOptions = new MapOptions();
    defaultMapOptions.setDisplayProjection(
        new Projection(
            "EPSG:4326")); // causes the mouse popup to display coordinates in this format
    defaultMapOptions.setNumZoomLevels(16);

    // Create a MapWidget
    MapWidget mapWidget = new MapWidget("500px", "500px", defaultMapOptions);
    // 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 = "http://labs.metacarta.com/wms/vmap0";

    WMS wmsLayer = new WMS("Basic WMS", wmsUrl, wmsParams, wmsLayerParams);

    // Add the WMS to the map
    Map map = mapWidget.getMap();
    map.addLayer(wmsLayer);

    // Add a measure control to the map
    MeasureOptions measOpts = new MeasureOptions();
    measOpts.setPersist(true);
    measOpts.setGeodesic(true); // earth is not a cylinder
    Measure measure = new Measure(new PathHandler(), measOpts);
    map.addControl(measure);

    measure.addMeasureListener(
        new MeasureListener() {
          public void onMeasure(MeasureEvent eventObject) {
            Window.alert(
                "Measured distance is " + eventObject.getMeasure() + " " + eventObject.getUnits());
          }
        });
    measure.activate();

    // 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

    // Center and zoom to a location
    map.setCenter(new LonLat(146.7, -41.8), 6);

    contentPanel.add(
        new HTML(
            "<p>This example shows how to add a Measure Control to the map.</p><p>Click on the map to add measure points, end a measurement using double click.</p><p>Note that you could add buttons to enable/disable the measure control on command.</p>"));
    contentPanel.add(mapWidget);

    initWidget(contentPanel);

    mapWidget
        .getElement()
        .getFirstChildElement()
        .getStyle()
        .setZIndex(0); // force the map to fall behind popups
  }