Mapbox SymbolLayer隐藏标记

时间:2018-07-24 10:35:17

标签: android kotlin mapbox mapbox-android mapbox-marker

我使用符号层在地图上绘制一堆点:

app.post('/createaccount', (req, res) => {
    new_username = req.body.username;
    new_password = req.body.password;
    new_firstname = req.body.firstname;
    new_lastname = req.body.lastname;

    MongoClient.connect(url, (err, client) => {
        if (err) return console.log(err)
        db = client.db('entelligence')

        var myobj = {
            firstName: new_firstname,
            lastName: new_lastname,
            username: new_username,
            password: new_password
        };

        var match = false;
        var empty = false;
        var error_string = "";
        for (var i = 0; i < array.length; i++) {
            console.log(array[i].username);
            if (array[i].username == new_username) {
                match = true;
            }
        }

        if (match) {
            error_string = "Username is  already taken. "
        };
        if (new_firstname == '' || new_lastname == '' || new_username == '' || new_password == '') {
            error_string += "Field(s) cannot be empty";
        }
        console.log(error_string);

        if (error_string == "") {
            db.collection("users").insertOne(myobj, function(err, res) {
                if (err) throw err;
                console.log("1 document inserted");
            });
            return res.redirect('/');
        }

        return res.send(error_string);

    })
})

此后,我在地图上添加了几个标记(此标记需要定期进行动画处理)

var imgId = R.drawable.ic_route_stop

        var featureCollection = FeatureCollection.fromFeatures(mSelectedBusStops!!.map { stop ->
            Feature.fromGeometry(com.mapbox.geojson.Point.fromLngLat(
                    stop.Lon.toDouble(),
                    stop.Lat.toDouble()))
        });
        map?.addSource(
                GeoJsonSource(mMarkerSourceIdentifier,
                        featureCollection,
                        GeoJsonOptions()
                ))

        val image = BitmapFactory.decodeResource(activity?.resources, imgId)
        map?.addImage(mMarkerImgIdentifier, image)

        var layer = SymbolLayer(mMarkerStyleLayerIdentifier, mMarkerSourceIdentifier)
        layer.setProperties(PropertyFactory.iconImage(mMarkerImgIdentifier),
                PropertyFactory.iconAllowOverlap(true))
        map?.addLayer(layer)

这里的重要部分是标记,我稍后添加的标记应该始终可见。但是我的符号层隐藏了标记图标,我需要将标记放在前面。有什么办法可以解决?

这是它的外观

enter image description here

1 个答案:

答案 0 :(得分:1)

您需要将SymbolLayer放置在层堆栈中的标记层下方。您可以使用map?.addLayerBelow(layer, "com.mapbox.annotations.points")来实现。