Skip to content

Commit

Permalink
AAD-105: WMS legend, WMS feature info, overall search for values
Browse files Browse the repository at this point in the history
  • Loading branch information
jandm committed Nov 26, 2014
1 parent bc393f7 commit 2f520df
Show file tree
Hide file tree
Showing 24 changed files with 1,168 additions and 282 deletions.
1 change: 0 additions & 1 deletion map/pom.xml
Expand Up @@ -131,7 +131,6 @@
<dependency>
<groupId>org.geomajas.plugin</groupId>
<artifactId>geomajas-client-gwt2-plugin-wms-server-extension</artifactId>
<version>2.1.1</version>
</dependency>

<dependency>
Expand Down
Expand Up @@ -45,6 +45,7 @@
import org.geomajas.plugin.staticsecurity.client.StaticSecurityTokenRequestHandler;
import org.geomajas.plugin.staticsecurity.client.util.SsecLayout;
import org.geomajas.widget.searchandfilter.client.util.GsfLayout;
import org.ktunaxa.referral.client.action.WmsFeatureInfoModalAction;
import org.ktunaxa.referral.client.action.ZoomCurrentReferralModalAction;
import org.ktunaxa.referral.client.action.ZoomKtunaxaTerritoryModalAction;
import org.ktunaxa.referral.client.gui.DocumentItem;
Expand Down Expand Up @@ -76,6 +77,7 @@ public class KtunaxaEntryPoint implements EntryPoint {
public static final String TOOL_ZOOM_KTUNAXA_TERRITORY = "ZoomKtunaxaTerritory";
public static final String TOOL_ZOOM_CURRENT_REFERRAL = "ZoomCurrentReferral";
public static final String TOOL_SELECT_REFERRAL = "SelectReferralMode";
public static final String TOOL_FEATURE_INFO = "GetFeatureInfoMode";

private GetReferralMapResponse appInfo;

Expand Down Expand Up @@ -108,6 +110,11 @@ public ToolbarBaseAction createTool(MapWidget mapWidget) {
return new MakeReferralCurrentModalAction(mapWidget);
}
});
ToolbarRegistry.put(TOOL_FEATURE_INFO, new ToolCreator() {
public ToolbarBaseAction createTool(MapWidget mapWidget) {
return new WmsFeatureInfoModalAction(mapWidget);
}
});
AttributeFormFieldRegistry.registerCustomFormItem("topMiddleBottom", new DataSourceFieldFactory() {
public DataSourceField create() {
return new DataSourceIntegerField();
Expand Down
@@ -0,0 +1,112 @@
/*
* Ktunaxa Referral Management System.
*
* Copyright (C) see version control system
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ktunaxa.referral.client.action;

import org.geomajas.geometry.Coordinate;
import org.geomajas.gwt.client.controller.AbstractGraphicsController;
import org.geomajas.gwt.client.map.layer.InternalClientWmsLayer;
import org.geomajas.gwt.client.map.layer.Layer;
import org.geomajas.gwt.client.spatial.Mathlib;
import org.geomajas.gwt.client.spatial.WorldViewTransformer;
import org.geomajas.gwt.client.widget.MapWidget;
import org.geomajas.gwt2.client.map.feature.JsonFeatureFactory;
import org.geomajas.gwt2.plugin.wms.client.WmsClient;
import org.geomajas.gwt2.plugin.wms.client.layer.WmsLayer;
import org.geomajas.gwt2.plugin.wms.client.layer.WmsLayerConfiguration;
import org.geomajas.gwt2.plugin.wms.client.layer.WmsLayerImpl;
import org.geomajas.gwt2.plugin.wms.client.service.WmsService;
import org.ktunaxa.referral.client.gui.MapLayout;

import com.google.gwt.event.dom.client.MouseUpEvent;
import com.smartgwt.client.types.ContentsType;
import com.smartgwt.client.widgets.HTMLPane;
import com.smartgwt.client.widgets.Window;

public class WmsFeatureInfoController extends AbstractGraphicsController {

/** Number of pixels that describes the tolerance allowed when trying to select features. */
private int pixelTolerance;

public WmsFeatureInfoController(MapWidget mapWidget, int pixelTolerance) {
super(mapWidget);
this.pixelTolerance = pixelTolerance;
}

/**
* On mouse up, execute the search by location, and display a
* {@link org.geomajas.gwt.client.widget.FeatureAttributeWindow} if a result is found.
*/
public void onMouseUp(MouseUpEvent event) {
Coordinate worldPosition = getWorldPosition(event);
final Window window = new Window();
window.setWidth(MapLayout.getInstance().getLayerPanel().getWidth());
window.setHeight(MapLayout.getInstance().getLayerPanel().getHeight());
window.setCanDragReposition(true);
window.setCanDragResize(true);
StringBuilder sb = null;
WmsLayerConfiguration layerConfig = new WmsLayerConfiguration();
for (Layer<?> layer : mapWidget.getMapModel().getLayers()) {
if (layer.isShowing() && layer instanceof InternalClientWmsLayer) {
if (sb == null) {
sb = new StringBuilder();
InternalClientWmsLayer l = (InternalClientWmsLayer)layer;
layerConfig.setBaseUrl(l.getWmsLayer().getConfiguration().getBaseUrl());
layerConfig.setVersion(l.getWmsLayer().getConfiguration().getVersion());
layerConfig.setCrs(l.getWmsLayer().getConfiguration().getCrs());
layerConfig.setFormat(l.getWmsLayer().getConfiguration().getFormat());
layerConfig.setStyles("");
layerConfig.setLegendConfig(l.getWmsLayer().getConfiguration().getLegendConfig());
layerConfig.setTransparent(true);
layerConfig.setWmsServiceVendor(l.getWmsLayer().getConfiguration().getWmsServiceVendor());
} else {
sb.append(",");
}
sb.append(layer.getId());
}
}
if(sb != null) {
layerConfig.setLayers(sb.toString());
WmsLayer dummy = new WmsLayerImpl("all", layerConfig.getCrs(), layerConfig, null, null);
final String url = WmsClient
.getInstance()
.getWmsService()
.getFeatureInfoUrl(dummy, worldPosition,
mapWidget.getMapModel().getMapView().getBounds().toDtoBbox(),
1. / mapWidget.getMapModel().getMapView().getCurrentScale(),
WmsService.GetFeatureInfoFormat.HTML.toString(), 10);
window.setTitle("Features found for "+sb.toString()+":");
HTMLPane htmlPane = new HTMLPane();
htmlPane.setContentsURL(url);
htmlPane.setContentsType(ContentsType.PAGE);
window.addItem(htmlPane);
if(!window.isDrawn()) {
window.showNextTo(MapLayout.getInstance().getMap(), "left");
}
}

}

private double calculateBufferFromPixelTolerance() {
WorldViewTransformer transformer = mapWidget.getMapModel().getMapView().getWorldViewTransformer();
Coordinate c1 = transformer.viewToWorld(new Coordinate(0, 0));
Coordinate c2 = transformer.viewToWorld(new Coordinate(pixelTolerance, 0));
return Mathlib.distance(c1, c2);
}

}
@@ -0,0 +1,68 @@
/*
* Ktunaxa Referral Management System.
*
* Copyright (C) see version control system
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ktunaxa.referral.client.action;

import org.geomajas.gwt.client.action.ToolbarModalAction;
import org.geomajas.gwt.client.i18n.I18nProvider;
import org.geomajas.gwt.client.util.WidgetLayout;
import org.geomajas.gwt.client.widget.MapWidget;

import com.smartgwt.client.widgets.events.ClickEvent;


public class WmsFeatureInfoModalAction extends ToolbarModalAction {

private MapWidget mapWidget;

private WmsFeatureInfoController controller;

/** Number of pixels that describes the tolerance allowed when trying to select features. */
private int pixelTolerance = 5;

// Constructor:

public WmsFeatureInfoModalAction(MapWidget mapWidget) {
super(WidgetLayout.iconInfo, I18nProvider.getToolbar().featureInfoTitle(), I18nProvider
.getToolbar().featureInfoTooltip());
this.mapWidget = mapWidget;
controller = new WmsFeatureInfoController(mapWidget, pixelTolerance);
}

// ToolbarModalAction implementation:

@Override
public void onSelect(ClickEvent event) {
mapWidget.setController(controller);
}

@Override
public void onDeselect(ClickEvent event) {
mapWidget.setController(null);
}

// Getters and setters:

public int getPixelTolerance() {
return pixelTolerance;
}

public void setPixelTolerance(int pixelTolerance) {
this.pixelTolerance = pixelTolerance;
}
}
49 changes: 21 additions & 28 deletions map/src/main/java/org/ktunaxa/referral/client/gui/MapLayout.java
Expand Up @@ -23,15 +23,13 @@

import org.geomajas.configuration.FeatureStyleInfo;
import org.geomajas.configuration.SymbolInfo;
import org.geomajas.configuration.client.ScaleInfo;
import org.geomajas.geometry.Coordinate;
import org.geomajas.global.GeomajasConstant;
import org.geomajas.gwt.client.Geomajas;
import org.geomajas.gwt.client.command.GwtCommandDispatcher;
import org.geomajas.gwt.client.gfx.paintable.GfxGeometry;
import org.geomajas.gwt.client.gfx.style.ShapeStyle;
import org.geomajas.gwt.client.map.MapView;
import org.geomajas.gwt.client.map.event.MapModelChangedEvent;
import org.geomajas.gwt.client.map.event.MapModelChangedHandler;
import org.geomajas.gwt.client.map.feature.Feature;
import org.geomajas.gwt.client.map.feature.LazyLoadCallback;
import org.geomajas.gwt.client.map.layer.ClientWmsLayer;
Expand All @@ -45,14 +43,14 @@
import org.geomajas.gwt.client.util.WidgetLayout;
import org.geomajas.gwt.client.widget.MapWidget;
import org.geomajas.gwt.client.widget.Toolbar;
import org.geomajas.gwt2.client.map.MapConfigurationImpl;
import org.geomajas.gwt2.client.map.layer.tile.TileConfiguration;
import org.geomajas.gwt2.plugin.wms.client.WmsClient;
import org.geomajas.gwt2.plugin.wms.client.capabilities.WmsGetCapabilitiesInfo;
import org.geomajas.gwt2.plugin.wms.client.capabilities.WmsLayerInfo;
import org.geomajas.gwt2.plugin.wms.client.layer.WmsLayerConfiguration;
import org.geomajas.gwt2.plugin.wms.client.service.WmsService;
import org.geomajas.gwt2.plugin.wms.client.service.WmsService.WmsVersion;
import org.geomajas.widget.layer.configuration.client.ClientAbstractNodeInfo;
import org.geomajas.widget.layer.configuration.client.ClientExtraLayerInfo;
import org.geomajas.widget.layer.configuration.client.ClientLayerNodeInfo;
import org.geomajas.widget.layer.configuration.client.ClientLayerTreeInfo;
import org.ktunaxa.referral.client.i18n.LocalizedMessages;
Expand All @@ -72,7 +70,6 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.http.client.URL;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Window;
Expand All @@ -92,6 +89,8 @@
*/
public final class MapLayout extends VLayout {

private static final double METER_PER_INCH = 0.0254;

/**
* Focus options after refreshing the referral.
*
Expand Down Expand Up @@ -242,6 +241,8 @@ public void onClick(ClickEvent event) {
protected void addClientLayers() {
// assuming collocated geoserver !!!
final String url = Geomajas.getDispatcherUrl().replace("/map/d", "/geoserver/ows");
// final String url = "http://127.0.0.1:8888/d/proxy?url=http://64.141.44.215:9090/geoserver/ows";
final Callback<Void, Void> callback = CommunicationHandler.get().startAction("Loading layers...", false);
WmsClient.getInstance().getWmsService()
.getCapabilities(url, WmsVersion.V1_3_0, new Callback<WmsGetCapabilitiesInfo, String>() {

Expand All @@ -259,24 +260,38 @@ public void onSuccess(WmsGetCapabilitiesInfo result) {
ClientWmsLayer wmsLayer = new ClientWmsLayer(info.getName(), mapWidget.getMapModel()
.getMapInfo().getCrs(), wmsConfig, tileConfig);
ClientWmsLayerInfo wmsLayerInfo = new ClientWmsLayerInfo(wmsLayer);
wmsLayerInfo.setMaximumScale(new ScaleInfo(1/toResolution(info.getMinScaleDenominator())));
wmsLayerInfo.setMinimumScale(new ScaleInfo(1/toResolution(info.getMaxScaleDenominator())));
ClientExtraLayerInfo extra = new ClientExtraLayerInfo();
extra.setLegendUrl(wmsLayer.getLegendImageUrl());
extra.setLegendUrlTitle("Legend");
wmsLayerInfo.getWidgetInfo().put(ClientExtraLayerInfo.IDENTIFIER, extra);
ClientLayerTreeInfo tree = (ClientLayerTreeInfo) mapWidget.getMapModel().getMapInfo()
.getWidgetInfo(ClientLayerTreeInfo.IDENTIFIER);
ClientLayerNodeInfo node = new ClientLayerNodeInfo();
node.setLayerId(wmsLayerInfo.getId());
tree.getTreeNode().getTreeNodes().add(node);
wmsLayerInfo.setVisible(false);
mapWidget.getMapModel().addLayer(wmsLayerInfo);
callback.onSuccess(null);
}

}

@Override
public void onFailure(String reason) {
SC.say("Could not reach geoserver on "+url);
callback.onSuccess(null);
}
});

}

public double toResolution(double scaleDenominator) {
double pixelsPerUnit = METER_PER_INCH / MapConfigurationImpl.DEFAULT_DPI;
return pixelsPerUnit * scaleDenominator;
}


protected void updateRights() {
if (!(UserContext.getInstance().isGuest() || UserContext.getInstance().isDataEntry())) {
Expand Down Expand Up @@ -524,26 +539,4 @@ public void refreshSearch() {
searchPanel.refreshSearch();
}

private ClientWmsLayerInfo addWms(String name, MapWidget mapWidget) {

WmsLayerConfiguration wmsConfig = new WmsLayerConfiguration();
wmsConfig.setFormat("image/png");
wmsConfig.setLayers(name);
wmsConfig.setVersion(WmsService.WmsVersion.V1_3_0);
wmsConfig.setBaseUrl("http://64.141.44.215:9090/geoserver/ows");
wmsConfig.setCrs(KtunaxaConstant.MAP_CRS);
wmsConfig.setTransparent(true);
wmsConfig.setMaximumResolution(Double.MAX_VALUE);
wmsConfig.setMinimumResolution(1 / mapWidget.getMapModel().getMapInfo().getMaximumScale());

TileConfiguration tileConfig = new TileConfiguration(256, 256, new Coordinate(-20037508.343, -20037508.343),
mapWidget.getMapModel().getMapView().getResolutions());

ClientWmsLayer wmsLayer = new ClientWmsLayer(name, mapWidget.getMapModel().getMapInfo().getCrs(), wmsConfig,
tileConfig);

ClientWmsLayerInfo wmsLayerInfo = new ClientWmsLayerInfo(wmsLayer);
return wmsLayerInfo;
}

}

0 comments on commit 2f520df

Please sign in to comment.