Leaflet / Leaflet.VectorGrid

Display gridded vector data (sliced GeoJSON or protobuf vector tiles) in Leaflet 1.0.0
593 stars 192 forks source link

Not working properly inside api call (tested with ajax and fetch) #229

Closed marcodelmoral closed 4 years ago

marcodelmoral commented 4 years ago

Hello, I'm trying to show some points on map taken from an API but it won't change the default marker for the leaflet icon one. It does work outside the API calls, I've tried ajax and fecth to no avail.

            var getjson = $.getJSON("http://127.0.0.1:8000/geo/apiestaciones/",function(data){
                var stations = L.vectorGrid.slicer(data, {
                    vectorTileLayerStyles: {
                        interactive: true,
                        rendererFactory: L.canvas.tile,
                        vectorTileLayerStyles:{
                            sliced: { icon: new L.Icon.Default()}
                        }
                    }
                }).addTo(map);

                stations.on('click', function(e) {
                    var pro = e.layer.properties;
                    var HTML = '';
                    for (var q in pro) {
                        HTML += q + ":" + pro[q] + '<br />';
                    }
                    L.popup()
                        .setContent(HTML)
                        .setLatLng(e.latlng)
                        .openOn(map);
                });
            });

Besides not applying the new Icon, the second part of the call, that applies the properties to the marker and lets them show on click, is not getting called. I've tried with both versions, the one here and the one that fixes the error found in other marker issues.

Thank you in advance

IvanSanchez commented 4 years ago

Hi, great to hear that you find Leaflet useful!

However, this issue tracker is used for reporting bugs and discussing new features. For questions on using Leaflet, please use gis.stackexchange.com or stackoverflow.

If you are really sure that this is a bug in leaflet, or a feature request, please change the wording to make it look like a bug report.

IvanSanchez commented 4 years ago

Hola, Marco,

Aparte del copia-pega de "esto es para bugs, no para soporte", decirte que es imposible saber qué pasa sin saber qué datos vienen de tu API, y sin ver el código funcionando (p ej poniendo una demo en www.leafletjs.com/edit )