Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AngularJS - Leaflet] Invalid data passed to the polyline path #323

Closed
connor11528 opened this issue Mar 12, 2014 · 3 comments
Closed

[AngularJS - Leaflet] Invalid data passed to the polyline path #323

connor11528 opened this issue Mar 12, 2014 · 3 comments

Comments

@connor11528
Copy link

I'm trying to draw a path when a user clicks a certain element. In my view I have the directive:

<leaflet 
        center="nairobi" 
        paths="paths" 
        markers="markers" 
        defaults="defaults" 
        height="600">
    </leaflet>

Then in my controller I fetch the data points and add them to $scope.paths

   // function to draw path on map
    $scope.drawRoute = function(shape_id){
        // get path coordinates
        Route.getCoords(shape_id, function(points){
            var newPath = {
                color:'red',
                weight: 4,
                latlngs: []
            };

            // create array of latlngs
            angular.forEach(points, function(point){
                 // each point looks like this: ["1001", "-1.320547", "36.70583"]
                var coord = {
                    lat: point[1],
                    lng: point[2]
                };
                newPath.latlngs.push(coord);
            });
            var pathName = shape_id;

            // add path to $scope
            $scope.paths[pathName] = newPath;

        }, function(error){
            $scope.routeToDraw  = error;
        });
    };

    // generate map
    angular.extend($scope, {
        nairobi: {
            lat: -1.284381, 
            lng: 36.809031,
            zoom: 12
        },
        paths: {
            defaultPath: {
                color: 'red',
                weight: 4,
                latlngs: [
                        { lat: -1.284381, lng: 36.700974 },
                        { lat: -1.31349, lng: 36.699959 },
                        { lat: -1.311739, lng: 36.698589 }
                ],
            }
        },
        markers: {},
        defaults: {
            scrollWheelZoom: false
        }
    });

The defaultPath shows up fine when the page loads, but when I click an element I get an error:

[AngularJS - Leaflet] Invalid data passed to the polyline path angular.js:9383
TypeError: Cannot call method 'on' of undefined

How can I draw a path when a user clicks an element?

@tombatossals
Copy link
Owner

Hi, please, could you implement the case in a working demo?

You could use this jsfiddle as a start:
http://jsfiddle.net/tombatossals/4PhzC/

Thanks for reporting

@nmccready
Copy link
Contributor

This issue was moved to angular-ui/ui-leaflet#9

@nmccready nmccready reopened this Oct 29, 2015
@tombatossals
Copy link
Owner

I'm going to rework&redesign angular-leaflet-directive to be compatible with Leaflet v1.0. It will mantain almost all its functionality, and will be compatible with the current features of the directive, but I must start from a fresh point, so I'm going to close this issue. If you think it must be worked with the new version, please reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants