angular-leaflet-rails 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +26 -0
- data/Rakefile +6 -0
- data/angular-leaflet-rails.gemspec +23 -0
- data/lib/angular-leaflet-rails/version.rb +5 -0
- data/vendor/assets/javascripts/angular-leaflet.js +173 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e8700dc973f07864d75fb305b5674daafc0894c0
|
4
|
+
data.tar.gz: 1a1a848a1da0b15f8d5a9002e3e55e0939a34508
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 78f383c44ce9da940aa2ecab083e45490aafcc1c90a855cae3724b452f8076e8fd5058940e38ed80d20f95af30e55a8386a46362ec55096c245dbea1e733a308
|
7
|
+
data.tar.gz: d230e3cfb9e23def7aa995bbb033be718c4a2facd261c78a7e6e7b1812ac2221c5837be2877709bcf7d2d71d9066b6f49408dc55f75cd0a7c373c7144c961b86
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Tymon Tobolski
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# angular-leaflet-rails
|
2
|
+
|
3
|
+
[angular-leaflet-directive](https://github.com/tombatossals/angular-leaflet-directive) packaged for Rails assets pipeline.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Add the following to your gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "angular-leaflet-rails"
|
11
|
+
```
|
12
|
+
|
13
|
+
Add the following directive to your Javascript manifest file (application.js):
|
14
|
+
|
15
|
+
```js
|
16
|
+
//= require angular-ui
|
17
|
+
```
|
18
|
+
|
19
|
+
|
20
|
+
## Contributing
|
21
|
+
|
22
|
+
1. Fork it
|
23
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
24
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
25
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
26
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
desc "Fetch new version from https://github.com/tombatossals/angular-leaflet-directive"
|
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`
|
6
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'angular-leaflet-rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "angular-leaflet-rails"
|
8
|
+
spec.version = AngularLeaflet::Rails::VERSION
|
9
|
+
spec.authors = ["Tymon Tobolski"]
|
10
|
+
spec.email = ["i@teamon.eu"]
|
11
|
+
spec.description = %q{angular-leaflet-directive packaged for Rails assets pipeline}
|
12
|
+
spec.summary = %q{angular-leaflet-directive packaged for Rails assets pipeline}
|
13
|
+
spec.homepage = "http://github.com/rails-assets/angular-leaflet-rails"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,173 @@
|
|
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 initial view
|
26
|
+
map.setView([0, 0], 1);
|
27
|
+
|
28
|
+
// Set tile layer
|
29
|
+
var tilelayer = scope.tilelayer || 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
|
30
|
+
var maxZoom = scope.maxZoom || 12;
|
31
|
+
L.tileLayer(tilelayer, { maxZoom: maxZoom }).addTo(map);
|
32
|
+
|
33
|
+
// Manage map center events
|
34
|
+
if (attrs.center && scope.center) {
|
35
|
+
|
36
|
+
if (scope.center.lat && scope.center.lng && scope.center.zoom) {
|
37
|
+
map.setView(new L.LatLng(scope.center.lat, scope.center.lng), scope.center.zoom);
|
38
|
+
} else if (scope.center.autoDiscover === true) {
|
39
|
+
map.locate({ setView: true, maxZoom: maxZoom });
|
40
|
+
}
|
41
|
+
|
42
|
+
map.on("dragend", function(e) {
|
43
|
+
scope.$apply(function (s) {
|
44
|
+
s.center.lat = map.getCenter().lat;
|
45
|
+
s.center.lng = map.getCenter().lng;
|
46
|
+
});
|
47
|
+
});
|
48
|
+
|
49
|
+
map.on("zoomend", function(e) {
|
50
|
+
scope.$apply(function (s) {
|
51
|
+
s.center.zoom = map.getZoom();
|
52
|
+
});
|
53
|
+
});
|
54
|
+
|
55
|
+
scope.$watch("center", function (center, oldValue) {
|
56
|
+
map.setView([center.lat, center.lng], center.zoom);
|
57
|
+
}, true);
|
58
|
+
}
|
59
|
+
|
60
|
+
if (attrs.markers !== undefined) {
|
61
|
+
var markers_dict = [];
|
62
|
+
|
63
|
+
var createAndLinkMarker = function(mkey, scope) {
|
64
|
+
var markerData = scope.markers[mkey];
|
65
|
+
var marker = new L.marker(
|
66
|
+
scope.markers[mkey],
|
67
|
+
{
|
68
|
+
draggable: markerData.draggable ? true:false
|
69
|
+
}
|
70
|
+
);
|
71
|
+
|
72
|
+
if (markerData.message) {
|
73
|
+
scope.$watch("markers." + mkey + ".message", function(newValue) {
|
74
|
+
marker.bindPopup(markerData.message);
|
75
|
+
});
|
76
|
+
|
77
|
+
scope.$watch("markers." + mkey + ".focus", function(newValue) {
|
78
|
+
if (newValue) {
|
79
|
+
marker.openPopup();
|
80
|
+
}
|
81
|
+
});
|
82
|
+
}
|
83
|
+
|
84
|
+
scope.$watch("markers." + mkey + ".draggable", function (newValue, oldValue) {
|
85
|
+
if (newValue === false) {
|
86
|
+
marker.dragging.disable();
|
87
|
+
} else if (newValue === true) {
|
88
|
+
marker.dragging.enable();
|
89
|
+
}
|
90
|
+
});
|
91
|
+
|
92
|
+
var dragging_marker = false;
|
93
|
+
marker.on("dragstart", function(e) {
|
94
|
+
dragging_marker = true;
|
95
|
+
});
|
96
|
+
|
97
|
+
marker.on("drag", function (e) {
|
98
|
+
scope.$apply(function (s) {
|
99
|
+
markerData.lat = marker.getLatLng().lat;
|
100
|
+
markerData.lng = marker.getLatLng().lng;
|
101
|
+
});
|
102
|
+
});
|
103
|
+
|
104
|
+
marker.on("dragend", function(e) {
|
105
|
+
dragging_marker = false;
|
106
|
+
if (markerData.message) {
|
107
|
+
marker.openPopup();
|
108
|
+
}
|
109
|
+
});
|
110
|
+
|
111
|
+
scope.$watch('markers.' + mkey, function() {
|
112
|
+
marker.setLatLng(scope.markers[mkey]);
|
113
|
+
}, true);
|
114
|
+
|
115
|
+
scope.$watch("markers" + mkey + ".lng", function (newValue, oldValue) {
|
116
|
+
if (dragging_marker || !newValue) return;
|
117
|
+
marker.setLatLng(new L.LatLng(marker.getLatLng().lat, newValue));
|
118
|
+
});
|
119
|
+
|
120
|
+
scope.$watch("markers" + mkey + ".lat", function (newValue, oldValue) {
|
121
|
+
if (dragging_marker || !newValue) return;
|
122
|
+
marker.setLatLng(new L.LatLng(newValue, marker.getLatLng().lng));
|
123
|
+
});
|
124
|
+
return marker;
|
125
|
+
}; // end of create and link marker
|
126
|
+
|
127
|
+
scope.$watch("markers", function(newMarkerList) {
|
128
|
+
// find deleted markers
|
129
|
+
for (var delkey in markers_dict) {
|
130
|
+
if (!scope.markers[delkey]) {
|
131
|
+
map.removeLayer(markers_dict[delkey]);
|
132
|
+
delete markers_dict[delkey];
|
133
|
+
}
|
134
|
+
}
|
135
|
+
// add new markers
|
136
|
+
for (var mkey in scope.markers) {
|
137
|
+
if (markers_dict[mkey] === undefined) {
|
138
|
+
var marker = createAndLinkMarker(mkey, scope);
|
139
|
+
map.addLayer(marker);
|
140
|
+
markers_dict[mkey] = marker;
|
141
|
+
}
|
142
|
+
} // for mkey in markers
|
143
|
+
}, true); // watch markers
|
144
|
+
} // if attrs.markers
|
145
|
+
|
146
|
+
if (attrs.path) {
|
147
|
+
var polyline = new L.Polyline([], { weight: 10, opacity: 1});
|
148
|
+
map.addLayer(polyline);
|
149
|
+
scope.$watch("path.latlngs", function(latlngs) {
|
150
|
+
for (var idx=0, length=latlngs.length; idx < length; idx++) {
|
151
|
+
if (latlngs[idx] === undefined || latlngs[idx].lat === undefined || latlngs[idx].lng === undefined) {
|
152
|
+
$log.warn("Bad path point inn the $scope.path array ");
|
153
|
+
latlngs.splice(idx, 1);
|
154
|
+
}
|
155
|
+
}
|
156
|
+
polyline.setLatLngs(latlngs);
|
157
|
+
}, true);
|
158
|
+
|
159
|
+
scope.$watch("path.weight", function(weight) {
|
160
|
+
polyline.setStyle({
|
161
|
+
weight: weight
|
162
|
+
});
|
163
|
+
}, true);
|
164
|
+
|
165
|
+
scope.$watch("path.color", function(color) {
|
166
|
+
polyline.setStyle({
|
167
|
+
color: color
|
168
|
+
});
|
169
|
+
}, true);
|
170
|
+
} // end of attrs.path
|
171
|
+
} // end of link function
|
172
|
+
};
|
173
|
+
}]);
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: angular-leaflet-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tymon Tobolski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: angular-leaflet-directive packaged for Rails assets pipeline
|
42
|
+
email:
|
43
|
+
- i@teamon.eu
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- angular-leaflet-rails.gemspec
|
54
|
+
- lib/angular-leaflet-rails/version.rb
|
55
|
+
- vendor/assets/javascripts/angular-leaflet.js
|
56
|
+
homepage: http://github.com/rails-assets/angular-leaflet-rails
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.0.0
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: angular-leaflet-directive packaged for Rails assets pipeline
|
80
|
+
test_files: []
|
81
|
+
has_rdoc:
|