Add a click event on the icon of the device on the map

ss884 years ago

Hello
I am trying to add a click event on the icon of the device on the map, and to do i am looking for the name of the feature and the layer responsible for that in Traccar so that i use the following code to achieve that :

map.on("click", function(e) {
    map.forEachFeatureAtPixel(e.pixel, function (feature, layer) {
        //do something
    })
}); 
Anton Tananaev4 years ago

There's already a callback for devices. Why not just use that?

ss884 years ago

From

 devices.js 
: would this code be helpful ?

renderer: function (value) {
                var status;
                if (value) {
                    status = Ext.getStore('DeviceStatuses').getById(value);
                    if (status) {
                        return status.get('name');
                    }
                }
                return null;
            }

how to add this handler to the above map on click callback so that the status of the device appears on the device location icon on the map (through a dialog window for exp) ?

Anton Tananaev4 years ago

This code has nothing to do with the map.

ss884 years ago

Not the map, but the device's status which i want it displayed when i click on the icon of the device on the map

For the map is this code the closest to what i want to achieve ? :


 this.map.on('pointermove', function (e) {
            var hit = this.forEachFeatureAtPixel(e.pixel, function () {
                return true;
            });
            if (hit) {
                target.style.cursor = 'pointer';
            } else {
                target.style.cursor = '';
            }
        });

PLUTARCO ORDONEZ4 years ago

you mean something like that?

Even click

Carlos Valdivia 4 years ago

Buenas Tardes Plutarco,
Esta muy interesante la funcionalidad de la ventana en mapa al seleccionar la unidad, llevo algo de tiempo tratando de implementarla, pero no queda jeje ... Alguna sugerencia de como llegar hasta ese grado como tu tienes implementado.

sosapablo3 years ago

totalmente interesado

juank3 years ago

buenas tardes plutarco podrias indicar que archivos verificar o modificar para llegar al de tu imagen . gracias