Hitachi Vantara Pentaho Community Forums
Results 1 to 6 of 6

Thread: Color Legend for newMapComponent with Shapes.

  1. #1
    Join Date
    Aug 2010
    Posts
    11

    Default Color Legend for newMapComponent with Shapes.

    Hi

    I was able to plot a map with goe JSON file and color code with the values of the shape file. now i want to add a legend for colors of the shapes. there is an option in google overlay component to display and customize the legend.

    Can any explain on how to achieve this or display the legend in newMapComponent.

    Any help is greatly appreciated.

    Thanks
    Ram

  2. #2
    Join Date
    Jan 2014
    Posts
    189

    Default

    The NewMapComponent does not currently support a legend.
    You can access the following JIRA ticket http://jira.pentaho.com/browse/CDE-867 to state your use cases and express which functionalities you would like to see in that component.

    Provided that enough people are looking for a certain feature, it is likely that such developments are moved higher in the priority queue.

    Assuming you cannot currently wait for that, the solution would be to append a div in postExecution.
    Something along the lines (for a numeric scale):

    Code:
    function(){
    
    var seriesModel = this.model.find("shapes").toJSON(); // The model contains "digested" data, namely
    var template = '<div class="map-legend-container"><div class="map-legend-min">{{extremes.fill.min}}</div>{{#colormap}}<div style="background-color:{{.}};">{{/colormap}}<div class="map-legend-max">{{extremes.fill.max}}</div></div>';
    
    var $legend = Mustache.render(template, seriesModel)
    this.placeholder().append($legend);
    
    }
    You'll obviously need to add a lot of CSS to get the legend render as you want.

    DISCLAIMER: I did not test the code above. You weren't expecting the full answer were you?
    Last edited by crusso; 09-27-2016 at 10:36 AM.

  3. #3
    Join Date
    Aug 2010
    Posts
    11

    Default

    Thank you crusso.

    I was looking for something to start with.

    i executed the above code, it says "Uncaught TypeError: Cannot read property 'render' of undefined". i can see the mustache.js file.Should i reference Mustache.js anywhere ?

    We also have Pentaho licenses for EE version. i will update the jira ticket with the functionality required.

    Thanks is advance for your help.

    thanks
    Ram

  4. #4
    Join Date
    Jan 2014
    Posts
    189

    Default

    Oh you probably need to wrap the whole thing around a require block:

    Code:
    function(){
    
    var seriesModel = this.model.find("shapes").toJSON(); // The model contains "digested" data, namely
    var template = '<div class="map-legend-container"><div class="map-legend-min">{{extremes.fill.min}}</div>{{#colormap}}<div style="background-color:{{.}};">{{/colormap}}<div class="map-legend-max">{{extremes.fill.max}}</div></div>';
    
    var me = this;
    require(["cdf/lib/mustache"], function(Mustache){
      var $legend = Mustache.render(template, seriesModel);
      me.placeholder().append($legend);
    });
    
    }

  5. #5
    Join Date
    Aug 2010
    Posts
    11

    Default

    Thank you Crusso.. it works. am adding css and few additional formatting to look like actual legend. i will post the code snipped once am done.

    thank you once again for you help...

    thanks
    Ram

  6. #6

    Default

    Hi Ramraj

    Could you copy the css files and the code of the function?

    Thanks

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.