Giter Club home page Giter Club logo

Comments (4)

heshan0131 avatar heshan0131 commented on May 2, 2024

@gingerizer
The current behavior is intended. To make the config small and only include the neccessary part, mapStyle config will not include the default set of map styles, because they are constants that can be loaded later in the application. when exporting conifg, mapStyles will only contain the ones added by the user.

Is there a reason you want all the map styles to be saved in the config?

from kepler.gl.

gingerizer avatar gingerizer commented on May 2, 2024

My base configuration is such that I am not using any of the default map styles that are pre-configured as constants. Ideally I would be able to disable the use of these default maps (and the subsequent calls made to retrieve the styles) since I have configured my own. I'm working in an offline environment.

<KeplerGl
   mapboxApiAccessToken=""
   id="keplerMap"
   width={width}
   height={height}
   mapStyles={CUSTOM_MAP_STYLES}
/>

Since I have my own map styles configured as a custom set of default styles when I add new data to the map I have to re-set the map styles in the config. I was hoping that getMapConfig() would provide this set for me.

Sure I can add all of the default styles back to the config, however the user might have added their own custom styles that weren't in the default configuration and because I've updated the map with new data those changes would be lost- would they not?

If they aren't included in the config to keep it small then is there a way to access them for those that need it? Also, does that mean that mapStyles will always be empty? If so why bother including it in the config response?

from kepler.gl.

gingerizer avatar gingerizer commented on May 2, 2024

I've discovered a way to easily get the mapStyles. The method shown in visacademy is as such:

// This method is used as reference to show how to export the current kepler.gl instance configuration
  // Once exported the configuration can be imported using parseSavedConfig or load method from KeplerGlSchema
  getMapConfig() {
    // retrieve kepler.gl store
    const {keplerGl} = this.props;
    // retrieve current kepler.gl instance store
    const {map} = keplerGl;

    // create the config object
    return KeplerGlSchema.getConfigToSave(map);
  }

Essentially, the map object contains the desired mapStyles which need to be appended to what is returned from the getConfigToSave(map) which becomes:

// This method is used as reference to show how to export the current kepler.gl instance configuration
  // Once exported the configuration can be imported using parseSavedConfig or load method from KeplerGlSchema
  getMapConfig() {
    // retrieve kepler.gl store
    const {keplerGl} = this.props;
    // retrieve current kepler.gl instance store
    const {map} = keplerGl;

    // create the config object
    // return KeplerGlSchema.getConfigToSave(map);   // does not include any custom configured map styles
    let mapConfig = KeplerGlSchema.getConfigToSave(map);
    mapConfig.config.mapStyle = map.mapStyle;     // Add back the available map styles to the map config
  
    return mapConfig;
  }

from kepler.gl.

heshan0131 avatar heshan0131 commented on May 2, 2024

@gingerizer instead of passing mapStyles in as props at the component level, you can try configure the mapStyle reducer's inisitalState by calling keplerGlReducer.intialState() and pass in your set of mapStyles. You can take a look at this example

All you need to do is

const withUberMapStyles = keplerGlReducer.initialState({
  mapStyle: {
    // add your own map styles as default to mapStyle reducer
    // mapStyles needs to be an object with `id` as the key
    mapStyles: DEFAULT_MAP_STYLES.reduce((accu, curr) => ({
      ...accu,
      [curr.id]: curr
    }), {})
  }
})

from kepler.gl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.