1

I'm trying to get events on the client side and showing changes (new markers) in realtime on a leaflet map with socket.io.

The problem is in defining data that comes from socket.. I don't know the propriate way for getting data:

L.layerJSON({
   url: "msg"

I'm trying with url property, but it doesn't work.

Here is the code:

angular.module('app')
.controller('MapController', [ '$scope', '$http', '$interval', 'leafletData', 'socketio',  function($scope, $http, $interval, leafletData, socketio) {

        var map = L.map('map', {
            zoom: 8,
            layers: L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'),
            useCache: true
        });

        var markers = new L.MarkerClusterGroup().addTo(map);

        socketio.on('mapCoord', function (msg) {
            L.layerJSON({
                url: "msg",
                propertyLoc: ['latitude','longitude'],
                propertyTitle: 'name',
                minShift: Infinity,        
                caching: true,
                layerTarget: markers
            })
            .addTo(map);
        });

        map.addLayer(markers);
    }])
1

L.layerJSON does not exist! Read http://leafletjs.com/reference-1.0.0.html !!

You probably want to create new instances of L.Marker by looping through the data received via websockets, and then doing something like L.marker([msg.latitude, msg.longitude]).addTo(markers) to add the new markers to your instance of MarkerClusterGroup.

  • Thanks Ivan. Just to clarify L.LayerJSON; instead of geojson, I use data in json format and there is a leaflet-layerJSON library. – user3265921 Jul 7 '16 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.