SetMapLegend

Hi
I am trying to use the setMapLegend method in MapViewer to create a map legend. But there is only headlines for each symbol not the symbol itself that is written. I post the code below. What could be wrong so the symbols are not written?
String imageMapUrl = "";
MapViewer mv = new MapViewer("mymapurl");
mv.setImageFormat(MapViewer.FORMAT_GIF_URL);
mv.setDataSourceName("mydatasource");
String [][][]legenddata = new String[1][][]; // legend with one column
legenddata[0] = new String[8][]; // column with 8 items
for(int i=0;i<8;i++)
legenddata[0] = new String[5]; // description of each item
legenddata[0][i][0] = null; // text
legenddata[0][i][1] = null; // style
legenddata[0][i][2] = "false"; // is title
legenddata[0][i][3] = null; // tab
legenddata[0][i][4] = "false"; // is separator
// <entry text="Map Legend" is_title="true" />
legenddata[0][0][0] = "Map Legend"; // text
legenddata[0][0][2] = "true"; // is title
// <entry style="M.STAR" text="center point" />
legenddata[0][1][0] = "center point"; // text
legenddata[0][1][1] = "M.STAR"; // style
// <entry style="M.CITY HALL 3" text="cities" />
legenddata[0][2][0] = "cities"; // text
legenddata[0][2][1] = "M.CITY HALL"; // style
// <entry is_separator="true" />
legenddata[0][3][4] = "true"; // is separator
// <entry style="C.ROSY BROWN STROKE" text="state boundary" />
legenddata[0][4][0] = "state boundary"; // text
legenddata[0][4][1] = "C.ROSY BROWN STROKE"; // style
// <entry style="L.PH" text="interstate highway" />
legenddata[0][5][0] = "interstate highway"; // text
legenddata[0][5][1] = "L.PH"; // style
// <entry text="County population:" />
legenddata[0][6][0] = "County population:"; // text
// <entry style="V.COUNTY_POP_DENSITY" tab="1" />
legenddata[0][7][1] = "V.COUNTY_POP_DENSITY"; // style
legenddata[0][7][3] = "1"; // tab
mv.setMapLegend("#ffffff","255","#ff0000","MEDIUM",
"NORTH_EAST",legenddata);
try{
boolean res = mv.run();
if(res)
imageMapUrl = mv.getGeneratedMapImageURL();
}catch(Exception ex){}

Hi,
some items based on your code that you should check:
1) Assuming MapViewer url is defined on a String variable 'mymapurl' you should use: MapViewer mv = new MapViewer(mymapurl);
2) It seems that the legend initialization code ('for') does not compile. It should be:
    for(int i=0;i<8;i++)
      legenddata[0] = new String[5]; // description of each item
legenddata[0][i][0] = null; // text
legenddata[0][i][1] = null; // style
legenddata[0][i][2] = "false"; // is title
legenddata[0][i][3] = null; // tab
legenddata[0][i][4] = "false"; // is separator
3) After compiling this code, and having it pointing to the demo dataset that comes with MapViewer, the legend is rendered with success. So verify if your datasource has the styles defined.
Joao

Similar Messages

  • Embedded Legend in JSP file

    I would like to embed my legend within my map request. I can display the legend on my page within a Table Row, but I would prefer it located inthe Southwest corner of my map image. Can this be done? I have seen it in XML done this way.
    Here is my legend code as well as my map display code.
    Thanks!
    <tr><td><mv:makeLegend id="myLegend">
    <legend bgstyle="fill:#ffffff;stroke:#ff0000" profile="SMALL" position="SOUTHWEST">
    <column>
    <entry text="Map Legend:" is_title="true" />
    <entry style="M.GREEN" text="No Outages Reported" />
    <entry style="M.RED" text="Outage Reported" />
    <entry style="M.AMBER" text="Degraded Status Reported" />
    </column>
    </legend>
    </mv:makeLegend>
    <IMG SRC="<%=myLegend%>"></td></tr>
    <tr align="center">
    <td valign="top" align="center">
    <input type="image"
    border="1"
    src="<mv:getMapURL />"
    name="userClick"
    alt="Click on the map for selected action">
    </td></tr>

    Hi,
    you can't use the makeLegend tag to embed it on map, but you can add an API method on your jsp code to add the legend. This is an example:
    <%@ taglib uri="http://xmlns.oracle.com/j2ee/jsp/tld/spatial/mvtaglib.tld" prefix="mapviewer"%>
    <%@ page contentType="text/html;charset=windows-1252"%>
    <%@ page import="oracle.lbs.mapclient.MapViewer" %>
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
        <title>untitled</title>
      </head>
      <body title="MapViewer WebMap">
        <DIV align="center">
          <mapviewer:init url="http://stadb35.us.oracle.com:8888/mapviewer/omserver" datasource="mvdemo" id="mvHandle"/>
          <mapviewer:setParam basemap="density_map" width="600" height="450" antialiasing="true" title="My Web Map" centerX="-122.4" centerY="37.8" size="10"/>
        <%
          MapViewer mv = (MapViewer) session.getAttribute("mvHandle");
          mv.setMapLegend("<legend bgstyle=\"fill:#ffffff;stroke:#ff0000\" " +
                          "profile=\"MEDIUM\" position=\"SOUTHWEST\">\n" +
                          "<column>\n" +
                          "<entry text=\"Map Legend:\" is_title=\"true\" />\n " +
                          "<entry style=\"V.COUNTY_POP_DENSITY\" tab=\"1\"/>\n " +
                          "</column>\n " +
                          "</legend>");
        %>
          <mapviewer:run/>
        </DIV>
        <img src="<mapviewer:getMapURL />"/>
      </body>
    </html>

  • Mapviewer demo mapinit.jsp with svg doesn't work with jdeveloper

    hi ng,
    i tried the source code for the svg-sample in jdeveloper and first of all jdeveloper dislikes the line "<embed id="map" src="<%= mv.getGeneratedMapImageURL() %>...". after "embed" a green line is to be seen.
    When i start the sample the map looks okay, but when i want to hide a theme (or zoom), i get the internet_explorer-message "error on the page".
    "themeVisibleArray[idx]='false';" goes right but the next line occurs the error: "map.window.hideTheme(theme) ;"
    map is not known at this place, it seems to me.
    who can help (please)?
    greetings
    thomas

    hi,
    i still have a problem. i can work on an existing svg-map but not on a just generated svg-map. zoomin2 works.
    here's the code:
    <%@ taglib uri="http://xmlns.oracle.com/j2ee/jsp/tld/spatial/mvtaglib.tld" prefix="mapviewer"%>
    <%@ page contentType="text/html;charset=UTF-8"%>
    <%@ page import="java.io.*"%>
    <%@ page import="java.net.*"%>
    <%@ page import="java.util.*"%>
    <%@ page import="oracle.lbs.mapclient.*"%>
    <%@ page import="oracle.lbs.mapcommon.MapResponse"%>
    <%@ page import="java.awt.Dimension"%>
    <%
    String sizeStr = request.getParameter("initsize") ;
    String scaleStr = request.getParameter("scale") ;
    String cxStr = request.getParameter("centerX") ;
    String cyStr = request.getParameter("centerY") ;
    String baseMap = request.getParameter("basemap");
    String _width = request.getParameter("width") ;
    String _height = request.getParameter("height") ;
    String _infoon = request.getParameter("infoon") ;
    String action = request.getParameter("action");
    boolean infoon = false;
    boolean recenter = false ;
    boolean zoomin = false ;
    boolean zoomin2 = false ;
    int width = 600 ;
    int height = 400 ;
    if(_width!=null && _height!=null)
    try
    width = Integer.parseInt(_width) ;
    catch(Exception e){}
    try
    height = Integer.parseInt(_height) ;
    catch(Exception e){}
    if(baseMap==null) baseMap = "demo_map";
    double size = 0.2 ;
    try
    size = Double.parseDouble(sizeStr) ;
    catch(Exception e){}
    double scale = 2 ;
    try
    scale = Double.parseDouble(scaleStr) ;
    catch(Exception e){}
    double cx = -122.2615 ;
    try
    cx = Double.parseDouble(cxStr) ;
    catch(Exception e){}
    double cy = 37.5266 ;
    try
    cy = Double.parseDouble(cyStr) ;
    catch(Exception e){}
    String dataSrc = request.getParameter("datasrc");
    boolean newSession = false;
    // retrieve mapviewer client handle from session
    MapViewer mv = (MapViewer) session.getAttribute("mvhandle");
    boolean sessionExpired = false ;
    if(mv==null || request.getParameter("initflag")!=null)
    if(request.getParameter("initflag")==null)
    sessionExpired = true ;
    else
    //initializes MapViewer bean instance
    newSession = true;
    String mvURL = request.getParameter("mvurl");
    // create a new mapviewer client handle
    mv = new MapViewer(mvURL);
    mv.setDataSourceName(dataSrc);
    mv.setImageFormat(MapResponse.FORMAT_SVGZ_URL);
    /* the javascript function svgClicked will be called when the svg map
    is clicked. svgClicked is defined in this page, it recenters or zoomins
    the map. */
    mv.setSVGOnClick("svgClicked") ;
    /* initial themes (from an existing base map) */
    mv.addThemesFromBaseMap(baseMap);
    mv.setSVGZoomLevels(3);
    /* disable the builtin navigation bar */
    mv.setShowSVGNavBar(false) ;
    mv.setMapTitle(" MAP TITLE ");
    mv.setMapLegend(
    "<legend bgstyle=\"fill:#ffffff;stroke:#ff0000\" profile=\"MEDIUM\" position=\"SOUTH_EAST\">"+
    " <column>"+
    " <entry text=\"Map Legend\" is_title=\"true\" />"+
    " <entry style=\"M.CITY HALL 3\" text=\"cities\" />"+
    " <entry style=\"M.CITY HALL 4\" text=\"big cities\" />"+
    " <entry style=\"L.PH\" text=\"interstate highway\" />"+
    " </column></legend>");
    mv.setDeviceSize(new Dimension(width, height));
    session.setAttribute("mvhandle", mv); // keep client handle in the session
    String themes[] = new String[0] ;
    if(!sessionExpired)
    themes = mv.getThemeNames() ;
    mv.setCenter(cx, cy);
    mv.setSize(size);
    mv.setSVGZoomRatio(scale) ;
    mv.setSVGShowInfo(infoon);
    String[] checkedThemes = request.getParameterValues("_mthemev_");
    if(checkedThemes!=null && checkedThemes.length>0)
    Hashtable checked = new Hashtable(30) ;
    for(int i=0; i<checkedThemes.length; i++)
    checked.put(checkedThemes, checkedThemes[i]) ;
    for(int i=0; i<themes.length; i++)
    if(checked.get(themes[i])!=null)
    mv.setThemeVisibleInSVG(themes[i], true);
    else
    mv.setThemeVisibleInSVG(themes[i], false) ;
    mv.run() ;
    %>
    <html>
    <head>
    <title>untitled</title>
    <%-- <embed id="map" name="map" src="<%= mv.getGeneratedMapImageURL() %>" width="<%= width %>" height="<%= height %>"></embed> --%>
    <%-- src="images/omsmap3_56.svgz" --%>
    <%-- src="<%= mv.getGeneratedMapImageURL() %>" --%>
    <%-- <object name="map" data="images/test_svg.svgz" type="image/svg+xml" width="800" height="600" standby="Warte noch ein Weilchen..."> --%>
    <%-- </object> --%>
    <script type="text/javascript">
    var mapSize = <%= size %> ;
    var scale = <%= scale %> ;
    var width=<%= width%> ;
    var height=<%= height%> ;
    var rcx = <%= cx %> ;
    var rcy = <%= cy %> ;
    var cx = <%= width/2%> ;
    var cy = <%= height/2%> ;
    var disabled = true ;
    // var themeVisibleArray = ...
    var info = <%= infoon %> ;
    var legend = false ;
    var clickZoomin = <%= zoomin %> ;
    var clickRecenter = <%= recenter %> ;
    function zoomin()
    map.window.setZoomRatio(1.1);
    function zoomin2()
    map2.window.setZoomRatio(1.1);
    </script>
    </head>
    <body>
    <P>
    <form method="GET" action="test2.jsp">
    <P>Name:
    <input type="text" size="60" name="name" value="<%= mv.getGeneratedMapImageURL() %>"/>
    <input type="text" size="60" name="datasrc" value="<%= request.getParameter("datasrc") %>"/>
    <input type="text" size="60" name="basemap" value="<%= request.getParameter("basemap") %>"/>
    <input type="text" size="60" name="centerX" value="<%= request.getParameter("centerX") %>"/>
    <input type="text" size="60" name="centerY" value="<%= request.getParameter("centerY") %>"/>
    <input type="text" size="60" name="initsize" value="<%= request.getParameter("initsize") %>"/>
    <input type="text" size="60" name="width" value="<%= request.getParameter("width") %>"/>
    <input type="text" size="60" name="height" value="<%= request.getParameter("height") %>"/>
    <input type="text" size="60" name="type" value="<%= request.getParameter("type") %>"/>
    </P>
    <P>
    <input type="SUBMIT" value="Submit"/>
    </P>
    </form>
    </P>
    <table>
    <tr>
    <td colspan="2">
    <I>URL</I>[<B><%=mv.getGeneratedMapImageURL()%></B>]
    </td>
    </tr>
    </table>
    <%-- images/test_svg.svgz --%>
    <embed src="<%= mv.getGeneratedMapImageURL() %>" name="map" id="map" width="500" height="500" type="image/svg+xml" />
    <embed src="images/test_svg.svgz" name="map2" id="map2" width="500" height="500" type="image/svg+xml" />
    <%-- <embed id="map" src="<%= mv.getGeneratedMapImageURL() %>" width="<%= width %>" height="<%= height %>"></embed> --%>
    <FORM name="form" action="test2.jsp" method="GET" >
    <input type="radio" name="action" value="zoomin" <%= zoomin?"checked":"" %> onclick="zoomin()" ><B>Zoom In</B>
    <input type="radio" name="action2" value="zoomin2" <%= zoomin2?"checked":"" %> onclick="zoomin2()" ><B>Zoom In2</B>
    <input type="hidden" name="width" value="<%=width%>"/>
    <input type="hidden" name="height" value="<%=height%>"/>
    <input type="hidden" id="cx" name="centerX" value=""/>
    <input type="hidden" id="cy" name="centerY" value=""/>
    <input type="hidden" id="size" name="initsize" value=""/>
    <input type="hidden" id="scale" name="scale" value=""/>
    <input type="hidden" id="infoon" name="infoon" value="<%=(infoon?"yes":"no")%>" />
    </FORM>
    <br>
    <P> 
    </P>
    </body>
    </html>

  • MapViewer Legend

    Hallo,
    I am dealing with mapviewer and the legend.
    1: I can create a legend by defining each theme and the symbol I use for this. But is there a way that the legend is defined "automaticlly" so that I do not have to define each theme but mapviewer knows which themes are in this map and generates?
    2: I can position the legend with position="NORTH_WEST". Are there other way to position it? By using numbers?
    3: Are there code samples and where I could use?
    4: I can not change the font of the text in the legend?
    Thanks in advance Tig

    Hi Tig,
    Currently you can't generate the automatic legend based on the themes, and also you can't define a location (X,Y) to put the legend. We'll add these items on the enhancement list.
    For item 4, MapViewer parses the legend font, however the API method setMapLegend does not have this parameter. We'll also add this enhancement. If you issue a XML request directly, you can define the font as:
    <legend bgstyle="fill:#ffffff;fill-opacity:128;stroke:#ff0000"
              position="NORTH_WEST" font="Dialog">Next, is a sample of Java code to generate the structure to pass to the API method setMapLegend:
      String [][][]legenddata = new String[1][][];  // legend with one column
      legenddata[0] = new String[8][];    // column with 8 items
      for(int i=0;i<8;i++)
        legenddata[0] = new String[5]; // description of each item
    legenddata[0][i][0] = null; // text
    legenddata[0][i][1] = null; // style
    legenddata[0][i][2] = "false"; // is title
    legenddata[0][i][3] = null; // tab
    legenddata[0][i][4] = "false"; // is separator
    // <entry text="Map Legend" is_title="true" />
    legenddata[0][0][0] = "Map Legend"; // text
    legenddata[0][0][2] = "true"; // is title
    // <entry style="M.STAR" text="center point" />
    legenddata[0][1][0] = "center point"; // text
    legenddata[0][1][1] = "M.STAR"; // style
    // <entry style="M.CITY HALL 3" text="cities" />
    legenddata[0][2][0] = "cities"; // text
    legenddata[0][2][1] = "M.CITY HALL"; // style
    // <entry is_separator="true" />
    legenddata[0][3][4] = "true"; // is separator
    // <entry style="C.ROSY BROWN STROKE" text="state boundary" />
    legenddata[0][4][0] = "state boundary"; // text
    legenddata[0][4][1] = "C.ROSY BROWN STROKE"; // style
    // <entry style="L.PH" text="interstate highway" />
    legenddata[0][5][0] = "interstate highway"; // text
    legenddata[0][5][1] = "L.PH"; // style
    // <entry text="County population:" />
    legenddata[0][6][0] = "County population:"; // text
    // <entry style="V.COUNTY_POP_DENSITY" tab="1" />
    legenddata[0][7][1] = "V.COUNTY_POP_DENSITY"; // style
    legenddata[0][7][3] = "1"; // tab
    mapViewer.setMapLegend("#ffffff","255","#ff0000","MEDIUM","NORTH_EAST",legenddata);
    Thanks for your comments.
    Joao

Maybe you are looking for

  • How to close a pop up window of used component ( usage defined )

    Hi Friends , I'm calling a window as a pop up of used component ( Usage defined ). I want to close that pop up using a button on the embedded view of that window. it would be great help If any one can help me in this. Regards, Laeeq

  • Request time out - zip file processing in sharepoint 2010

    Hello All, I have developed web part that uploads the zip package file and then programmatically zip will extracted and all files will uploaded to picture library. If zip files are larger then it gets request timed out error..in production server. Cu

  • Can't open the illustration could not complete the requested operation

    I have a really big problem with an illustrator file which i can't open. As the file was saved Adobe Illustrator unexpected closed down during the saving process which damaged the file. The corrupted file size is still big (368mb) and if i open the f

  • Usage

    Hiya all, Just checked my usage and it's nearly 200Gb just goes to show how much you use with an ipad2 + galaxy tab I'm on option2 so it's not a problem but it just go to show how fast your usage goes up when using these items. Before I had either of

  • Advice required on TSCM62-- Certification

    I'm doing Online Training on SD TSCM60 & 62. Regards to preparing for certification, can anyone advice whether I need to concentrate only on theory or do I need to concentrate on working & solving on the excercises which are given in the books. How i