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

Binding geoJson to scope #19

Open
ThomasHambach opened this issue May 7, 2015 · 0 comments
Open

Binding geoJson to scope #19

ThomasHambach opened this issue May 7, 2015 · 0 comments

Comments

@ThomasHambach
Copy link

Since currently you can only pass in a string, and I had to be able to dynamically change my markers...

(function() {
  'use strict';

  angular.module('angular-mapbox').directive('featureLayer', function() {
    return {
      restrict: 'E',
      require: '^mapbox',
      scope: {
        'mapData': '='
      },
      link: function(scope, element, attrs, controller) {
        controller.getMap().then(function(map) {

          var featureLayer = L.mapbox.featureLayer().addTo(map);
          featureLayer.on('layeradd', function(e) {
            var marker = e.layer,
              feature = marker.feature;
            marker.setIcon(L.icon(feature.properties.icon));
          });

          scope.$watch('mapData', function(data) {
            if(data) {
              featureLayer.setGeoJSON(data);
            }
          });

        });

      }
    };
  });
})();

Example in jade

    mapbox#map-container(map-id="XXXX",zoom="18",trackResize="true",height="{{ mapHeight }}",width="100%")
        feature-layer(map-data="$parent.mappedVenues")
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

1 participant