Chevron Z Index

How to make the chevron appear on top of markers and cluster markers? I was looking for a Z index to set but couldn’t find any. I tried with circle but still no luck.

You could try with this: Dynamic Layer Ordering | Map, Map Examples | Maps SDK for Android | TomTom Developer Portal
But you would have to check the name of this layer. To get all layers:

tomtomMap.getStyleSettings().getLayers()
1 Like

Oh man, this sent me down the rabbit hole :laughing:. There are 754 layers there all with the same name and different Id. After hours and hours i think i got it, i think… I have to use a layer that contains symbols created from geoJson as source and json for layer. I found an example on how to create those and add them to the map but i don’t see anything on the map. The layer exists and i can get id, source id, visibility. This is the code that Damian wrote in 2019:

{
    "type": "FeatureCollection",
    "features": [
        {
            "id": "GeoJSON Polygon",
            "type": "Feature",
            "properties": {},
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            48.893478,
                            2.334595
                        ],
                        [
                            48.893479,
                            2.334597
                        ],
                        [
                            48.893482,
                            2.334599
                        ],
                        [
                            48.893485,
                            2.334600
                        ],
                        [
                            48.893489,
                            2.334605
                        ],
                        [
                            48.893491,
                            2.334608
                        ],
                        [
                            48.893495,
                            2.334610
                        ],
                        [
                            48.893499,
                            2.334612
                        ],
                        [
                            48.893500,
                            2.334616
                        ],
                        [
                            48.893504,
                            2.334619
                        ],
                        [
                            48.893508,
                            2.334620
                        ],
                        [
                            48.893509,
                            2.334622
                        ],
                        [
                            48.893512,
                            2.334623
                        ],
                        [
                            48.893516,
                            2.334626
                        ],
                        [
                            48.893518,
                            2.334628
                        ],
                        [
                            48.893520,
                            2.334630
                        ],
                        [
                            48.893522,
                            2.334632
                        ],
                        [
                            48.893528,
                            2.334633
                        ],
                        [
                            48.893529,
                            2.334635
                        ],
                        [
                            48.893530,
                            2.334637
                        ],
                        [
                            48.893534,
                            2.334639
                        ]
                    ]
                ]
            }
        }
    ]
}

Then you add it like you did:

GeoJsonSource source = SourceFactory.createGeoJsonSource(GEOJSON_SOURCE_ID);
source.setGeoJson(geoJsonData);
map.getStyleSettings().addSource(source);

And now you need to prepare a JSON of an layer and provide the ID of the GeoJSON source to it:

{
    “id”: “layer-line-id”,
    “type”: “line”,
    “layout”: {
        “visibility”: “visible”
    },
    “paint”: {
        “line-color”: “rgba(26, 203, 207, 1)”,
        “line-width”: 6
    },
    “source”: “geojson-source-id”
}

Finally add a layer to the map by calling:

Layer layer = LayerFactory.createLayer(layerJson);
tomtomMap.getStyleSettings().addLayer(layer);

I know that his code creates polygon but im just trying to make it visible atm and them use symbols. Everything seems to be alright and the layer is added to the map with max and min zoom infinite but it is just not visible.

This is my code:

JSONObject featureCollection = new JSONObject();
JSONArray features = new JSONArray();
JSONObject feature = new JSONObject();
JSONObject properties = new JSONObject();
try {
	featureCollection.put("type", "FeatureCollection");
	feature.put("id", "GeoJSON Polygon");
	feature.put("type", "Feature");
	feature.put("properties", properties);

	JSONObject geometry = new JSONObject();
	JSONArray coordinates = new JSONArray();
	JSONArray coordinate = new JSONArray();

	JSONArray ceva = new JSONArray().put(0, 51.386798);
	ceva.put(1, -2.714332);
	JSONArray ceva2 = new JSONArray().put(0, 51.386696);
	ceva2.put(1, -2.713455);
	JSONArray ceva3 = new JSONArray().put(0, 51.386406);
	ceva3.put(1, -2.713554);
	JSONArray ceva4 = new JSONArray().put(0, 51.386540);
	ceva4.put(1, -2.714415);

	coordinate.put(ceva);
	coordinate.put(ceva2);
	coordinate.put(ceva3);
	coordinate.put(ceva4);

	geometry.put("type", "Polygon");
	coordinates.put(coordinate);
	geometry.put("coordinates", coordinates);

	feature.put("geometry", geometry);
	features.put(feature);
	featureCollection.put("features", features);

	Log.e("geo", featureCollection.toString());
}catch (Throwable e){
	Log.e("geoJson", "error: " + e.getLocalizedMessage());
}finally {
	GeoJsonSource source = SourceFactory.createGeoJsonSource("GEOJSON_SOURCE_ID");
	source.setGeoJson(featureCollection.toString());
	tomMap.getStyleSettings().addSource(source);

	JSONObject json = new JSONObject();
	JSONObject layout = new JSONObject();
	JSONObject paint = new JSONObject();
	try {
		json.put("id", "layer-line-id");
		json.put("type", "line");
		layout.put("visibility", "visible");
		json.put("layout", layout);
		paint.put("line-color", "#000000");
		paint.put("line-opacity", 1);
		paint.put("line-width", 30);
		json.put("paint", paint);
		json.put("source", "geojson_source_id");
	} catch (JSONException e) {
		e.printStackTrace();
		Log.e("json", "error: " + e.getLocalizedMessage());
	}finally {
		Layer layer = LayerFactory.createLayer(json.toString());
		tomMap.getStyleSettings().addLayer(layer);
		String id = layer.getId();
		List<Layer> lay = tomMap.getStyleSettings().findLayersById(id);
		float maxZoom = layer.getMaxZoom();
		float minZoom = layer.getMinZoom();
		Visibility visibility = layer.getVisibility();
		Log.e("json", "id: " + id + " / index: " + lay + " / maxZoom: " + maxZoom + " / minZoom: " + minZoom + " / visi: " + visibility);
	}
}

GeoJSON standard uses lon,lat format.
Also Polygon must be closed - last point should be the same as first one.
Here is a fixed code:

JSONArray ceva = new JSONArray().put(1, 51.386798);
ceva.put(0, -2.714332);
JSONArray ceva2 = new JSONArray().put(1, 51.386696);
ceva2.put(0, -2.713455);
JSONArray ceva3 = new JSONArray().put(1, 51.386406);
ceva3.put(0, -2.713554);
JSONArray ceva4 = new JSONArray().put(1, 51.386540);
ceva4.put(0, -2.714415);

coordinate.put(ceva);
coordinate.put(ceva2);
coordinate.put(ceva3);
coordinate.put(ceva4);
coordinate.put(ceva);

Yeah. I know about the switch of lat lng, My mistake was that last location wasn’t the same as first one. Thanks. I actually managed to sort it out. This is my code if someone needs it.

                 if (layer != null){
                        JSONObject featureCollection = new JSONObject();
                        JSONArray features = new JSONArray();
                        try {
                            featureCollection.put("type", "FeatureCollection");
                            int pointNumber = 0;
                            for (GeoLocation geoLocation : ridersOnlineList) {
                                pointNumber ++;
                                JSONObject feature = new JSONObject();
                                JSONObject properties = new JSONObject();
                                JSONObject geometry = new JSONObject();
                                JSONArray point = new JSONArray();

                                feature.put("id", "GeoJSON Point " + pointNumber);
                                feature.put("type", "Feature");
                                feature.put("properties", properties);

                                point.put(1, geoLocation.latitude);
                                point.put(0, geoLocation.longitude);

                                geometry.put("type", "Point");
                                geometry.put("coordinates", point);

                                feature.put("geometry", geometry);
                                features.put(feature);
                            }
                            featureCollection.put("features", features);
                        }catch (Throwable e){
                            e.printStackTrace();
                        }finally {
                            com.google.common.base.Optional<Source> sourceOptional = tomMap.getStyleSettings().findSourceById("GEOJSON_SOURCE_ID");
                            FuncUtils.apply(sourceOptional, source -> {
                                GeoJsonSource geoJsonSource = (GeoJsonSource) source;
                                geoJsonSource.setGeoJson(featureCollection.toString());
                            });
                        }
                    }else {
                        Drawable drawable = AppCompatResources.getDrawable(activity, R.drawable.onlineridermarker);
                        if (drawable != null){
                            Image image = ImageFactory.createImage("markerImage", drawable);
                            tomMap.getStyleSettings().addImage(image);
                        }
                        JSONObject featureCollection = new JSONObject();
                        JSONArray features = new JSONArray();
                        try {
                            featureCollection.put("type", "FeatureCollection");
                            int pointNumber = 0;
                            for (GeoLocation geoLocation : ridersOnlineList) {
                                pointNumber ++;
                                JSONObject feature = new JSONObject();
                                JSONObject properties = new JSONObject();
                                JSONObject geometry = new JSONObject();
                                JSONArray point = new JSONArray();

                                feature.put("id", "GeoJSON Point " + pointNumber);
                                feature.put("type", "Feature");
                                feature.put("properties", properties);

                                point.put(1, geoLocation.latitude);
                                point.put(0, geoLocation.longitude);

                                geometry.put("type", "Point");
                                geometry.put("coordinates", point);

                                feature.put("geometry", geometry);
                                features.put(feature);
                            }
                            featureCollection.put("features", features);
                        }catch (Throwable e){
                            e.printStackTrace();
                        }finally {
                            GeoJsonSource source = SourceFactory.createGeoJsonSource("GEOJSON_SOURCE_ID");
                            source.setGeoJson(featureCollection.toString());
                            tomMap.getStyleSettings().addSource(source);

                            JSONObject json = new JSONObject();
                            JSONObject layout = new JSONObject();
                            JSONObject paint = new JSONObject();
                            try {
                                json.put("id", "layer-symbol-id");
                                json.put("type", "symbol");

                                layout.put("visibility", "visible");
                                layout.put("icon-image", "markerImage");
                                layout.put("icon-allow-overlap", true);
                                layout.put("icon-ignore-placement", true);

                                json.put("layout", layout);
                                json.put("paint", paint);
                                json.put("source", "GEOJSON_SOURCE_ID");
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }finally {
                                layer = LayerFactory.createLayer(json.toString());
                                tomMap.getStyleSettings().addLayer(layer);
                                tomMap.getStyleSettings().moveLayerBehind(layer.getId(), "tomtom-RANDOM-chevron-layer-for-tomtom-position-icon-1");
                            }
                        }
                    }