angular-leaflet-rails 0.1.0.1 → 0.1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06b70b6fcd0d05403b3655ee5d37495145a7afbb
4
- data.tar.gz: b49142f05f11414cdace61acfc1294635237a0b3
3
+ metadata.gz: 4c1b6b33c352fc16a7c7f8f6278c898c29cc4cc2
4
+ data.tar.gz: 5eff4ee16ee676380fe528316c0fd3a2b8c6fdbd
5
5
  SHA512:
6
- metadata.gz: 59bc3bd6bc3437368af756638aed52df3a6f6077d6f8fca51efcfdd1687ce24853ab78f70a409a91b980bb9628b9ff63aefbeec5721bfd1fe1dbd0b590e63e3f
7
- data.tar.gz: fff2df32759ed392c30da617088369e85196fb61fa2d231da60621f99ed5245cc74cddd04812e82af3aed7ab292aadcf7062eab99778990ba52047e128767bac
6
+ metadata.gz: 568215391c96ca4ff49c7a0329e884aba0d2f6d8bc45d993ffaf4143a4cca2d4f366bd023eff52b8aa9a122ae63e646398db7157de76ee6e23ad065dff7fe88a
7
+ data.tar.gz: 6e59640ef3ec914b45455b2e0995b45fcd9d062c688f3e3faa18a7bea590784241360aea837883407b801b848d01e4c37ed6e86c9c7050ca9c4dd7f55846fe44
data/README.md CHANGED
@@ -16,6 +16,14 @@ Add the following directive to your Javascript manifest file (application.js):
16
16
  //= require angular-leaflet
17
17
  ```
18
18
 
19
+ Add the following directive to your CSS manifest file (application.css):
20
+
21
+ ```css
22
+ *= require angular-leaflet
23
+ ```
24
+
25
+
26
+
19
27
 
20
28
  ## Contributing
21
29
 
data/Rakefile CHANGED
@@ -2,5 +2,7 @@ require "bundler/gem_tasks"
2
2
 
3
3
  desc "Fetch new version from https://github.com/tombatossals/angular-leaflet-directive"
4
4
  task :fetch do
5
- `curl https://raw.github.com/tombatossals/angular-leaflet-directive/master/src/angular-leaflet-directive.js > vendor/assets/javascripts/angular-leaflet.js`
5
+ source = "https://raw.github.com/tombatossals/angular-leaflet-directive/master/src/angular-leaflet-directive.js"
6
+ target = "vendor/assets/javascripts/angular-leaflet-directive.js"
7
+ sh "curl #{source} > #{target}"
6
8
  end
@@ -18,6 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "angular-rails"
22
+ spec.add_dependency "leaflet-rails"
23
+
21
24
  spec.add_development_dependency "bundler", "~> 1.3"
22
25
  spec.add_development_dependency "rake"
23
26
  end
@@ -0,0 +1,11 @@
1
+ require "angular-leaflet-rails/version"
2
+ require "angular-rails"
3
+ require "leaflet-rails"
4
+
5
+ module AngularLeaflet
6
+ module Rails
7
+ class Engine < ::Rails::Engine
8
+ # Rails -> use vendor directory.
9
+ end
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  module AngularLeaflet
2
2
  module Rails
3
- VERSION = "0.1.0.1"
3
+ VERSION = "0.1.0.2"
4
4
  end
5
5
  end
@@ -0,0 +1,153 @@
1
+ var leafletDirective = angular.module("leaflet-directive", []);
2
+
3
+ leafletDirective.directive("leaflet", ["$http", "$log", function ($http, $log) {
4
+ return {
5
+ restrict: "E",
6
+ replace: true,
7
+ transclude: true,
8
+ scope: {
9
+ center: "=center",
10
+ tilelayer: "=tilelayer",
11
+ markers: "=markers",
12
+ path: "=path",
13
+ maxZoom: "@maxzoom"
14
+ },
15
+ template: '<div class="angular-leaflet-map"></div>',
16
+ link: function (scope, element, attrs, ctrl) {
17
+ var $el = element[0],
18
+ map = new L.Map($el);
19
+
20
+ // Expose the map object, for testing purposes
21
+ if (attrs.map) {
22
+ scope.map = map;
23
+ }
24
+
25
+ // Set maxZoom from attrs
26
+ if (attrs.maxzoom){
27
+ scope.maxZoom = parseInt(attrs.maxzoom)
28
+ }
29
+
30
+ // Set initial view
31
+ map.setView([0, 0], 1);
32
+
33
+ // Set tile layer
34
+ var tilelayer = scope.tilelayer || 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
35
+ var maxZoom = scope.maxZoom || 12;
36
+ L.tileLayer(tilelayer, { maxZoom: maxZoom }).addTo(map);
37
+
38
+ // Manage map center events
39
+ if (attrs.center && scope.center) {
40
+
41
+ if (scope.center.lat && scope.center.lng && scope.center.zoom) {
42
+ map.setView(new L.LatLng(scope.center.lat, scope.center.lng), scope.center.zoom);
43
+ } else if (scope.center.autoDiscover === true) {
44
+ map.locate({ setView: true, maxZoom: maxZoom });
45
+ }
46
+
47
+ map.on("dragend", function(e) {
48
+ scope.$apply(function (s) {
49
+ s.center.lat = map.getCenter().lat;
50
+ s.center.lng = map.getCenter().lng;
51
+ });
52
+ });
53
+
54
+ map.on("zoomend", function(e) {
55
+ scope.$apply(function (s) {
56
+ s.center.zoom = map.getZoom();
57
+ });
58
+ });
59
+
60
+ scope.$watch("center", function (center, oldValue) {
61
+ map.setView([center.lat, center.lng], center.zoom);
62
+ }, true);
63
+ }
64
+
65
+ if (attrs.markers && scope.markers) {
66
+ var markers = {};
67
+
68
+ var createAndLinkMarker = function(key, scope) {
69
+ var data = scope.markers[key];
70
+ var marker = new L.marker(
71
+ scope.markers[key],
72
+ {
73
+ draggable: data.draggable ? true:false
74
+ }
75
+ );
76
+
77
+ marker.on("dragend", function(e) {
78
+ scope.$apply(function (s) {
79
+ data.lat = marker.getLatLng().lat;
80
+ data.lng = marker.getLatLng().lng;
81
+ if (data.message) {
82
+ marker.openPopup();
83
+ }
84
+ });
85
+ });
86
+
87
+ scope.$watch('markers.' + key, function(newval, oldval) {
88
+ if (!newval) {
89
+ map.removeLayer(markers[key]);
90
+ delete markers[key];
91
+ return;
92
+ }
93
+
94
+ if (newval.draggable !== undefined && newval.draggable !== oldval.draggable) {
95
+ newval.draggable ? marker.dragging.enable() : marker.dragging.disable();
96
+ }
97
+
98
+ if (newval.focus !== undefined && newval.focus !== oldval.focus) {
99
+ newval.focus ? marker.openPopup() : marker.closePopup();
100
+ }
101
+
102
+ if (newval.message !== undefined && newval.message !== oldval.message) {
103
+ marker.bindPopup(newval);
104
+ }
105
+
106
+ if (newval.lat !== oldval.lat || newval.lng !== oldval.lng) {
107
+ marker.setLatLng(new L.LatLng(newval.lat, newval.lng));
108
+ }
109
+ }, true);
110
+
111
+ return marker;
112
+ }; // end of create and link marker
113
+
114
+ scope.$watch("markers", function(newMarkerList) {
115
+ // add new markers
116
+ for (var key in scope.markers) {
117
+ if (markers[key] === undefined) {
118
+ var marker = createAndLinkMarker(key, scope);
119
+ map.addLayer(marker);
120
+ markers[key] = marker;
121
+ }
122
+ }
123
+ }, true);
124
+ } // if attrs.markers
125
+
126
+ if (attrs.path) {
127
+ var polyline = new L.Polyline([], { weight: 10, opacity: 1});
128
+ map.addLayer(polyline);
129
+ scope.$watch("path.latlngs", function(latlngs) {
130
+ for (var idx=0, length=latlngs.length; idx < length; idx++) {
131
+ if (latlngs[idx] === undefined || latlngs[idx].lat === undefined || latlngs[idx].lng === undefined) {
132
+ $log.warn("Bad path point inn the $scope.path array ");
133
+ latlngs.splice(idx, 1);
134
+ }
135
+ }
136
+ polyline.setLatLngs(latlngs);
137
+ }, true);
138
+
139
+ scope.$watch("path.weight", function(weight) {
140
+ polyline.setStyle({
141
+ weight: weight
142
+ });
143
+ }, true);
144
+
145
+ scope.$watch("path.color", function(color) {
146
+ polyline.setStyle({
147
+ color: color
148
+ });
149
+ }, true);
150
+ } // end of attrs.path
151
+ } // end of link function
152
+ };
153
+ }]);
@@ -1,178 +1,3 @@
1
- var leafletDirective = angular.module("leaflet-directive", []);
2
-
3
- leafletDirective.directive("leaflet", ["$http", "$log", function ($http, $log) {
4
- return {
5
- restrict: "E",
6
- replace: true,
7
- transclude: true,
8
- scope: {
9
- center: "=center",
10
- tilelayer: "=tilelayer",
11
- markers: "=markers",
12
- path: "=path",
13
- maxZoom: "@maxzoom"
14
- },
15
- template: '<div class="angular-leaflet-map"></div>',
16
- link: function (scope, element, attrs, ctrl) {
17
- var $el = element[0],
18
- map = new L.Map($el);
19
-
20
- // Expose the map object, for testing purposes
21
- if (attrs.map) {
22
- scope.map = map;
23
- }
24
-
25
- // Set maxZoom from attrs
26
- if (attrs.maxzoom){
27
- scope.maxZoom = parseInt(attrs.maxzoom)
28
- }
29
-
30
- // Set initial view
31
- map.setView([0, 0], 1);
32
-
33
- // Set tile layer
34
- var tilelayer = scope.tilelayer || 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
35
- var maxZoom = scope.maxZoom || 12;
36
- L.tileLayer(tilelayer, { maxZoom: maxZoom }).addTo(map);
37
-
38
- // Manage map center events
39
- if (attrs.center && scope.center) {
40
-
41
- if (scope.center.lat && scope.center.lng && scope.center.zoom) {
42
- map.setView(new L.LatLng(scope.center.lat, scope.center.lng), scope.center.zoom);
43
- } else if (scope.center.autoDiscover === true) {
44
- map.locate({ setView: true, maxZoom: maxZoom });
45
- }
46
-
47
- map.on("dragend", function(e) {
48
- scope.$apply(function (s) {
49
- s.center.lat = map.getCenter().lat;
50
- s.center.lng = map.getCenter().lng;
51
- });
52
- });
53
-
54
- map.on("zoomend", function(e) {
55
- scope.$apply(function (s) {
56
- s.center.zoom = map.getZoom();
57
- });
58
- });
59
-
60
- scope.$watch("center", function (center, oldValue) {
61
- map.setView([center.lat, center.lng], center.zoom);
62
- }, true);
63
- }
64
-
65
- if (attrs.markers !== undefined) {
66
- var markers_dict = [];
67
-
68
- var createAndLinkMarker = function(mkey, scope) {
69
- var markerData = scope.markers[mkey];
70
- var marker = new L.marker(
71
- scope.markers[mkey],
72
- {
73
- draggable: markerData.draggable ? true:false
74
- }
75
- );
76
-
77
- if (markerData.message) {
78
- scope.$watch("markers." + mkey + ".message", function(newValue) {
79
- marker.bindPopup(markerData.message);
80
- });
81
-
82
- scope.$watch("markers." + mkey + ".focus", function(newValue) {
83
- if (newValue) {
84
- marker.openPopup();
85
- }
86
- });
87
- }
88
-
89
- scope.$watch("markers." + mkey + ".draggable", function (newValue, oldValue) {
90
- if (newValue === false) {
91
- marker.dragging.disable();
92
- } else if (newValue === true) {
93
- marker.dragging.enable();
94
- }
95
- });
96
-
97
- var dragging_marker = false;
98
- marker.on("dragstart", function(e) {
99
- dragging_marker = true;
100
- });
101
-
102
- marker.on("drag", function (e) {
103
- scope.$apply(function (s) {
104
- markerData.lat = marker.getLatLng().lat;
105
- markerData.lng = marker.getLatLng().lng;
106
- });
107
- });
108
-
109
- marker.on("dragend", function(e) {
110
- dragging_marker = false;
111
- if (markerData.message) {
112
- marker.openPopup();
113
- }
114
- });
115
-
116
- scope.$watch('markers.' + mkey, function() {
117
- marker.setLatLng(scope.markers[mkey]);
118
- }, true);
119
-
120
- scope.$watch("markers" + mkey + ".lng", function (newValue, oldValue) {
121
- if (dragging_marker || !newValue) return;
122
- marker.setLatLng(new L.LatLng(marker.getLatLng().lat, newValue));
123
- });
124
-
125
- scope.$watch("markers" + mkey + ".lat", function (newValue, oldValue) {
126
- if (dragging_marker || !newValue) return;
127
- marker.setLatLng(new L.LatLng(newValue, marker.getLatLng().lng));
128
- });
129
- return marker;
130
- }; // end of create and link marker
131
-
132
- scope.$watch("markers", function(newMarkerList) {
133
- // find deleted markers
134
- for (var delkey in markers_dict) {
135
- if (!scope.markers[delkey]) {
136
- map.removeLayer(markers_dict[delkey]);
137
- delete markers_dict[delkey];
138
- }
139
- }
140
- // add new markers
141
- for (var mkey in scope.markers) {
142
- if (markers_dict[mkey] === undefined) {
143
- var marker = createAndLinkMarker(mkey, scope);
144
- map.addLayer(marker);
145
- markers_dict[mkey] = marker;
146
- }
147
- } // for mkey in markers
148
- }, true); // watch markers
149
- } // if attrs.markers
150
-
151
- if (attrs.path) {
152
- var polyline = new L.Polyline([], { weight: 10, opacity: 1});
153
- map.addLayer(polyline);
154
- scope.$watch("path.latlngs", function(latlngs) {
155
- for (var idx=0, length=latlngs.length; idx < length; idx++) {
156
- if (latlngs[idx] === undefined || latlngs[idx].lat === undefined || latlngs[idx].lng === undefined) {
157
- $log.warn("Bad path point inn the $scope.path array ");
158
- latlngs.splice(idx, 1);
159
- }
160
- }
161
- polyline.setLatLngs(latlngs);
162
- }, true);
163
-
164
- scope.$watch("path.weight", function(weight) {
165
- polyline.setStyle({
166
- weight: weight
167
- });
168
- }, true);
169
-
170
- scope.$watch("path.color", function(color) {
171
- polyline.setStyle({
172
- color: color
173
- });
174
- }, true);
175
- } // end of attrs.path
176
- } // end of link function
177
- };
178
- }]);
1
+ //= require angular
2
+ //= require leaflet
3
+ //= require angular-leaflet-directive
@@ -0,0 +1,6 @@
1
+ /*
2
+ * This is just a proxy to leaflet-rails gem stylesheets
3
+ * to make require consistent inside rails app
4
+ *
5
+ *= require leaflet
6
+ */
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: angular-leaflet-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.1
4
+ version: 0.1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tymon Tobolski
@@ -10,6 +10,34 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2013-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: angular-rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: leaflet-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -51,8 +79,11 @@ files:
51
79
  - README.md
52
80
  - Rakefile
53
81
  - angular-leaflet-rails.gemspec
82
+ - lib/angular-leaflet-rails.rb
54
83
  - lib/angular-leaflet-rails/version.rb
84
+ - vendor/assets/javascripts/angular-leaflet-directive.js
55
85
  - vendor/assets/javascripts/angular-leaflet.js
86
+ - vendor/assets/stylesheets/angular-leaflet.css
56
87
  homepage: http://github.com/rails-assets/angular-leaflet-rails
57
88
  licenses:
58
89
  - MIT