【问题标题】:Display WMS layer in GWT-Openlayers在 GWT-Openlayers 中显示 WMS 层
【发布时间】:2016-09-02 19:35:57
【问题描述】:

我使用 GWT-Openlayers,我想在我的地图中添加一个 WMS 图层。代码如下:

    ...
    MapOptions defaultMapOptions = new MapOptions();
    defaultMapOptions.setNumZoomLevels(7);

    //Create a MapWidget
    MapWidget mapWidget = new MapWidget("700px", "700px", defaultMapOptions);

    GoogleV3Options gSatelliteOptions = new GoogleV3Options();
    gSatelliteOptions.setIsBaseLayer(true);
    gSatelliteOptions.setType(GoogleV3MapType.G_SATELLITE_MAP);
    GoogleV3 gSatellite = new GoogleV3("Google Satellite", gSatelliteOptions);

    mapWidget.getMap().addLayer(gSatellite);

    //Create a WMS layer as base layer
    WMSParams wmsParams = new WMSParams();
    wmsParams.setFormat("image/png");
    wmsParams.setLayers("topp:tasmania_state_boundaries");
    wmsParams.setStyles("");
    wmsParams.setParameter("transparent", "true");

    //create a WMS layer
    WMSOptions wmsLayerParams = new WMSOptions();
    wmsLayerParams.setUntiled();
    wmsLayerParams.setTransitionEffect(TransitionEffect.RESIZE);
    wmsLayerParams.setIsBaseLayer(false);

    String wmsUrl = "http://demo.opengeo.org/geoserver/wms";

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

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

    //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(new MousePosition()); 

    //Center and zoom to a location
    LonLat lonLat = new LonLat(146.7, -41.8);
    lonLat.transform(new Projection(ProjectionCode.LONGLAT.getEpsgCode()).getProjectionCode(),
            map.getProjection()); //transform lonlat to OSM coordinate system
    map.setCenter(lonLat, 6);
    ...

我使用了我在这个网站上找到的示例代码: http://demo.gwt-openlayers.org/gwt_ol_showcase/GwtOpenLayersShowcase.html

任何人都可以尝试,因为 wmsUrl 指向演示站点。

问题是 WMS 图层仅在我缩小到最外层缩放级别时出现。如果我尝试放大,它会再次消失。有什么想法吗?

【问题讨论】:

    标签: java gwt openlayers wms gwt-openlayers


    【解决方案1】:

    我找到了一个设置:

    wmsLayerParams.setDisplayOutsideMaxExtent(true);
    

    但我不明白为什么默认值不是真实值...

    【讨论】:

    • 我遇到了这个问题,当我同时设置 wmsLayerParams.setIsBaseLayer(true); wmsLayerParams.setDisplayOutsideMaxExtent(true);我根本看不到塔斯马尼亚边界层,即使我明确选择了所需的 wms 基础层。但作为非基础层,它正确显示
    【解决方案2】:

    您似乎没有正确设置缩放级别。您的缩放级别范围仅为 6-7。您已定义最大值。缩放为 7。defaultMapOptions.setNumZoomLevels(7); 并将地图以缩放级别 6 居中。map.setCenter(lonLat, 6); 因此地图仅在缩放级别 6 和 7 之间显示。 将setNumZoomLevels 提高到更高的值可能会有所帮助。

    【讨论】:

      猜你喜欢
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多