Code Monkey home page Code Monkey logo

Comments (6)

houqp avatar houqp commented on August 15, 2024

It works for me, can you show us all your controller code?

from angular-leaflet-directive.

nickponline avatar nickponline commented on August 15, 2024

Hmm, I must be doing something wrong. Here is my code:

function MapCtrl($scope) {

$scope.center = {
        lat:  0,
        lng:  0,
        zoom: 13,
};

angular.extend($scope, {
    markers : {},
});

$scope.paths = {
    path: {
        weight: 3,
        opacity: 0.5,
        latlngs: [],
    },
};

$scope.remove_waypoint = function(wp) {

    var idx = $scope.paths.path.latlngs.indexOf(wp);
    var ky = wp['number']

    delete $scope.markers[ky];
    $scope.paths.path.latlngs.splice(idx, 1);

}

$scope.add_waypoint = function(wp)
{        
    var lat = wp.latlng.lat;
    var lng = wp.latlng.lng;
    var ts  = $scope.paths.path.latlngs.length;

    $scope.markers[ts] = {
        'lat': lat,
        'lng': lng,
        'draggable' : true, 
        'number' : $scope.paths.path.latlngs.length,
    }

    $scope.paths.path.latlngs.push($scope.markers[ts]);  
    $scope.$digest();        
}

}

from angular-leaflet-directive.

houqp avatar houqp commented on August 15, 2024

hm, seems ok to me. any reason why calling digest manually at the end of add_waypoint?

could you put up an example (including basic html code) in jsfiddle so we can reproduce the error on our side?

from angular-leaflet-directive.

JaumeFigueras avatar JaumeFigueras commented on August 15, 2024

Also, can you update the directive to v0.6 or the master version? The error log line numbers do not fit with actual code. You probably have a version with some bugs.
Agree with @houqp why call digest?

from angular-leaflet-directive.

nickponline avatar nickponline commented on August 15, 2024

@houqp: Sorry the $digest should not be there.

Effectively I have number of objects each representing maps and when I select one it loads it's corresponding markers and paths to a shared leaflet map. When I select another it removes the markers and paths and loads the news one. I don't specify a layer parameter so that is null, therefore when the markers are removed by the watcher layer is null.

I see that it's been fixed in the current version with: if (layers !== undefined && layers !== null)

Thanks, can close :)

from angular-leaflet-directive.

houqp avatar houqp commented on August 15, 2024

glad that you figured it out yourself :)

from angular-leaflet-directive.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.