Ejemplo n.º 1
0
  private static String generateHTML(
      TileLayer layer, String gridSetStr, String formatStr, boolean asPlugin)
      throws GeoWebCacheException {
    String layerName = layer.getName();

    GridSubset gridSubset = layer.getGridSubset(gridSetStr);

    BoundingBox bbox = gridSubset.getGridSetBounds();
    BoundingBox zoomBounds = gridSubset.getOriginalExtent();

    String res = "resolutions: " + Arrays.toString(gridSubset.getResolutions()) + ",\n";

    String units = "units: \"" + gridSubset.getGridSet().guessMapUnits() + "\",\n";

    String openLayersPath;
    if (asPlugin) {
      openLayersPath = "../openlayers/OpenLayers.js";
    } else {
      openLayersPath = "../openlayers/OpenLayers.js";
    }

    String page =
        "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head>\n"
            + "<meta http-equiv=\"imagetoolbar\" content=\"no\">\n"
            + "<title>"
            + layerName
            + " "
            + gridSubset.getName()
            + " "
            + formatStr
            + "</title>\n"
            + "<style type=\"text/css\">\n"
            + "body { font-family: sans-serif; font-weight: bold; font-size: .8em; }\n"
            + "body { border: 0px; margin: 0px; padding: 0px; }\n"
            + "#map { width: 85%; height: 85%; border: 0px; padding: 0px; }\n"
            + "</style>\n"
            + "<script src=\""
            + openLayersPath
            + "\"></script>    \n"
            + "<script type=\"text/javascript\">               \n"
            + "var map, demolayer;                               \n"
            + "  // sets the chosen modifiable parameter        \n"
            + "  function setParam(name, value){                \n"
            + "   str = \"demolayer.mergeNewParams({\" + name + \": '\" + value + \"'})\" \n"
            + "   // alert(str);                                   \n"
            + "   eval(str);                                    \n"
            + "  }                                              \n"
            + "OpenLayers.DOTS_PER_INCH = "
            + gridSubset.getDotsPerInch()
            + ";\n"
            + "OpenLayers.Util.onImageLoadErrorColor = 'transparent';\n"
            + "function init(){\n"
            + "var mapOptions = { \n"
            + res
            + "projection: new OpenLayers.Projection('"
            + gridSubset.getSRS().toString()
            + "'),\n"
            + "maxExtent: new OpenLayers.Bounds("
            + bbox.toString()
            + "),\n"
            + units
            + "controls: []\n"
            + "};\n"
            + "map = new OpenLayers.Map('map', mapOptions );\n"
            + "map.addControl(new OpenLayers.Control.PanZoomBar({\n"
            + "		position: new OpenLayers.Pixel(2, 15)\n"
            + "}));\n"
            + "map.addControl(new OpenLayers.Control.Navigation());\n"
            + "map.addControl(new OpenLayers.Control.Scale($('scale')));\n"
            + "map.addControl(new OpenLayers.Control.MousePosition({element: $('location')}));\n"
            + "demolayer = new OpenLayers.Layer.WMS(\n"
            + "\""
            + layerName
            + "\",\"../service/wms\",\n"
            + "{layers: '"
            + layerName
            + "', format: '"
            + formatStr
            + "' },\n"
            + "{ tileSize: new OpenLayers.Size("
            + gridSubset.getTileWidth()
            + ","
            + gridSubset.getTileHeight()
            + ")";

    /*
     * If the gridset has a top left tile origin, lets tell that to open layers. Otherwise it'll
     * calculate tile bounds based on the bbox bottom left corner, leading to misaligned
     * requests.
     */
    GridSet gridSet = gridSubset.getGridSet();
    if (gridSet.isTopLeftAligned()) {
      page +=
          ",\n tileOrigin: new OpenLayers.LonLat(" + bbox.getMinX() + ", " + bbox.getMaxY() + ")";
    }

    page +=
        "});\n"
            + "map.addLayer(demolayer);\n"
            + "map.zoomToExtent(new OpenLayers.Bounds("
            + zoomBounds.toString()
            + "));\n"
            + "// The following is just for GetFeatureInfo, which is not cached. Most people do not need this \n"
            + "map.events.register('click', map, function (e) {\n"
            + "  document.getElementById('nodelist').innerHTML = \"Loading... please wait...\";\n"
            + "  var params = {\n"
            + "    REQUEST: \"GetFeatureInfo\",\n"
            + "    EXCEPTIONS: \"application/vnd.ogc.se_xml\",\n"
            + "    BBOX: map.getExtent().toBBOX(),\n"
            + "    X: e.xy.x,\n"
            + "    Y: e.xy.y,\n"
            + "    INFO_FORMAT: 'text/html',\n"
            + "    QUERY_LAYERS: map.layers[0].params.LAYERS,\n"
            + "    FEATURE_COUNT: 50,\n"
            + "    Layers: '"
            + layerName
            + "',\n"
            + "    Styles: '',\n"
            + "    Srs: '"
            + gridSubset.getSRS().toString()
            + "',\n"
            + "    WIDTH: map.size.w,\n"
            + "    HEIGHT: map.size.h,\n"
            + "    format: \""
            + formatStr
            + "\" };\n"
            + "  OpenLayers.loadURL(\"../service/wms\", params, this, setHTML, setHTML);\n"
            + "  OpenLayers.Event.stop(e);\n"
            + "  });\n"
            + "}\n"
            + "function setHTML(response){\n"
            + "    document.getElementById('nodelist').innerHTML = response.responseText;\n"
            + "};\n"
            + "</script>\n"
            + "</head>\n"
            + "<body onload=\"init()\">\n"
            + "<div id=\"params\">"
            + makeModifiableParameters(layer)
            + "</div>\n"
            + "<div id=\"map\"></div>\n"
            + "<div id=\"nodelist\"></div>\n"
            + "</body>\n"
            + "</html>";
    return page;
  }