VOL3 / v-ol3

Vaadin OpenLayers 3 wrapper
Apache License 2.0
15 stars 18 forks source link

Unable to load WMS Image from geoserver on localhost #46

Closed jobsonm closed 9 years ago

jobsonm commented 9 years ago

Trying to use the OpenLayers (at v0.1.7) to load a image from a geoserver stored layer on my "localhost" PC. If I do a "layer Preview" within geoserver I get the following output:

Request: getMap Time = [] Format = image/png Filter = null Buffer = 0 Filters = null ValidateSchema = false Tiled = false FeatureVersion = null Transparent = false StyleFormat = sld SldBody = null Sld = null StyleUrl = null Crs = GEOGCS["WGS 84", DATUM["World Geodetic System 1984", SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]], AUTHORITY["EPSG","6326"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Geodetic longitude", EAST], AXIS["Geodetic latitude", NORTH], AUTHORITY["EPSG","4326"]] Bbox = SRSEnvelope[-2.1915973960504687 : -1.6000229379737738, 51.15011747003079 : 51.31302800327667] RemoteOwsType = null RemoteOwsURL = null Env = {} FormatOptions = {} Angle = 0.0 CQLFilter = null Elevation = [] FeatureId = null StartIndex = null ViewParams = null BgColor = java.awt.Color[r=255,g=255,b=255] TilesOrigin = null Palette = null SRS = EPSG:4326 Styles = [StyleImpl[ name=raster]] Layers = [org.geoserver.wms.MapLayerInfo@770c7188] MaxFeatures = null Width = 1198 Height = 330 Exceptions = SE_XML StyleBody = null SldVersion = null StyleVersion = null Version = 1.1.0 BaseUrl = http://localhost:8080/geoserver/ Request = GetMap RequestCharset = UTF-8 RawKvp = {REQUEST=GetMap, SRS=EPSG:4326, FORMAT=image/png, BBOX=-2.1915973960504687,51.15011747003079,-1.6000229379737738,51.31302800327667, VERSION=1.1.0, STYLES=, SERVICE=WMS, WIDTH=1198, HEIGHT=330, LAYERS=SPTA:spta} Get = true

If I use my Java code (listed at the bottom) I get the following output on the geoserver log file:

Request: getMap Time = [] Format = image/png Filter = null Buffer = 0 Filters = null ValidateSchema = false Tiled = false FeatureVersion = null Transparent = true StyleFormat = sld SldBody = null Sld = null StyleUrl = null Crs = GEOGCS["WGS 84", DATUM["World Geodetic System 1984", SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]], AUTHORITY["EPSG","6326"]], PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]], UNIT["degree", 0.017453292519943295], AXIS["Geodetic latitude", NORTH], AXIS["Geodetic longitude", EAST], AUTHORITY["EPSG","4326"]] Bbox = SRSEnvelope[-121.46484375 : 121.46484375, -253.125 : 253.125] RemoteOwsType = null RemoteOwsURL = null Env = {} FormatOptions = {} Angle = 0.0 CQLFilter = null Elevation = [] FeatureId = null StartIndex = null ViewParams = null BgColor = java.awt.Color[r=255,g=255,b=255] TilesOrigin = null Palette = null SRS = urn:x-ogc:def:crs:EPSG:4326 Styles = [StyleImpl[ name=raster]] Layers = [org.geoserver.wms.MapLayerInfo@770c7188] MaxFeatures = null Width = 2880 Height = 1382 Exceptions = SE_XML StyleBody = null SldVersion = null StyleVersion = null Version = 1.3.0 BaseUrl = http://localhost:8080/geoserver/ Request = GetMap RequestCharset = UTF-8 RawKvp = {REQUEST=GetMap, FORMAT=image/png, CRS=EPSG:4326, BBOX=-121.46484375,-253.125,121.46484375,253.125, VERSION=1.3.0, STYLES=, SERVICE=WMS, WIDTH=2880, HEIGHT=1382, TRANSPARENT=true, LAYERS=SPTA:spta} Get = true

So everything is the same apart from the BBOX values. I could set the version to 1.1.0 but I still get the BBOX inconsistencies. My Java code is lised in it'sentirety below:

package com.qinetiq.training.web.aime.openlayers;

import gov.nasa.worldwind.ogc.wms.WMSCapabilities; import gov.nasa.worldwind.ogc.wms.WMSLayerCapabilities;

import java.io.File; import java.util.HashMap; import java.util.Map; import java.util.Vector;

import org.vaadin.addon.vol3.OLMap; import org.vaadin.addon.vol3.OLView; import org.vaadin.addon.vol3.OLViewOptions; import org.vaadin.addon.vol3.client.OLCoordinate; import org.vaadin.addon.vol3.client.Projections; import org.vaadin.addon.vol3.client.control.OLMousePositionControl; import org.vaadin.addon.vol3.client.control.OLScaleLineControl; import org.vaadin.addon.vol3.feature.OLFeature; import org.vaadin.addon.vol3.feature.OLGeometry; import org.vaadin.addon.vol3.feature.OLLineString; import org.vaadin.addon.vol3.feature.OLPoint; import org.vaadin.addon.vol3.layer.OLImageLayer; import org.vaadin.addon.vol3.layer.OLLayer; import org.vaadin.addon.vol3.layer.OLTileLayer; import org.vaadin.addon.vol3.source.OLImageWMSSource; import org.vaadin.addon.vol3.source.OLImageWMSSourceOptions; import org.vaadin.addon.vol3.source.OLSource; import org.vaadin.addon.vol3.source.OLVectorSource;

import aimeJava.generic.AimeLogger; import aimeJava.generic.DataHolder; import aimeJava.generic.FomDataItem; import aimeJava.rpr.BaseEntity; import aimeJava.rpr.EntityID; import aimeJava.rpr.RprProperties;

import com.qinetiq.training.web.aime.AimeWebServlet; import com.qinetiq.training.web.aime.MilStd2525; import com.qinetiq.training.web.aime.app.AbstractApplicationRuntimeDisplay; import com.qinetiq.training.web.aime.app.QinetiQApplicationBaseUI; import com.qinetiq.training.web.aime.utilities.coordinates.LatLonAltPoint; import com.vaadin.tapio.googlemaps.GoogleMap; import com.vaadin.tapio.googlemaps.client.LatLon; import com.vaadin.tapio.googlemaps.client.events.MapMoveListener; import com.vaadin.tapio.googlemaps.client.overlays.GoogleMapMarker; import com.vaadin.ui.AbstractLayout; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Notification; import com.vaadin.ui.VerticalLayout;

@SuppressWarnings("serial") public class AimeOpenLayersRuntimeDisplay extends AbstractApplicationRuntimeDisplay implements BaseEntity.CreationListener, BaseEntity.UpdateListener, MapMoveListener { private OLMap map; // private OLTileLayer baseLayer; // private OLLayer baseLayer; // private OLVectorLayer vectorLayer;

private final String LATITUDE = "latitude", LONGITUDE = "longitude",
        ZOOM_LEVEL = "zoomLevel";

public AimeOpenLayersRuntimeDisplay(QinetiQApplicationBaseUI application)
{
    super(application);

    VerticalLayout layout = new VerticalLayout();
    layout.setSizeFull();

    BaseEntity.registerCreationListener(this);
    Vector<FomDataItem> items = BaseEntity.getFomDataItems();
    for (int i = 0; i < items.size(); i++)
    {
        FomDataItem item = BaseEntity.getFomDataItems().get(i);
        BaseEntity.registerUpdateListener(this, item);
    }

    // Load the configuration from the cookie
    // BrowserCookie.detectCookieValue(application.generateCookieName(),
    // new BrowserCookie.Callback()
    // {
    // @Override
    // public void onValueDetected(String value)
    // {
    // application.load(value);
    // MapConfiguration newPosition = new MapConfiguration(
    // application.getConfiguration());
    // configureMap(newPosition);
    // }
    // });

    // create map instance
    map = new OLMap();
    map.setSizeFull();

    // add layers to map
    // OLLayer layer = createTileLayer(createImageSource());
    OLLayer layer = createImageLayer(createImageSource());
    map.addLayer(layer);

    map.setView(createView());
    // vectorLayer = new OLVectorLayer(createVectorSource());
    // vectorLayer.setLayerVisible(true);
    // map.addLayer(vectorLayer);

    // Add the entity layer
    AimeOpenLayers aimeOpenLayers = (AimeOpenLayers) getApplication();
    map.addLayer(new EntityLayer(new EntityLayerSource(), aimeOpenLayers
            .getEntityLayerOptions()));

    // Add the map component
    layout.addComponent(map);
    // layout.addComponent(createControls());

    // Set full screen
    layout.setExpandRatio(map, 1.0f);

    // Set the main display
    setCompositionRoot(layout);

    Notification.show("AIME OpenLayers plugin",
            "TO IMPLEMENT IN NEXT VERSION",
            Notification.Type.HUMANIZED_MESSAGE);
}

private OLSource createImageSource()
{
    OLSource source = null;

    // Has the user set a WMS layer source
    if (getApplication() instanceof AimeOpenLayers)
    {
        AimeOpenLayers aimeOpenLayers = (AimeOpenLayers) getApplication();

        if ((aimeOpenLayers.getSelectedLayer() != null)
                && (aimeOpenLayers.getWmsCapability() != null)
                && (aimeOpenLayers.getSelectedUri() != null))
        {
            WMSCapabilities wmsCapability = aimeOpenLayers
                    .getWmsCapability();
            WMSLayerCapabilities selectedLayer = aimeOpenLayers
                    .getSelectedLayer();

            // OLTileGrid tileGrid = new OLTileGrid();

            // Set the WMS source data
            OLImageWMSSourceOptions options = new OLImageWMSSourceOptions();
            options.setUrl(aimeOpenLayers.getSelectedUri().toString());

            Map<String, String> params = new HashMap<String, String>();
            // params.put("LAYERS", "osm_auto:all");
            params.put("LAYERS", selectedLayer.getName());
            params.put("FORMAT", "image/png");
            // params.put("TRANSPARENT", "true");
            options.setParams(params);

            options = createSptaImageSource();

            // Set the source data
            source = new OLImageWMSSource(options);
        }
        else
        {
            OLImageWMSSourceOptions options = createSptaImageSource();
            // OLImageWMSSourceOptions options = createTestSource();
            source = new OLImageWMSSource(options);
            System.out.println("AIME WMS....");

            // source = new OLMapQuestSource(OLMapQuestLayerName.OSM);
        }

    }
    else
    {
        // do nothing
    }

    return source;
}

protected OLLayer createTileLayer(OLSource source)
{
    return new OLTileLayer(source);
}

protected OLLayer createImageLayer(OLSource source)
{
    return new OLImageLayer(source);
}

private OLView createView()
{
    OLViewOptions options = new OLViewOptions();
    // options.setMapProjection("EPSG:900913");
    options.setMapProjection("EPSG:4326");
    options.setInputProjection(Projections.EPSG4326);

    OLView view = new OLView(options);
    view.setZoom(3);
    view.setCenter(0, 0);

    return view;
}

protected OLImageWMSSourceOptions createSptaImageSource()
{
    OLImageWMSSourceOptions options = new OLImageWMSSourceOptions();
    // options.setUrl("http:" + getApplication().getAimeServerUrl()
    // + "/geoserver/SPTA/wms");
    options.setUrl("http://localhost:8080/geoserver/SPTA/wms");

    Map<String, String> params = new HashMap<String, String>();
    params.put("LAYERS", "SPTA:spta");
    params.put("FORMAT", "image/png");
    // params.put(
    // "bbox",
    // "51.15011747003079%2C-2.1915973960504687%2C51.31302800327667%2C-1.6000229379737738");
    // params.put(
    // "BBOX",
    // "51.15011747003079 : 51.31302800327667, -2.1915973960504687 : -1.6000229379737738");
    options.setParams(params);

    // SRSEnvelope[-11.546630859375 : 11.546630859375, -21.09375 : 21.09375]
    return options;
}

protected OLImageWMSSourceOptions createTestSource()
{
    AimeLogger
            .getLogger()
            .info("*********************** USING TEST CREATE TEST SOURCE ROUTINE ***********************");
    OLImageWMSSourceOptions options = new OLImageWMSSourceOptions();
    // WebMapService of World http://www.osm-wms.de/
    options.setUrl("http://129.206.228.72/cached/osm");
    Map<String, String> params = new HashMap<String, String>();
    params.put("LAYERS", "osm_auto:all");
    params.put("FORMAT", "image/png");
    options.setParams(params);
    return options;
}

private OLSource createVectorSource()
{
    OLVectorSource source = new OLVectorSource();
    source.addFeature(createPointFeature(-50, 0));
    source.addFeature(createPointFeature(50, 0));
    source.addFeature(createPointFeature(-50, 50));
    source.addFeature(createPointFeature(50, 50));
    source.addFeature(createRectangleFeature("rect", -50, 0, 100, 50));
    return source;
}

private OLGeometry createPointFeature(double x, double y)
{
    return new OLPoint(x, y);
}

private OLFeature createRectangleFeature(String id, double x, double y,
        double width, double height)
{
    OLFeature testFeature = new OLFeature(id);
    OLLineString lineString = new OLLineString();
    lineString.add(new OLCoordinate(x, y));
    lineString.add(new OLCoordinate(x + width, y));
    lineString.add(new OLCoordinate(x + width, y + height));
    lineString.add(new OLCoordinate(x, y + height));
    lineString.add(new OLCoordinate(x, y));
    testFeature.setGeometry(lineString);
    return testFeature;
}

private void createMapControls()
{
    map.setMousePositionControl(new OLMousePositionControl());
    map.getMousePositionControl().projection = Projections.EPSG4326;
    map.setScaleLineControl(new OLScaleLineControl());
}

private void configureMap(MapConfiguration newPosition)
{
    // googleMap.setCenter(newPosition);
    // googleMap.setZoom(newPosition.getZoomLevel());
}

@Override
public void entityUpdateCallback(BaseEntity ent, DataHolder encoder)
{

    // Get the entity ID
    EntityID id = new EntityID();

    // if ((ent.getEntityID(id)) && (map != null)
    // && (encoder instanceof GccLocationEncoder))
    // {
    // // Try to locate the marker
    // GoogleMapMarker marker = findMarker(id);
    //
    // if (marker == null)
    // {
    // addMarkerToMap(id, ent);
    // }
    // else
    // {
    // // Just reposition the marker
    // // Get the location
    // LatLon latlon = getLocation(ent);
    //
    // // Move the marker
    // marker.setPosition(latlon);
    // }
    // }
}

@Override
public void entityCreationCallback(BaseEntity ent)
{
    // Get the entity ID
    EntityID id = new EntityID();

    // if ((ent.getEntityID(id)) && (googleMap != null))
    // {
    // addMarkerToMap(id, ent);
    // }

}

private void addMarkerToMap(EntityID id, BaseEntity ent)
{
    // Get the marking
    String marking = ent.getMarkingText();

    // Get the location
    LatLon latlon = getLocation(ent);

    // Get the icon
    String icon = MilStd2525.getSymbolIDFor(ent);

    // Create a marker
    GoogleMapMarker marker = new GoogleMapMarker(marking, latlon, false);
    if ((getApplication() != null)
            && (getApplication().getAimeServerUrl() != null))
    {
        marker.setIconUrl(getApplication().getAimeServerUrl()
                + AimeWebServlet.getMilStd2525ServletPath()
                + File.separator + icon);
    }
    else
    {
        AimeLogger
                .getLogger()
                .info("[AIME GOOGLE MAPS] Unable to locate path to AIME - using localhost");
        marker.setIconUrl("http://localhost:8080"
                + AimeWebServlet.getMilStd2525MappingPath()
                + File.separator + icon);
    }

    // Set the id
    marker.setId(id.hashCode());

    // Turn of the animation
    marker.setAnimationEnabled(false);

    // Add the marking to the map
    // googleMap.addMarker(marker);
}

private LatLon getLocation(BaseEntity ent)
{
    // Get the entity position
    LatLonAltPoint point = new LatLonAltPoint(ent);
    LatLon latlon = new LatLon(point.getLatitude(), point.getLongitude());
    return latlon;
}

@Override
public void entityDestructionCallback(BaseEntity ent)
{
    // Get the entity ID
    EntityID id = new EntityID();

    // if ((ent.getEntityID(id)) && (googleMap != null))
    // {
    // // TRy to locate the marker
    // GoogleMapMarker marker = findMarker(id);
    //
    // if (marker != null)
    // {
    // // Remove the marker
    // googleMap.removeMarker(marker);
    // }
    // else
    // {
    // // do nothing
    // }
    // }
}

private synchronized GoogleMapMarker findMarker(EntityID id)
{
    GoogleMapMarker marker = null;
    // if (googleMap != null)
    // {
    // for (GoogleMapMarker currentMarker : googleMap.getMarkers())
    // {
    // if (currentMarker.getId() == id.hashCode())
    // {
    // marker = currentMarker;
    // break;
    // }
    // }
    // }

    return marker;
}

@Override
public void mapMoved(int zoomLevel, LatLon center, LatLon boundsNE,
        LatLon boundsSW)
{
    if (getApplication() != null)
    {
        // The map has moved. Save the new location
        getApplication().getConfiguration().put(ZOOM_LEVEL,
                String.valueOf(zoomLevel));
        getApplication().getConfiguration().put(LATITUDE,
                String.valueOf(center.getLat()));
        getApplication().getConfiguration().put(LONGITUDE,
                String.valueOf(center.getLon()));
        getApplication().save();
    }
}

private class MapConfiguration extends LatLon
{
    private int zoomLevel = 4;

    // private GoogleMap.MapType mapType = GoogleMap.MapType.Roadmap;

    public MapConfiguration(double lat, double lon, int zoom,
            GoogleMap.MapType mapType)
    {
        setLat(lat);
        setLon(lon);
        this.zoomLevel = zoom;
        // this.mapType = mapType;
    }

    public MapConfiguration(Map<String, String> configuration)
    {
        // Is there any configuration
        if (configuration != null)
        {
            try
            {
                String strLat = configuration.get(LATITUDE);
                String strLon = configuration.get(LONGITUDE);
                String strZoom = configuration.get(ZOOM_LEVEL);

                if ((strLat != null) && (strLon != null)
                        && (strZoom != null))
                {
                    setLat(Double.parseDouble(strLat));
                    setLon(Double.parseDouble(strLon));
                    zoomLevel = Integer.parseInt(strZoom);
                }
                else
                {
                    throw new NumberFormatException();
                }

            }
            catch (NumberFormatException nfe)
            {
                setLat(RprProperties.getSingleton().getLatitudeOriginDeg());
                setLon(RprProperties.getSingleton().getLongitudeOriginDeg());
            }
        }
    }

    public int getZoomLevel()
    {
        return zoomLevel;
    }
}

protected void resetView()
{
    map.getView().setCenter(0, 0);
    map.getView().setZoom(1);
}

protected AbstractLayout createControls()
{
    HorizontalLayout controls = new HorizontalLayout();
    controls.setSpacing(true);
    controls.setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    Button button = new Button("Reset view");
    button.addClickListener(new Button.ClickListener()
    {
        @Override
        public void buttonClick(Button.ClickEvent event)
        {
            resetView();
        }
    });
    controls.addComponent(button);
    button = new Button("Show view state");
    button.addClickListener(new Button.ClickListener()
    {
        @Override
        public void buttonClick(Button.ClickEvent event)
        {
            OLCoordinate center = map.getView().getCenter();
            StringBuilder message = new StringBuilder();
            message.append("center: ").append(center.toText()).append("\n");
            message.append("rotation: ")
                    .append(map.getView().getRotation()).append("\n");
            message.append("zoom: ").append(map.getView().getZoom())
                    .append("\n");
            message.append("resolution: ")
                    .append(map.getView().getResolution()).append("\n");
            Notification.show(message.toString());
        }
    });
    controls.addComponent(button);
    button = new Button("Toggle map visibility");
    button.addClickListener(new Button.ClickListener()
    {
        @Override
        public void buttonClick(Button.ClickEvent event)
        {
            map.setVisible(!map.isVisible());
        }
    });
    controls.addComponent(button);
    return controls;
}

}

Note I've comment out the default TileLayer (which does work) and renders a Internet source map. If I use my createImageLayer(createImageSource()) implementation then --> No map.

Is it a bug? or a PICINC? Any help would be very greatly appreciated.

Mike

jobsonm commented 9 years ago

Resolved. Not sure what I've done but it seems to be working now. Not changed any of the code base or played around GeoServer but all I've got a map from a WMS. May be it was a good old fashioned reboot....

Styp commented 9 years ago

I am gglad you fixed it! I was not able to reproduce it... Could you poste the config or give a few hints in which direction you tried to change your GeoServer config?