Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8716989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:12:43+00:00 2026-06-13T06:12:43+00:00

Following directie code is from http://jsfiddle.net/M6RPn/26/ I want to get a json feed that

  • 0

Following directie code is from http://jsfiddle.net/M6RPn/26/
I want to get a json feed that has many lat and long.. I can get a json with $resource or $http in Angular easily but How can I feed it to this directive to map thing on the map?

module.directive('sap', function() {
    return {
        restrict: 'E',
        replace: true,
        template: '<div></div>',
        link: function(scope, element, attrs) {
            var map = L.map(attrs.id, {
                center: [40, -86],
                zoom: 10
            });
            //create a CloudMade tile layer and add it to the map
            L.tileLayer('http://{s}.tile.cloudmade.com/57cbb6ca8cac418dbb1a402586df4528/997/256/{z}/{x}/{y}.png', {
                maxZoom: 18
            }).addTo(map);

            //add markers dynamically
            var points = [{lat: 40, lng: -86},{lat: 40.1, lng: -86.2}];
            for (var p in points) {
                L.marker([points[p].lat, points[p].lng]).addTo(map);
            }
        }
    };
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:12:47+00:00Added an answer on June 13, 2026 at 6:12 am

    I don’t know a lot about Leaflet or what you’re trying to do, but I’d assume you want to pass some coordinates in from your controller to your directive?

    There are actually a lot of ways to do that… the best of which involve leveraging scope.

    Here’s one way to pass data from your controller to your directive:

    module.directive('sap', function() {
        return {
            restrict: 'E',
            replace: true,
            template: '<div></div>',
            link: function(scope, element, attrs) {
                var map = L.map(attrs.id, {
                    center: [40, -86],
                    zoom: 10
                });
                //create a CloudMade tile layer and add it to the map
                L.tileLayer('http://{s}.tile.cloudmade.com/57cbb6ca8cac418dbb1a402586df4528/997/256/{z}/{x}/{y}.png', {
                    maxZoom: 18
                }).addTo(map);
    
                //add markers dynamically
                var points = [{lat: 40, lng: -86},{lat: 40.1, lng: -86.2}];
                updatePoints(points);
    
                function updatePoints(pts) {
                   for (var p in pts) {
                      L.marker([pts[p].lat, pts[p].lng]).addTo(map);
                   }
                }
    
                //add a watch on the scope to update your points.
                // whatever scope property that is passed into
                // the poinsource="" attribute will now update the points
                scope.$watch(attr.pointsource, function(value) {
                   updatePoints(value);
                });
            }
        };
    });
    

    Here’s the markup. In here you’re adding that pointsource attribute the link function is looking for to set up the $watch.

    <div ng-app="leafletMap">
        <div ng-controller="MapCtrl">
            <sap id="map" pointsource="pointsFromController"></sap>
        </div>
    </div>
    

    Then in your controller you have a property you can just update.

    function MapCtrl($scope, $http) {
       //here's the property you can just update.
       $scope.pointsFromController = [{lat: 40, lng: -86},{lat: 40.1, lng: -86.2}];
    
       //here's some contrived controller method to demo updating the property.
       $scope.getPointsFromSomewhere = function() {
         $http.get('/Get/Points/From/Somewhere').success(function(somepoints) {
             $scope.pointsFromController = somepoints;
         });
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following chunk html code works as expected: <iframe src=http://www.amazon.com/></iframe> But when trying embed inner
I have seen in Debugging .net 2.0 Applications the following code [Conditional(DEBUG)] void AssertTableExists()
I want to localize Web Service in ASP.NET application. I can write the following
Following on from a previous question, I have the following code: var results =
The following site Writing Boot Sector Code provides a sample of code that prints
I found the following code in php.ini . what does that mean? And PHP
I have the following code: public static IList<SortOption> SortValues() { var sortValues = (from
I'm trying to get the CPU ID from the machine. I found the following
I have ASP.net website. In App_Code folder I have class that has extension methods.
The following piece of code is from u-boot: /* Initialize GOT pointer. ** Global

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.