Combining data source in UIViewMap to display different Types

Has anyone tried to pass two different datasources (fetching each a different Type) to a UIViewMap before? I know I can pass a complex json object to the map with the data property, but the map only has one latitude and one longitude field to use for display ?

You can probably accomplish this by using a local data source:

ui module MyApp {
    dataSource DataSourceC {
        "record": false,
        "collection": true,
        "localData": true
    }
}

At the page level you can add a listener to the data sources:

{
  "query": "MyApp.DataSourceA",
  "trigger": "loaded",
  "action": {
    "type": "UIActionCombineDataSourceAandB"
  }
}

Then in UIActionCombineDataSourceAandB:

function dispatch(page, e) {
  var environment = this.get("environment"),
  collectionA = environment.getDataSource("MyApp.DataSourceA"),
  collectionB = environment.getDataSource("MyApp.DataSourceB"),
  collectionC = env.getDataSource('MyApp.DataSourceC');

  collectionC.trigger('loading')

  //some logic here that combines A and B and sets the data in C

  collectionC.trigger('loaded')
}
1 Like

Thank you for your answer Sean, will I be able to change the icon to display the two Type differently ?

I think that’s more a question of the component than the data sources. Try this first, then see what appears. If it’s not what you want, then you’ll have to edit the js in the component. Thankfully it’s just a type so you can remix it as desired.

Ok I’m trying it out now, I’ll let you know how that goes :slightly_smiling_face:

@CharlesI did this work for you?

I had another thought that might be easier…you create an extendable dummy type that each of your types extend. Then by fetching the dummy type you’ll receive both types.

Hi @sean.summers unfortunately I had to continue on the rest of the UI and put that part aside. I think the solution is likely to work -and as you said I will probably have to remix the UIViewMap to alter the display behavior for my need. I’ll come back to this as soon as possible, and will keep you posted.