Skip to content

Commit 72c1137

Browse files
committed
Fixed dependencies
1 parent b190fd4 commit 72c1137

File tree

8 files changed

+188
-180
lines changed

8 files changed

+188
-180
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ Add the following directive to your Javascript manifest file (application.js):
1616
//= require angular-leaflet
1717
```
1818

19+
Add the following directive to your CSS manifest file (application.css):
20+
21+
```css
22+
*= require angular-leaflet
23+
```
24+
25+
26+
1927

2028
## Contributing
2129

Rakefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ require "bundler/gem_tasks"
22

33
desc "Fetch new version from https://github.com/tombatossals/angular-leaflet-directive"
44
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}"
68
end

angular-leaflet-rails.gemspec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Gem::Specification.new do |spec|
1818
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
1919
spec.require_paths = ["lib"]
2020

21+
spec.add_dependency "angular-rails"
22+
spec.add_dependency "leaflet-rails"
23+
2124
spec.add_development_dependency "bundler", "~> 1.3"
2225
spec.add_development_dependency "rake"
2326
end

lib/angular-leaflet-rails.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

lib/angular-leaflet-rails/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module AngularLeaflet
22
module Rails
3-
VERSION = "0.1.0.1"
3+
VERSION = "0.1.0.2"
44
end
55
end
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}]);
Lines changed: 3 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -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
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
*/

0 commit comments

Comments
 (0)