# HG changeset patch # User Ingo Weinzierl # Date 1320331876 0 # Node ID 78542ff1f562e2bf215db9a9133f674cd13945ac # Parent 4459901e4ec0131a11b69569dad8bdb7edff98cc Update map and theme panel when new layers are added via datacage or removed by context menu. flys-client/trunk@3155 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 4459901e4ec0 -r 78542ff1f562 flys-client/ChangeLog --- a/flys-client/ChangeLog Tue Nov 01 16:07:39 2011 +0000 +++ b/flys-client/ChangeLog Thu Nov 03 14:51:16 2011 +0000 @@ -1,3 +1,20 @@ +2011-11-03 Ingo Weinzierl + + * src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java: + Added methods to add and remove Layer instance to/from Map and grant + public access to createWMSLayer() method. + + * src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java: Moved + code to add new FacetRecords to the grid to an own method + addFacetRecord(). + + * src/main/java/de/intevation/flys/client/client/ui/map/MapThemePanel.java: + Override addFacetRecord() to be able to detect new FacetRecords. In this + case, we gonna create new WMS layers based on the FacetRecord and add a + new Layer object to the Map. + Override createRemoveItem() which removes a layer from Map and from + ThemePanel. + 2011-11-01 Raimund Renkert * src/main/java/de/intevation/flys/client/client/ui/StyleEditorWindow.java: diff -r 4459901e4ec0 -r 78542ff1f562 flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java Tue Nov 01 16:07:39 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/ThemePanel.java Thu Nov 03 14:51:16 2011 +0000 @@ -220,7 +220,7 @@ } FacetRecord newRecord = createRecord(theme); - list.addData(newRecord); + addFacetRecord(newRecord); String newArtifact = theme.getArtifact(); String newFacet = theme.getFacet(); @@ -242,6 +242,11 @@ } + protected void addFacetRecord(FacetRecord rec) { + list.addData(rec); + } + + protected FacetRecord createRecord(Theme theme) { return new FacetRecord(theme); } diff -r 4459901e4ec0 -r 78542ff1f562 flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java Tue Nov 01 16:07:39 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapOutputTab.java Thu Nov 03 14:51:16 2011 +0000 @@ -102,7 +102,6 @@ setFloodmap(new FloodMap(c.getSrid(), max)); initLayout(); - initLayers(); initBarriers(); GWT.log("MAX EXTENT: " + max); @@ -165,25 +164,6 @@ } - protected void initLayers() { - ThemeList themeList = themePanel.getThemeList(); - - int num = themeList.getThemeCount(); - Map map = floodMap.getMap(); - - for (int i = num; i >= 0; i--) { - Theme theme = themeList.getThemeAt(i); - Layer layer = createWMSLayer(theme); - - if (layer == null) { - continue; - } - - map.addLayer(layer); - } - } - - protected void initBarriers() { Vector vector = floodMap.getBarrierLayer(); vector.addVectorFeatureAddedListener( @@ -226,10 +206,40 @@ } + public void addLayer(Layer layer) { + Map map = getMap(); + + if (map != null) { + GWT.log("Add new layer '" + layer.getName() + "' to map."); + map.addLayer(layer); + } + } + + + public void removeLayer(String name) { + Map map = getMap(); + + Layer[] layers = map.getLayers(); + + for (Layer layer: layers) { + if (name.equals(layer.getName())) { + map.removeLayer(layer); + } + } + } + + @Override public void onRedrawRequest(RedrawRequestEvent event) { - // TODO FILL ME - GWT.log("TODO: Request redraw."); + mapService.doOut(collection, new AsyncCallback() { + public void onFailure(Throwable caught) { + GWT.log("MAP ERROR: " + caught.getMessage()); + } + + public void onSuccess(MapConfig c) { + themePanel.updateCollection(); + } + }); } @@ -243,6 +253,11 @@ } + protected ThemePanel getThemePanel() { + return themePanel; + } + + protected String getGeoJSONFromDynamic(ArtifactDescription desc) { DataList list = desc.getCurrentData(); @@ -327,7 +342,7 @@ } - protected Layer createWMSLayer(Theme theme) { + public Layer createWMSLayer(Theme theme) { if (theme == null) { return null; } @@ -379,6 +394,7 @@ themePanel = new MapThemePanel( collection, mode, + this, new MapThemePanel.ActivateCallback() { public void activate(Theme theme, boolean active) { activateTheme(theme, active); @@ -425,6 +441,8 @@ String name = theme.getDescription(); Layer layer = floodMap.getMap().getLayerByName(name); + GWT.log("Set visibility of '" + name + "': " + active); + if (layer != null) { layer.setIsVisible(active); } diff -r 4459901e4ec0 -r 78542ff1f562 flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapThemePanel.java --- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapThemePanel.java Tue Nov 01 16:07:39 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/MapThemePanel.java Thu Nov 03 14:51:16 2011 +0000 @@ -59,6 +59,8 @@ protected ThemeMovedCallback themeMovedCallback; protected LayerZoomCallback layerZoomCallback; + protected ListGridRecord[] oldRecords; + public static final String GRID_FIELD_ACTIVE = "active"; public static final String GRID_FIELD_STYLE = "style"; @@ -70,22 +72,25 @@ public MapThemePanel( Collection collection, + MapOutputTab mapOut, OutputMode mode, ActivateCallback activateCallback ) { - this(collection, mode, activateCallback, null, null); + this(collection, mode, mapOut, activateCallback, null, null); } public MapThemePanel( Collection collection, OutputMode mode, + MapOutputTab mapOut, ActivateCallback activateCallback, ThemeMovedCallback themeMovedCallback, LayerZoomCallback layerZoomCallback ) { super(collection, mode); + this.mapOut = mapOut; this.activateCallback = activateCallback; this.themeMovedCallback = themeMovedCallback; this.layerZoomCallback = layerZoomCallback; @@ -184,6 +189,35 @@ @Override + protected void clearGrid() { + oldRecords = list.getRecords(); + super.clearGrid(); + } + + + @Override + protected void addFacetRecord(FacetRecord rec) { + Theme newTheme = rec.getTheme(); + boolean isNew = true; + + for (ListGridRecord old: getOldRecords()) { + FacetRecord fr = (FacetRecord) old; + + if (newTheme.equals(fr.getTheme())) { + isNew = false; + break; + } + } + + if (isNew && mapOut != null) { + mapOut.addLayer(mapOut.createWMSLayer(newTheme)); + } + + super.addFacetRecord(rec); + } + + + @Override protected Menu getSingleContextMenu(final ListGridRecord[] records) { Menu menu = super.getSingleContextMenu(records); @@ -196,6 +230,30 @@ } + @Override + protected MenuItem createRemoveItem(final ListGridRecord[] records) { + MenuItem item = super.createRemoveItem(records); + item.addClickHandler(new ClickHandler() { + @Override + public void onClick(MenuItemClickEvent evt) { + for (ListGridRecord record: records) { + FacetRecord facet = (FacetRecord) record; + + Theme theme = facet.getTheme(); + theme.setVisible(0); + theme.setActive(0); + + getMapOutputTab().removeLayer(theme.getDescription()); + } + + updateCollection(); + } + }); + + return item; + } + + protected MenuItem createLayerZoomItem(final ListGridRecord[] recs) { final FacetRecord fr = (FacetRecord) recs[0]; final AttributedTheme at = (AttributedTheme) fr.getTheme(); @@ -236,5 +294,15 @@ themeMovedCallback.onThemeMoved(theme, oldIdx, newIdx); } } + + + protected ListGridRecord[] getOldRecords() { + return oldRecords != null ? oldRecords : new ListGridRecord[0]; + } + + + protected MapOutputTab getMapOutputTab() { + return mapOut; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :