@Override
 public MapOptions createMapPreviewOption() {
   MapOptions defaultMapOptions = new MapOptions();
   defaultMapOptions.setNumZoomLevels(18);
   defaultMapOptions.setProjection("EPSG:900913");
   defaultMapOptions.setDisplayProjection(new Projection("EPSG:4326"));
   defaultMapOptions.setUnits(MapUnits.METERS);
   defaultMapOptions.setMaxExtent(new Bounds(-20037508, -20037508, 20037508, 20037508.34));
   defaultMapOptions.setMaxResolution(new Double(156543.0339).floatValue());
   return defaultMapOptions;
 }
Beispiel #2
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();
  }
Beispiel #3
0
  /** Creates the center. */
  private void createCenter() {
    center = new ContentPanel();
    center.setLayout(new BorderLayout());
    center.setHeaderVisible(false);

    ContentPanel map = new ContentPanel();
    map.setLayout(new FitLayout());
    map.setHeaderVisible(false);

    // we dont need this since we have listener on south panel as well

    map.addListener(
        Events.Resize,
        new Listener<BaseEvent>() {

          public void handleEvent(BaseEvent be) {
            Dispatcher.forwardEvent(GeoGWTEvents.UPDATE_MAP_SIZE);
            // Dispatcher.forwardEvent(AcoDBEvents.UPDATE_SOUTH_SIZE);
          }
        });
    map.addListener(
        Events.Move,
        new Listener<BaseEvent>() {

          public void handleEvent(BaseEvent be) {
            Dispatcher.forwardEvent(GeoGWTEvents.UPDATE_MAP_SIZE);
            // Dispatcher.forwardEvent(AcoDBEvents.UPDATE_SOUTH_SIZE);
          }
        });

    map.setMonitorWindowResize(true);
    map.setLayoutOnChange(true);

    BorderLayoutData data = new BorderLayoutData(LayoutRegion.CENTER);
    data.setMargins(new Margins(0));

    // add map to center region of center panel
    center.add(map, data);

    data = new BorderLayoutData(LayoutRegion.CENTER);
    // data.setCollapsible(true);
    // data.setFloatable(true);
    // data.setSplit(true);
    data.setMargins(new Margins(5, 5, 5, 5));

    viewport.add(center, data);

    /* map options */
    MapOptions mapOptions = new MapOptions();
    mapOptions.setUnits(MapUnits.DEGREES);
    mapOptions.setProjection("EPSG:4326");

    MousePositionOutput mpOut =
        new MousePositionOutput() {

          public String format(LonLat lonLat, Map map) {
            String out = "";
            out += "<font size='2' color='black' style='font-weight:900'>";
            out += (float) lonLat.lon();
            out += " ";
            out += (float) lonLat.lat();
            out += "</font>";

            return out;
          }
        };

    MousePositionOptions mpOptions = new MousePositionOptions();
    mpOptions.setFormatOutput(mpOut);

    JSObject[] controls =
        new JSObject[] {
          new Navigation().getJSObject(),
          new PanZoom().getJSObject(),
          new LayerSwitcher().getJSObject(),
          new ScaleLine().getJSObject(),
          new MousePosition(mpOptions).getJSObject()
        };
    JObjectArray mapControls = new JObjectArray(controls);
    mapOptions.setControls(mapControls);

    Dispatcher.forwardEvent(GeoGWTEvents.INIT_MAPS_UI_MODULE, mapOptions);

    addBaseLayer();

    Dispatcher.forwardEvent(GeoGWTEvents.ATTACH_MAP_WIDGET, map);

    GeofenceGlobalConfiguration geoFenceConfiguration =
        (GeofenceGlobalConfiguration) GeofenceUtils.getInstance().getGlobalConfiguration();

    // Adjusting the Zoom level
    // Dispatcher.forwardEvent(GeoGWTEvents.ZOOM_TO_MAX_EXTENT);
    Dispatcher.forwardEvent(
        GeoGWTEvents.SET_MAP_CENTER,
        new Double[] {
          Double.valueOf(geoFenceConfiguration.getMapCenterLon()),
          Double.valueOf(geoFenceConfiguration.getMapCenterLat())
        });
    Dispatcher.forwardEvent(
        GeoGWTEvents.ZOOM, Integer.parseInt(geoFenceConfiguration.getMapZoom()));

    ToolbarItemManager toolbarItemManager = new ToolbarItemManager();

    // defining toolbar tools
    GenericClientTool poweredBy = new GenericClientTool();
    poweredBy.setId(ButtonBar.POWERED_BY);
    poweredBy.setOrder(-400);

    GenericClientTool toolbarSeparator1 = new GenericClientTool();
    toolbarSeparator1.setId(ButtonBar.TOOLBAR_SEPARATOR);
    toolbarSeparator1.setOrder(-300);

    ActionClientTool pan = new ActionClientTool();
    pan.setId("pan");
    pan.setEnabled(true);
    pan.setType("toggle");
    pan.setOrder(0);

    ActionClientTool zoomAll = new ActionClientTool();
    zoomAll.setId("zoomAll");
    zoomAll.setEnabled(true);
    zoomAll.setType("button");
    zoomAll.setOrder(10);

    ActionClientTool zoomBox = new ActionClientTool();
    zoomBox.setId("zoomBox");
    zoomBox.setEnabled(true);
    zoomBox.setType("toggle");
    zoomBox.setOrder(20);

    ActionClientTool zoomIn = new ActionClientTool();
    zoomIn.setId("zoomIn");
    zoomIn.setEnabled(true);
    zoomIn.setType("button");
    zoomIn.setOrder(30);

    ActionClientTool zoomOut = new ActionClientTool();
    zoomOut.setId("zoomOut");
    zoomOut.setEnabled(true);
    zoomOut.setType("button");
    zoomOut.setOrder(40);

    ActionClientTool drawFeature = new ActionClientTool();
    drawFeature.setId("drawFeature");
    drawFeature.setEnabled(true);
    drawFeature.setType("toggle");
    drawFeature.setOrder(50);

    GenericClientTool toolbarSeparator2 = new GenericClientTool();
    toolbarSeparator2.setId(ButtonBar.TOOLBAR_SEPARATOR);
    toolbarSeparator2.setOrder(300);

    //        ToolbarActionRegistry.getRegistry().put("synchUsers", new ToolActionCreator()
    //            {
    //
    //                public ToolbarAction createActionTool()
    //                {
    //                    UpdateUsersAction action = new UpdateUsersAction();
    //                    action.initialize();
    //
    //                    return action;
    //                }
    //            });
    //
    //        ActionClientTool synchUsers = new ActionClientTool();
    //        synchUsers.setId("synchUsers");
    //        synchUsers.setEnabled(true);
    //        synchUsers.setType("button");
    //        synchUsers.setOrder(310);

    GenericClientTool fillItem = new GenericClientTool();
    fillItem.setId(ButtonBar.FILL_ITEM);
    fillItem.setOrder(320);

    ToolbarActionRegistry.getRegistry()
        .put(
            "logout",
            new ToolActionCreator() {

              public ToolbarAction createActionTool() {
                LogoutAction action = new LogoutAction();
                action.initialize();

                return action;
              }
            });

    ActionClientTool logout = new ActionClientTool();
    logout.setId("logout");
    logout.setEnabled(true);
    logout.setType("button");
    logout.setOrder(500);

    List<GenericClientTool> clientTools = new ArrayList<GenericClientTool>();
    // clientTools.add(poweredBy);
    // clientTools.add(toolbarSeparator1);
    clientTools.add(pan);
    clientTools.add(zoomAll);
    clientTools.add(zoomBox);
    clientTools.add(zoomIn);
    clientTools.add(zoomOut);
    clientTools.add(drawFeature);
    clientTools.add(toolbarSeparator2);
    //        clientTools.add(synchUsers);
    clientTools.add(fillItem);
    clientTools.add(logout);

    toolbarItemManager.setClientTools(clientTools);

    if (GeoGWTUtils.getInstance().getGlobalConfiguration() == null) {
      GeoGWTUtils.getInstance().setGlobalConfiguration(new GeoGWTConfiguration());
    }

    GeoGWTUtils.getInstance().getGlobalConfiguration().setToolbarItemManager(toolbarItemManager);

    Dispatcher.forwardEvent(GeoGWTEvents.ATTACH_TOOLBAR, this.north);
    // Dispatcher.forwardEvent(GeofenceEvents.ATTACH_MAP_WIDGET, this.center);
  }