mapbox / mapbox-plugins-android

Mapbox Android Plugins are a collection of libraries that extend our other SDKs, helping you design powerful mapping features while the plugins handle most of the heavy lifting.
https://www.mapbox.com/android-docs/plugins/overview/
BSD 2-Clause "Simplified" License
241 stars 119 forks source link

InfoWindow support / selected states #649

Open tobrun opened 6 years ago

tobrun commented 6 years ago

With #647 we are adding the abillity to react on symbol click events. An extended use-case of this is to introduce selected states and showing an InfoWindow as result of it.

jeffypooo commented 5 years ago

@tobrun any idea when this will get released? We briefly experimented with replacing our current marker/info window functionality with this plugin (and the marker view plugin), but could not figure out a clean way to do callouts. This is/was pretty easy to do with MapboxMap.setInfoWindowAdapter.

If this is low on the priority list we can try and implement and send a PR.

constantinevassil commented 5 years ago

Callout is essential basic functionality.

What I need is the following:

1) the user taps on the map. 2) the App gets lat/lng 3) lat/lng is searched in map features 4) from the feature the App gets several fields like Title, Description.

Looking at the code: https://github.com/mapbox/mapbox-android-demo/blob/master/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/dds/InfoWindowSymbolLayerActivity.java

I can load "us_west_coast.geojson" to get the initial structure and dynamically update the location and Title, Description, etc.

It seems if I call refreshSource and have featureCollection already populated with lat/lng, Title, Description, etc. I can do that.

private void refreshSource() { if (source != null && featureCollection != null) { source.setGeoJson(featureCollection); } }

Now the question is how to create new featureCollection dynamically?

tobrun commented 5 years ago

@masterjefferson I'm aware that this is highly requested feature and I would love to prioritize this but with other pieces moving, I can't say I will be able to pick this is up the near future. The idea is that a InfoWindow would be a SymbolLayer on it's own which contents are static and we would probably need to opt to create a SymbolLayer per InfoWindow.

@topinvestor the idea behind geojson is that the should be perceived as immutable. So you can create new FeatureCollection instances with the multiple static creator methods as FeatureCollection.fromFeatures.

constantinevassil commented 5 years ago

@tobrun "the idea behind geojson is that the should be perceived as immutable. So you can create new FeatureCollection instances with the multiple static creator methods as FeatureCollection.fromFeatures"

I think this is what we need - could you please point me to example or just copy paste the relevant code how to populate FeatureCollection for this purpose. If I know how to do that I can do it that way.

What was able to do is:

... private FeatureCollection featureCollection; private GeoJsonSource source;

... private void refreshSource(LatLng position) {

If I have just one feature I can get it as follows: // PROPERTY_NAME = "name"; name = featureList.get(0).getStringProperty(PROPERTY_NAME); // // PROPERTY_NAME = "description"; description = featureList.get(0).getStringProperty(PROPERTY_NAME); //

   featureList.get(0) is as follows:

Feature{type=Feature, bbox=null, id=null, geometry=Point{type=Point, bbox=null, coordinates=[-117.5952959, 33.6388097]}, properties={"marker-color":"#7e7e7e","marker-size":"medium","marker-symbol":"", "name":"California", "description":"Modern counter-service spot serving locally sourced, organic soups, sandwiches, bowls & baked goods.", }}

If call refreshSource and initialize source.setGeoJson with these fields: name, description and coordinates (with position.getLongitude() and position.getLongitude()), this is all what is needed to do it dynamically.

It is like this: Feature feature = Feature.fromGeometry(Point.fromLngLat(position.getLongitude(), position.getLatitude()) );

The new info: feature.addStringProperty(PROPERTY_NAME, name);

The new info:
feature.addStringProperty(PROPERTY_NAME, capital);

At the end:

new GenerateViewIconTask(MainActivity.this).execute(featureCollection);

Would update the pin and the callout info to new information

So basically I regenerate the bitmap with the new info and can see it on the map.

Would there be any side effects with new GenerateViewIconTask like memory leak, etc?

jeffypooo commented 5 years ago

@tobrun understood, we'll look into a symbol layer implementation. We may send over a PR for this 🤓

Sent with GitHawk

klblk commented 5 years ago

Is this supposed to be part of annotation-plugin? I am not interested in using plugin (does not solve my problems), but I use custom SymbolLayers and I need to show InfoWindow when clicking. Maybe my tasks are too specific and I have to suffer=)

mortezahosseinee commented 5 years ago

Hi everybody. i have a situation, need help. i add a marker to map and onMapClick get first feature from getProjection and show an info window with custom layout, i used map.setInfoWindowAdapter(marker -> { ... }) everythings is ok. now i upgrade mapbox version from 6.0.2 to 7.3.2. so i add symbol layer and i have same task. //show info window on click of symbol layer points that info window has custom layout. i can't proceed, so go to add marker approach and using setInfoWindowAdapter but i faced this: setInfoWindowAdapter is Depricated... and i searched it and get this : depricated com.mapbox.mapboxsdk.maps.MapboxMap.setInfoWindowAdapter(MapboxMap.InfoWindowAdapter) As of 7.0.0, use Mapbox Annotation Plugin instead: https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-annotation i can't get my goal with this link, anybody can help me?

LukasPaczos commented 5 years ago

@mortezahosseinee check out the already linked in this topic SymbolLayer example of how to implement an info window.

langsmith commented 5 years ago

@mortezahosseinee , https://docs.mapbox.com/android/maps/examples/symbol-layer-info-window/ is what the example that @LukasPaczos linked to above, looks like.

mortezahosseinee commented 5 years ago

Thank you for your attention. But I need show info window with custom layout, i saw these links ago. if you don't understand my point, tell me explain more.

LukasPaczos commented 5 years ago

@mortezahosseinee in this case, https://docs.mapbox.com/android/maps/examples/symbollayer-mapillary/ might be helpful - it shows how to convert a custom layout into a bitmap, supply it to the map and make it interactive.

langsmith commented 5 years ago

it shows how to convert a custom layout into a bitmap, supply it to the map and make it interactive.

https://docs.mapbox.com/android/maps/examples/symbol-layer-info-window/ also converts a custom layout to a bitmap

tobrun commented 5 years ago

Sorry for the delay on this feature. I have a small POC working:

ezgif com-video-to-gif (80)

To make this a supported SymbolManager feature we still need:

mrfaa commented 4 years ago

@tobrun Any update on this feature request?

I also need a supported SymbolManager Feature to display an InfoWindow above an Marker after clicking this marker.

Do you have the code from your POC?

brandikun commented 4 years ago

I would also really appreciate an update on this. I am working on a GIS-lite project on Android and I am starting to realize that most libraries including mapbox are just not meant for GIS functionality. If anyone sees this and has any other suggestions, please let me know.

OsamaMuhammad commented 4 years ago

@tobrun Any update on this feature request? I need to display a custom info window on symbol click.

TarasOsiris commented 4 years ago

Hello, it would be really great to have this functionality as a part of the plugin since the iOS annotations plugin supports this out of the box. (basically having title and subtitle in SymbolOptions)

wshihdehx commented 4 years ago

@tobrun Is there a reason why this feature hasn't been implemented since it was requested in 2018?

wshihdehx commented 4 years ago

Sorry for the delay on this feature. I have a small POC working:

ezgif com-video-to-gif (80)

To make this a supported SymbolManager feature we still need:

  • [ ] correct anchor placement of the callout that takes in account:

    • [ ] iconAnchor
    • [ ] iconSize
    • [ ] iconDimension
  • [x] put code into a plugin
  • [x] support style reloading
  • [x] support title/message API
  • [ ] support View based API
  • [ ] support fills and lines -> requires additional turf ports

Hey @tobrun do you know when will this go live?

wshihdehx commented 4 years ago

I looked into using the symbol layer example here but it's too messy, MapBox should be making things easy, why do we have to write so much boilerplate code for a simple info window?

@tobrun

https://github.com/mapbox/mapbox-android-demo/blob/master/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/dds/InfoWindowSymbolLayerActivity.java

wshihdehx commented 4 years ago

Hello, it would be really great to have this functionality as a part of the plugin since the iOS annotations plugin supports this out of the box. (basically having title and subtitle in SymbolOptions)

I know man, it's been 3 years already, talk about slow, these are very basic features, I love MapBox but seriously they need to get these things added in Google Maps API it's so easy to do these simple things without having to write too much boiler plate code

tir38 commented 4 years ago

@wshihdehx plz don't spam this repo with requests. Plz don't open other issues that do nothing but point back to this issue.

I know it looks like sometimes things move slowly, but take the time to see what has been worked on that was higher priority in the last three years. You can start by reviewing all commits in this repo:

https://github.com/mapbox/mapbox-plugins-android/commits/master

You should also look at contribution graphs of the main devs who do work on this project to see what else they spend their time on:

Lastly, this is an OS project so if you really want this feature, you can try to build it yourself. Read the contribution page for more info.

If you just want to show your interest in getting this built a simple 👍 on the OP would probably be worth more than your four comments.