maps icon indicating copy to clipboard operation
maps copied to clipboard

Add API for other apps to show locations on the map

Open MeiKatz opened this issue 2 years ago • 9 comments

Hej, first things first: I am grateful that there is a maps app for NextCloud. But IMHO it could be a lot more useful if other apps could provide locations to show in the Maps app. For example the contacts app has the ability to show contacts from other sources (not only the contacts in the app itself and from the Mail app).

My use case is, that we have a lot of facilities that we manage in an own app. It would be nice if we could view them in the Maps app. Currently we could provide them via the Contacts app but there is no way to show only our facilities.

Is there any way to add this feature? Or any point to start off so I could add this feature by myself? As it is an API endpoint I guess there should be some thoughts about the definition of the endpoint.

MeiKatz avatar Aug 27 '22 15:08 MeiKatz

Hej MeiKatz, I like your Idea, sofar I haven't thought about this kind of Interface for other apps, but its definitely worth a thought. The maps app only shows certain hard-coded objects (favorites/ Contacts/ Photos/ Tracks/ Devices). I haven't thought about how to abstract this. Which would be the first step for an API. So for each of this objects there is code in different places:

  • backend
    • storage on the database and filesystem (see mymaps branch)
    • Extraction of the information from file system or contacts app
    • Endpoints (For adding removing and editing them)
  • fronted code:
    • Render them on the map
    • Create navigation Items
    • Right click menu
    • Sidebar content So all this would need to be controllable by the API.

But if your intention was just to show your Facilities as one of this hard-coded objects, then you could use exiting filters and API's. contacts Then you could use different groups to only show facilities or different kinds of facilities. favorites Then you could use favorite categories to filter on them. We could thing about linking thumbnails to favorites to show favorites with thumbnail.

@eneiluj : Any other thoughts/ Ideas?

tacruc avatar Aug 27 '22 18:08 tacruc

Hej Tacruc,

thanks for your quick response. Actually I thought about something like the unified search provider for this issue. But I am not sure how an NC app could make an own provider available for other apps. I guess the apps must check for the existence of an interface like OCA\Maps\ILocationProvider and if defined fetch the context instance and register its own location provider. Then we could use a single API endpoint for the frontend. Rendering staff on the frontend should be the easy part of it all.

MeiKatz avatar Aug 27 '22 18:08 MeiKatz

@eneiluj Do you have any experience in how to implement something like this? Maybe we could have a meeting to discuss this?

tacruc avatar Aug 31 '22 11:08 tacruc

I started a discussion in the NextCloud forum on this topic because currently I don't know the best practices in NextCloud for this kind of problem: https://help.nextcloud.com/t/make-custom-app-api-available-via-custom-provider/144543

MeiKatz avatar Aug 31 '22 12:08 MeiKatz

@MeiKatz That's a great idea!

For the provider registration, as Maps is not part of the core (it's an app, duh) we won't be able to extend IRegistrationContext to provide a registerMapsLocationProvider method. But we can use events for that. The maps app could trigger an event like LoadLocationProviderEvent. Apps could listen to this event to register a provider.

If you want to see examples of that kind of mechanism, the Dashboard and the RichText widgets are doing similar stuff to let apps register stuff:

  • how Files registers a RichText widget https://github.com/nextcloud/server/pull/33755
  • how integration_gitlab registers a component for its Dashboard widget: https://github.com/nextcloud/integration_gitlab/blob/master/src/dashboard.js

Then, we need to think it properly from the beginning. We need to define what's a provider, what's a geolocated item. First questions that come to mind:

  • How flexible are we on how elements are rendered on the map?
  • How flexible are we on the navigation items? Should we allow providers to give a AppNavigationItemto give complete freedom or is a json description of the items enough and we render them generically in Maps?
  • Do we allow interaction with items on the map? Maybe not in a first iteration.

And then, some more limitations or difficulties. For example, do we clusterify the items on the map? If so, we need an abstract way to do so, the provider should define how to render a cluster.

We can provide support during development. I have limited time though. I'll try to be responsive.

julien-nc avatar Sep 02 '22 14:09 julien-nc

@eneiluj still had the idea that it might be a good idea, to maybe meet at the conference. Although I have not yet decided if I will be there. @MeiKatz are you there?

tacruc avatar Sep 02 '22 14:09 tacruc

@eneiluj I didn't talk about the IRegistrationContext of NC itself but about a Maps related own interface in the way that the interface of NC works.

But: I think the idea with the events is still a step better than my first thought. I like it!

@tacruc Yes, I am available. Just say some date and time for a conference and I try to join you.

MeiKatz avatar Sep 02 '22 15:09 MeiKatz

@MeiKatz Arne was talking about this conference :grin: https://nextcloud.com/blog/youre-invited-nextcloud-conference-on-october-1-2-in-berlin/

@MeiKatz Your registration solution would work as well and is pretty much equivalent to the event. The event allows the Maps app to decide if it wants to receive providers or not by emitting the event or not.

julien-nc avatar Sep 02 '22 15:09 julien-nc

@eneiluj My bad. No, unfortunally I am not in Berlin at the conference. Maybe we can meet up at some other time and place.

MeiKatz avatar Sep 12 '22 11:09 MeiKatz