Android Mapbox Marker Labels





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-1















I'm trying to figure out how to make a dynamically generated list of markers display a dynamic text label on the map (not in the infoWindow). I know it's possible because I've used this feature in Mapbox Studio - I just can't figure out how to do it on Android! I considered creating a static Bitmap icon with the text incorporated, but that doesn't seem very flexible compared to the Mapbox Studio version, so I'd like to avoid it if I can! Any suggestions?










share|improve this question





























    -1















    I'm trying to figure out how to make a dynamically generated list of markers display a dynamic text label on the map (not in the infoWindow). I know it's possible because I've used this feature in Mapbox Studio - I just can't figure out how to do it on Android! I considered creating a static Bitmap icon with the text incorporated, but that doesn't seem very flexible compared to the Mapbox Studio version, so I'd like to avoid it if I can! Any suggestions?










    share|improve this question

























      -1












      -1








      -1








      I'm trying to figure out how to make a dynamically generated list of markers display a dynamic text label on the map (not in the infoWindow). I know it's possible because I've used this feature in Mapbox Studio - I just can't figure out how to do it on Android! I considered creating a static Bitmap icon with the text incorporated, but that doesn't seem very flexible compared to the Mapbox Studio version, so I'd like to avoid it if I can! Any suggestions?










      share|improve this question














      I'm trying to figure out how to make a dynamically generated list of markers display a dynamic text label on the map (not in the infoWindow). I know it's possible because I've used this feature in Mapbox Studio - I just can't figure out how to do it on Android! I considered creating a static Bitmap icon with the text incorporated, but that doesn't seem very flexible compared to the Mapbox Studio version, so I'd like to avoid it if I can! Any suggestions?







      android label mapbox mapbox-marker






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 24 '18 at 21:12









      Jake MaddenJake Madden

      8219




      8219
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You're trying to do what's called data-driven styling



          You should use a SymbolLayer to show text on a map. If the text you want to show is based on GeoJSON Features in your data set, then use the get expression in the textField property of a SymbolLayer.



          FeatureCollection featureCollection = FeatureCollection.fromFeatures();
          GeoJsonSource geoJsonSource = new GeoJsonSource("source-id", featureCollection);
          mapboxMap.addSource(geoJsonSource);

          SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id")
          .withProperties(PropertyFactory.textField(Expression.get("FEATURE-PROPERTY-KEY")));
          mapboxMap.addLayer(symbolLayer);


          The Annotation Plugin simplifies some of this. Also for reference to see how SymbolLayers are used, there is the Mapbox Android demo app.






          share|improve this answer
























          • You can also create a separate SymbolLayer for the markers. Reference the same GeoJson source as for your text. But for the marker layer, use the iconImage PropertyFactory method. Bitmap icon = BitmapFactory.decodeResource( Actvity.this.getResources(), R.drawable.marker_image); mapboxMap.addImage("marker-image", icon); then later: SymbolLayer markerLayer = new SymbolLayer("marker-layer-id", "source-id") .withProperties(PropertyFactory.iconImage("marker-image")); mapboxMap.addLayer(markerLayer);

            – langsmith
            Nov 25 '18 at 16:43













          • Thanks, this is just what I'm after I think! Do I have an alternative if my source is a dynamically compiled list of marker points in Java? I have a database of locations, and want to add them to a list of markers based on a set of information (so static source files aren't an option, unless I can dynamically draw a few points from such a source?). Thanks for the help! I'm curious about your second suggestion - what's the benefit of doing it this way? Seems a bit more complicated?

            – Jake Madden
            Nov 25 '18 at 21:13













          • Ahh, nevermind my question! That annotation symbolManager is exactly what I needed. I'll just use SymbolOptions for each marker. :) Thanks so much! I'm curious about the negative to my question - am I asking something stupid?

            – Jake Madden
            Nov 25 '18 at 21:26











          • @JakeMadden, not sure what you mean by "I'm curious about the negative to my question" Anyways, sounds like you're figuring things out. Once a GeoJsonSource is added to the map, any number of layers can reference the unique source id in the layer constructor.

            – langsmith
            Nov 27 '18 at 4:08











          • @JakeMadden , hard to help 'cause idk what your data looks like. If you can get the lat/long from each location in your database, do List<Feature> featureList = new ArrayList<>(); for (int x = 0; x < listOfLocationsFromDatabase.size; x++) { Point singlePoint = Point.fromLngLat(listOfLocationsFromDatabase.get(x).getLongitude(), listOfLocationsFromDatabase.get(x).getLongitude()); featureList.add(Feature.fromGeometry(singlePoint)); } FeatureCollection featureCollection = FeatureCollection.fromFeatures(featureList);

            – langsmith
            Nov 27 '18 at 4:13












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462414%2fandroid-mapbox-marker-labels%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          You're trying to do what's called data-driven styling



          You should use a SymbolLayer to show text on a map. If the text you want to show is based on GeoJSON Features in your data set, then use the get expression in the textField property of a SymbolLayer.



          FeatureCollection featureCollection = FeatureCollection.fromFeatures();
          GeoJsonSource geoJsonSource = new GeoJsonSource("source-id", featureCollection);
          mapboxMap.addSource(geoJsonSource);

          SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id")
          .withProperties(PropertyFactory.textField(Expression.get("FEATURE-PROPERTY-KEY")));
          mapboxMap.addLayer(symbolLayer);


          The Annotation Plugin simplifies some of this. Also for reference to see how SymbolLayers are used, there is the Mapbox Android demo app.






          share|improve this answer
























          • You can also create a separate SymbolLayer for the markers. Reference the same GeoJson source as for your text. But for the marker layer, use the iconImage PropertyFactory method. Bitmap icon = BitmapFactory.decodeResource( Actvity.this.getResources(), R.drawable.marker_image); mapboxMap.addImage("marker-image", icon); then later: SymbolLayer markerLayer = new SymbolLayer("marker-layer-id", "source-id") .withProperties(PropertyFactory.iconImage("marker-image")); mapboxMap.addLayer(markerLayer);

            – langsmith
            Nov 25 '18 at 16:43













          • Thanks, this is just what I'm after I think! Do I have an alternative if my source is a dynamically compiled list of marker points in Java? I have a database of locations, and want to add them to a list of markers based on a set of information (so static source files aren't an option, unless I can dynamically draw a few points from such a source?). Thanks for the help! I'm curious about your second suggestion - what's the benefit of doing it this way? Seems a bit more complicated?

            – Jake Madden
            Nov 25 '18 at 21:13













          • Ahh, nevermind my question! That annotation symbolManager is exactly what I needed. I'll just use SymbolOptions for each marker. :) Thanks so much! I'm curious about the negative to my question - am I asking something stupid?

            – Jake Madden
            Nov 25 '18 at 21:26











          • @JakeMadden, not sure what you mean by "I'm curious about the negative to my question" Anyways, sounds like you're figuring things out. Once a GeoJsonSource is added to the map, any number of layers can reference the unique source id in the layer constructor.

            – langsmith
            Nov 27 '18 at 4:08











          • @JakeMadden , hard to help 'cause idk what your data looks like. If you can get the lat/long from each location in your database, do List<Feature> featureList = new ArrayList<>(); for (int x = 0; x < listOfLocationsFromDatabase.size; x++) { Point singlePoint = Point.fromLngLat(listOfLocationsFromDatabase.get(x).getLongitude(), listOfLocationsFromDatabase.get(x).getLongitude()); featureList.add(Feature.fromGeometry(singlePoint)); } FeatureCollection featureCollection = FeatureCollection.fromFeatures(featureList);

            – langsmith
            Nov 27 '18 at 4:13
















          1














          You're trying to do what's called data-driven styling



          You should use a SymbolLayer to show text on a map. If the text you want to show is based on GeoJSON Features in your data set, then use the get expression in the textField property of a SymbolLayer.



          FeatureCollection featureCollection = FeatureCollection.fromFeatures();
          GeoJsonSource geoJsonSource = new GeoJsonSource("source-id", featureCollection);
          mapboxMap.addSource(geoJsonSource);

          SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id")
          .withProperties(PropertyFactory.textField(Expression.get("FEATURE-PROPERTY-KEY")));
          mapboxMap.addLayer(symbolLayer);


          The Annotation Plugin simplifies some of this. Also for reference to see how SymbolLayers are used, there is the Mapbox Android demo app.






          share|improve this answer
























          • You can also create a separate SymbolLayer for the markers. Reference the same GeoJson source as for your text. But for the marker layer, use the iconImage PropertyFactory method. Bitmap icon = BitmapFactory.decodeResource( Actvity.this.getResources(), R.drawable.marker_image); mapboxMap.addImage("marker-image", icon); then later: SymbolLayer markerLayer = new SymbolLayer("marker-layer-id", "source-id") .withProperties(PropertyFactory.iconImage("marker-image")); mapboxMap.addLayer(markerLayer);

            – langsmith
            Nov 25 '18 at 16:43













          • Thanks, this is just what I'm after I think! Do I have an alternative if my source is a dynamically compiled list of marker points in Java? I have a database of locations, and want to add them to a list of markers based on a set of information (so static source files aren't an option, unless I can dynamically draw a few points from such a source?). Thanks for the help! I'm curious about your second suggestion - what's the benefit of doing it this way? Seems a bit more complicated?

            – Jake Madden
            Nov 25 '18 at 21:13













          • Ahh, nevermind my question! That annotation symbolManager is exactly what I needed. I'll just use SymbolOptions for each marker. :) Thanks so much! I'm curious about the negative to my question - am I asking something stupid?

            – Jake Madden
            Nov 25 '18 at 21:26











          • @JakeMadden, not sure what you mean by "I'm curious about the negative to my question" Anyways, sounds like you're figuring things out. Once a GeoJsonSource is added to the map, any number of layers can reference the unique source id in the layer constructor.

            – langsmith
            Nov 27 '18 at 4:08











          • @JakeMadden , hard to help 'cause idk what your data looks like. If you can get the lat/long from each location in your database, do List<Feature> featureList = new ArrayList<>(); for (int x = 0; x < listOfLocationsFromDatabase.size; x++) { Point singlePoint = Point.fromLngLat(listOfLocationsFromDatabase.get(x).getLongitude(), listOfLocationsFromDatabase.get(x).getLongitude()); featureList.add(Feature.fromGeometry(singlePoint)); } FeatureCollection featureCollection = FeatureCollection.fromFeatures(featureList);

            – langsmith
            Nov 27 '18 at 4:13














          1












          1








          1







          You're trying to do what's called data-driven styling



          You should use a SymbolLayer to show text on a map. If the text you want to show is based on GeoJSON Features in your data set, then use the get expression in the textField property of a SymbolLayer.



          FeatureCollection featureCollection = FeatureCollection.fromFeatures();
          GeoJsonSource geoJsonSource = new GeoJsonSource("source-id", featureCollection);
          mapboxMap.addSource(geoJsonSource);

          SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id")
          .withProperties(PropertyFactory.textField(Expression.get("FEATURE-PROPERTY-KEY")));
          mapboxMap.addLayer(symbolLayer);


          The Annotation Plugin simplifies some of this. Also for reference to see how SymbolLayers are used, there is the Mapbox Android demo app.






          share|improve this answer













          You're trying to do what's called data-driven styling



          You should use a SymbolLayer to show text on a map. If the text you want to show is based on GeoJSON Features in your data set, then use the get expression in the textField property of a SymbolLayer.



          FeatureCollection featureCollection = FeatureCollection.fromFeatures();
          GeoJsonSource geoJsonSource = new GeoJsonSource("source-id", featureCollection);
          mapboxMap.addSource(geoJsonSource);

          SymbolLayer symbolLayer = new SymbolLayer("layer-id", "source-id")
          .withProperties(PropertyFactory.textField(Expression.get("FEATURE-PROPERTY-KEY")));
          mapboxMap.addLayer(symbolLayer);


          The Annotation Plugin simplifies some of this. Also for reference to see how SymbolLayers are used, there is the Mapbox Android demo app.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 25 '18 at 16:41









          langsmithlangsmith

          121211




          121211













          • You can also create a separate SymbolLayer for the markers. Reference the same GeoJson source as for your text. But for the marker layer, use the iconImage PropertyFactory method. Bitmap icon = BitmapFactory.decodeResource( Actvity.this.getResources(), R.drawable.marker_image); mapboxMap.addImage("marker-image", icon); then later: SymbolLayer markerLayer = new SymbolLayer("marker-layer-id", "source-id") .withProperties(PropertyFactory.iconImage("marker-image")); mapboxMap.addLayer(markerLayer);

            – langsmith
            Nov 25 '18 at 16:43













          • Thanks, this is just what I'm after I think! Do I have an alternative if my source is a dynamically compiled list of marker points in Java? I have a database of locations, and want to add them to a list of markers based on a set of information (so static source files aren't an option, unless I can dynamically draw a few points from such a source?). Thanks for the help! I'm curious about your second suggestion - what's the benefit of doing it this way? Seems a bit more complicated?

            – Jake Madden
            Nov 25 '18 at 21:13













          • Ahh, nevermind my question! That annotation symbolManager is exactly what I needed. I'll just use SymbolOptions for each marker. :) Thanks so much! I'm curious about the negative to my question - am I asking something stupid?

            – Jake Madden
            Nov 25 '18 at 21:26











          • @JakeMadden, not sure what you mean by "I'm curious about the negative to my question" Anyways, sounds like you're figuring things out. Once a GeoJsonSource is added to the map, any number of layers can reference the unique source id in the layer constructor.

            – langsmith
            Nov 27 '18 at 4:08











          • @JakeMadden , hard to help 'cause idk what your data looks like. If you can get the lat/long from each location in your database, do List<Feature> featureList = new ArrayList<>(); for (int x = 0; x < listOfLocationsFromDatabase.size; x++) { Point singlePoint = Point.fromLngLat(listOfLocationsFromDatabase.get(x).getLongitude(), listOfLocationsFromDatabase.get(x).getLongitude()); featureList.add(Feature.fromGeometry(singlePoint)); } FeatureCollection featureCollection = FeatureCollection.fromFeatures(featureList);

            – langsmith
            Nov 27 '18 at 4:13



















          • You can also create a separate SymbolLayer for the markers. Reference the same GeoJson source as for your text. But for the marker layer, use the iconImage PropertyFactory method. Bitmap icon = BitmapFactory.decodeResource( Actvity.this.getResources(), R.drawable.marker_image); mapboxMap.addImage("marker-image", icon); then later: SymbolLayer markerLayer = new SymbolLayer("marker-layer-id", "source-id") .withProperties(PropertyFactory.iconImage("marker-image")); mapboxMap.addLayer(markerLayer);

            – langsmith
            Nov 25 '18 at 16:43













          • Thanks, this is just what I'm after I think! Do I have an alternative if my source is a dynamically compiled list of marker points in Java? I have a database of locations, and want to add them to a list of markers based on a set of information (so static source files aren't an option, unless I can dynamically draw a few points from such a source?). Thanks for the help! I'm curious about your second suggestion - what's the benefit of doing it this way? Seems a bit more complicated?

            – Jake Madden
            Nov 25 '18 at 21:13













          • Ahh, nevermind my question! That annotation symbolManager is exactly what I needed. I'll just use SymbolOptions for each marker. :) Thanks so much! I'm curious about the negative to my question - am I asking something stupid?

            – Jake Madden
            Nov 25 '18 at 21:26











          • @JakeMadden, not sure what you mean by "I'm curious about the negative to my question" Anyways, sounds like you're figuring things out. Once a GeoJsonSource is added to the map, any number of layers can reference the unique source id in the layer constructor.

            – langsmith
            Nov 27 '18 at 4:08











          • @JakeMadden , hard to help 'cause idk what your data looks like. If you can get the lat/long from each location in your database, do List<Feature> featureList = new ArrayList<>(); for (int x = 0; x < listOfLocationsFromDatabase.size; x++) { Point singlePoint = Point.fromLngLat(listOfLocationsFromDatabase.get(x).getLongitude(), listOfLocationsFromDatabase.get(x).getLongitude()); featureList.add(Feature.fromGeometry(singlePoint)); } FeatureCollection featureCollection = FeatureCollection.fromFeatures(featureList);

            – langsmith
            Nov 27 '18 at 4:13

















          You can also create a separate SymbolLayer for the markers. Reference the same GeoJson source as for your text. But for the marker layer, use the iconImage PropertyFactory method. Bitmap icon = BitmapFactory.decodeResource( Actvity.this.getResources(), R.drawable.marker_image); mapboxMap.addImage("marker-image", icon); then later: SymbolLayer markerLayer = new SymbolLayer("marker-layer-id", "source-id") .withProperties(PropertyFactory.iconImage("marker-image")); mapboxMap.addLayer(markerLayer);

          – langsmith
          Nov 25 '18 at 16:43







          You can also create a separate SymbolLayer for the markers. Reference the same GeoJson source as for your text. But for the marker layer, use the iconImage PropertyFactory method. Bitmap icon = BitmapFactory.decodeResource( Actvity.this.getResources(), R.drawable.marker_image); mapboxMap.addImage("marker-image", icon); then later: SymbolLayer markerLayer = new SymbolLayer("marker-layer-id", "source-id") .withProperties(PropertyFactory.iconImage("marker-image")); mapboxMap.addLayer(markerLayer);

          – langsmith
          Nov 25 '18 at 16:43















          Thanks, this is just what I'm after I think! Do I have an alternative if my source is a dynamically compiled list of marker points in Java? I have a database of locations, and want to add them to a list of markers based on a set of information (so static source files aren't an option, unless I can dynamically draw a few points from such a source?). Thanks for the help! I'm curious about your second suggestion - what's the benefit of doing it this way? Seems a bit more complicated?

          – Jake Madden
          Nov 25 '18 at 21:13







          Thanks, this is just what I'm after I think! Do I have an alternative if my source is a dynamically compiled list of marker points in Java? I have a database of locations, and want to add them to a list of markers based on a set of information (so static source files aren't an option, unless I can dynamically draw a few points from such a source?). Thanks for the help! I'm curious about your second suggestion - what's the benefit of doing it this way? Seems a bit more complicated?

          – Jake Madden
          Nov 25 '18 at 21:13















          Ahh, nevermind my question! That annotation symbolManager is exactly what I needed. I'll just use SymbolOptions for each marker. :) Thanks so much! I'm curious about the negative to my question - am I asking something stupid?

          – Jake Madden
          Nov 25 '18 at 21:26





          Ahh, nevermind my question! That annotation symbolManager is exactly what I needed. I'll just use SymbolOptions for each marker. :) Thanks so much! I'm curious about the negative to my question - am I asking something stupid?

          – Jake Madden
          Nov 25 '18 at 21:26













          @JakeMadden, not sure what you mean by "I'm curious about the negative to my question" Anyways, sounds like you're figuring things out. Once a GeoJsonSource is added to the map, any number of layers can reference the unique source id in the layer constructor.

          – langsmith
          Nov 27 '18 at 4:08





          @JakeMadden, not sure what you mean by "I'm curious about the negative to my question" Anyways, sounds like you're figuring things out. Once a GeoJsonSource is added to the map, any number of layers can reference the unique source id in the layer constructor.

          – langsmith
          Nov 27 '18 at 4:08













          @JakeMadden , hard to help 'cause idk what your data looks like. If you can get the lat/long from each location in your database, do List<Feature> featureList = new ArrayList<>(); for (int x = 0; x < listOfLocationsFromDatabase.size; x++) { Point singlePoint = Point.fromLngLat(listOfLocationsFromDatabase.get(x).getLongitude(), listOfLocationsFromDatabase.get(x).getLongitude()); featureList.add(Feature.fromGeometry(singlePoint)); } FeatureCollection featureCollection = FeatureCollection.fromFeatures(featureList);

          – langsmith
          Nov 27 '18 at 4:13





          @JakeMadden , hard to help 'cause idk what your data looks like. If you can get the lat/long from each location in your database, do List<Feature> featureList = new ArrayList<>(); for (int x = 0; x < listOfLocationsFromDatabase.size; x++) { Point singlePoint = Point.fromLngLat(listOfLocationsFromDatabase.get(x).getLongitude(), listOfLocationsFromDatabase.get(x).getLongitude()); featureList.add(Feature.fromGeometry(singlePoint)); } FeatureCollection featureCollection = FeatureCollection.fromFeatures(featureList);

          – langsmith
          Nov 27 '18 at 4:13




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462414%2fandroid-mapbox-marker-labels%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()