leaflet-geosearch-rails 0.4.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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in leaflet-geosearch-rails.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Klaas Endrikat
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.
@@ -0,0 +1,48 @@
1
+ # Leaflet::GeoSearch::Rails
2
+
3
+ Integrates the [Leaflet GeoSearch] plugin with Rails asset pipeline
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'leaflet-geosearch-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install leaflet-geosearch-rails
18
+
19
+ ## Usage
20
+
21
+ Add the following to your `app/assets/javascripts/application.js`:
22
+
23
+ //= require leaflet.geosearch
24
+ //= require leaflet.geosearch.provider.openstreetmap
25
+ //= require leaflet.geosearch.provider.xyz
26
+
27
+ Add the following to your `app/assets/stylesheets/application.css`:
28
+
29
+ *= require leaflet.geosearch
30
+
31
+ Examples can be found at [smeijer]
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
40
+
41
+ ## License
42
+ MIT License, full text of license see [here][License]
43
+
44
+ *Free Software, Fuck Yeah!*
45
+
46
+ [License]: https://github.com/kendrikat/leaflet-geosearch-rails/blob/master/LICENSE.txt "LICENSE"
47
+ [Leaflet GeoSearch]: https://github.com/smeijer/L.GeoSearch
48
+ [smeijer]: https://github.com/smeijer/L.GeoSearch
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'leaflet-geosearch-rails/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "leaflet-geosearch-rails"
8
+ gem.version = Leaflet::Geosearch::Rails::VERSION
9
+ gem.authors = ["Klaas Endrikat"]
10
+ gem.email = ["klaas.endrikat@googlemail.com"]
11
+ gem.description = %q{Integrates the Leaflet GeoSearch plugin with Rails asset pipeline}
12
+ gem.summary = %q{Leaflet GeoSearch plugin for Rails}
13
+ gem.license = 'MIT'
14
+ gem.homepage = "https://github.com/kendrikat/leaflet-geosearch-rails"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+ end
@@ -0,0 +1,10 @@
1
+ require "leaflet-geosearch-rails/version"
2
+
3
+ module Leaflet
4
+ module Geosearch
5
+ module Rails
6
+ class Engine < ::Rails::Engine
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Leaflet
2
+ module Geosearch
3
+ module Rails
4
+ VERSION = "0.4.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,144 @@
1
+ /*
2
+ * L.Control.GeoSearch - search for an address and zoom to it's location
3
+ * https://github.com/smeijer/leaflet.control.geosearch
4
+ */
5
+
6
+ L.GeoSearch = {};
7
+ L.GeoSearch.Provider = {};
8
+
9
+ // MSIE needs cors support
10
+ jQuery.support.cors = true;
11
+
12
+ L.GeoSearch.Result = function (x, y, label) {
13
+ this.X = x;
14
+ this.Y = y;
15
+ this.Label = label;
16
+ };
17
+
18
+ L.Control.GeoSearch = L.Control.extend({
19
+ options: {
20
+ position: 'topcenter'
21
+ },
22
+
23
+ initialize: function (options) {
24
+ this._config = {};
25
+ L.Util.extend(this.options, options);
26
+ this.setConfig(options);
27
+ },
28
+
29
+ setConfig: function (options) {
30
+ this._config = {
31
+ 'country': options.country || '',
32
+ 'provider': options.provider,
33
+
34
+ 'searchLabel': options.searchLabel || 'search for address...',
35
+ 'notFoundMessage' : options.notFoundMessage || 'Sorry, that address could not be found.',
36
+ 'messageHideDelay': options.messageHideDelay || 3000,
37
+ 'zoomLevel': options.zoomLevel || 18
38
+ };
39
+ },
40
+
41
+ onAdd: function (map) {
42
+ var $controlContainer = $(map._controlContainer);
43
+
44
+ if ($controlContainer.children('.leaflet-top.leaflet-center').length == 0) {
45
+ $controlContainer.append('<div class="leaflet-top leaflet-center"></div>');
46
+ map._controlCorners.topcenter = $controlContainer.children('.leaflet-top.leaflet-center').first()[0];
47
+ }
48
+
49
+ this._map = map;
50
+ this._container = L.DomUtil.create('div', 'leaflet-control-geosearch');
51
+
52
+ var searchbox = document.createElement('input');
53
+ searchbox.id = 'leaflet-control-geosearch-qry';
54
+ searchbox.type = 'text';
55
+ searchbox.placeholder = this._config.searchLabel;
56
+ this._searchbox = searchbox;
57
+
58
+ var msgbox = document.createElement('div');
59
+ msgbox.id = 'leaflet-control-geosearch-msg';
60
+ msgbox.className = 'leaflet-control-geosearch-msg';
61
+ this._msgbox = msgbox;
62
+
63
+ var resultslist = document.createElement('ul');
64
+ resultslist.id = 'leaflet-control-geosearch-results';
65
+ this._resultslist = resultslist;
66
+
67
+ $(this._msgbox).append(this._resultslist);
68
+ $(this._container).append(this._searchbox, this._msgbox);
69
+
70
+ L.DomEvent
71
+ .addListener(this._container, 'click', L.DomEvent.stop)
72
+ .addListener(this._container, 'keypress', this._onKeyUp, this);
73
+
74
+ L.DomEvent.disableClickPropagation(this._container);
75
+
76
+ return this._container;
77
+ },
78
+
79
+ geosearch: function (qry) {
80
+ try {
81
+ var provider = this._config.provider;
82
+
83
+ if(typeof provider.GetLocations == 'function') {
84
+ var results = provider.GetLocations(qry, function(results) {
85
+ this._processResults(results);
86
+ }.bind(this));
87
+ }
88
+ else {
89
+ var url = provider.GetServiceUrl(qry);
90
+
91
+ $.getJSON(url, function (data) {
92
+ try {
93
+ var results = provider.ParseJSON(data);
94
+ this._processResults(results);
95
+ }
96
+ catch (error) {
97
+ this._printError(error);
98
+ }
99
+ }.bind(this));
100
+ }
101
+ }
102
+ catch (error) {
103
+ this._printError(error);
104
+ }
105
+ },
106
+
107
+ _processResults: function(results) {
108
+ if (results.length == 0)
109
+ throw this._config.notFoundMessage;
110
+
111
+ this._map.fireEvent('geosearch_foundlocations', {Locations: results});
112
+ this._showLocation(results[0]);
113
+ },
114
+
115
+ _showLocation: function (location) {
116
+ if (typeof this._positionMarker === 'undefined')
117
+ this._positionMarker = L.marker([location.Y, location.X]).addTo(this._map);
118
+ else
119
+ this._positionMarker.setLatLng([location.Y, location.X]);
120
+
121
+ this._map.setView([location.Y, location.X], this._config.zoomLevel, false);
122
+ this._map.fireEvent('geosearch_showlocation', {Location: location});
123
+ },
124
+
125
+ _printError: function(message) {
126
+ $(this._resultslist)
127
+ .html('<li>'+message+'</li>')
128
+ .fadeIn('slow').delay(this._config.messageHideDelay).fadeOut('slow',
129
+ function () { $(this).html(''); });
130
+ },
131
+
132
+ _onKeyUp: function (e) {
133
+ var escapeKey = 27;
134
+ var enterKey = 13;
135
+
136
+ if (e.keyCode === escapeKey) {
137
+ $('#leaflet-control-geosearch-qry').val('');
138
+ $(this._map._container).focus();
139
+ }
140
+ else if (e.keyCode === enterKey) {
141
+ this.geosearch($('#leaflet-control-geosearch-qry').val());
142
+ }
143
+ }
144
+ });
@@ -0,0 +1,40 @@
1
+ /**
2
+ * L.Control.GeoSearch - search for an address and zoom to it's location
3
+ * L.GeoSearch.Provider.Bing uses bing geocoding service
4
+ * https://github.com/smeijer/leaflet.control.geosearch
5
+ */
6
+
7
+ L.GeoSearch.Provider.Bing = L.Class.extend({
8
+ options: {
9
+
10
+ },
11
+
12
+ initialize: function (options) {
13
+ options = L.Util.setOptions(this, options);
14
+ },
15
+
16
+ GetServiceUrl: function (qry) {
17
+ var parameters = L.Util.extend({
18
+ query: qry,
19
+ jsonp: '?'
20
+ }, this.options);
21
+
22
+ return 'http://dev.virtualearth.net/REST/v1/Locations'
23
+ + L.Util.getParamString(parameters);
24
+ },
25
+
26
+ ParseJSON: function (data) {
27
+ if (data.resourceSets.length == 0 || data.resourceSets[0].resources.length == 0)
28
+ return [];
29
+
30
+ var results = [];
31
+ for (var i = 0; i < data.resourceSets[0].resources.length; i++)
32
+ results.push(new L.GeoSearch.Result(
33
+ data.resourceSets[0].resources[i].point.coordinates[1],
34
+ data.resourceSets[0].resources[i].point.coordinates[0],
35
+ data.resourceSets[0].resources[i].address.formattedAddress
36
+ ));
37
+
38
+ return results;
39
+ }
40
+ });
@@ -0,0 +1,40 @@
1
+ /**
2
+ * L.Control.GeoSearch - search for an address and zoom to it's location
3
+ * L.GeoSearch.Provider.Esri uses arcgis geocoding service
4
+ * https://github.com/smeijer/leaflet.control.geosearch
5
+ */
6
+
7
+ L.GeoSearch.Provider.Esri = L.Class.extend({
8
+ options: {
9
+
10
+ },
11
+
12
+ initialize: function(options) {
13
+ options = L.Util.setOptions(this, options);
14
+ },
15
+
16
+ GetServiceUrl: function (qry) {
17
+ var parameters = L.Util.extend({
18
+ text: qry,
19
+ f: 'pjson'
20
+ }, this.options);
21
+
22
+ return 'http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find'
23
+ + L.Util.getParamString(parameters);
24
+ },
25
+
26
+ ParseJSON: function (data) {
27
+ if (data.locations.length == 0)
28
+ return [];
29
+
30
+ var results = [];
31
+ for (var i = 0; i < data.locations.length; i++)
32
+ results.push(new L.GeoSearch.Result(
33
+ data.locations[i].feature.geometry.x,
34
+ data.locations[i].feature.geometry.y,
35
+ data.locations[i].name
36
+ ));
37
+
38
+ return results;
39
+ }
40
+ });
@@ -0,0 +1,50 @@
1
+ /**
2
+ * L.Control.GeoSearch - search for an address and zoom to it's location
3
+ * L.GeoSearch.Provider.Google uses google geocoding service
4
+ * https://github.com/smeijer/leaflet.control.geosearch
5
+ */
6
+
7
+ onLoadGoogleApiCallback = function() {
8
+ L.GeoSearch.Provider.Google.Geocoder = new google.maps.Geocoder();
9
+ };
10
+
11
+ L.GeoSearch.Provider.Google = L.Class.extend({
12
+ options: {
13
+
14
+ },
15
+
16
+ initialize: function(options) {
17
+ options = L.Util.setOptions(this, options);
18
+
19
+ $.ajax({
20
+ url: "https://maps.googleapis.com/maps/api/js?v=3&callback=onLoadGoogleApiCallback&sensor=false",
21
+ dataType: "script"
22
+ });
23
+ },
24
+
25
+ GetLocations: function(qry, callback) {
26
+ var geocoder = L.GeoSearch.Provider.Google.Geocoder;
27
+
28
+ var parameters = L.Util.extend({
29
+ address: qry
30
+ }, this.options);
31
+
32
+ var results = geocoder.geocode(parameters, function(data){
33
+ data = {results: data};
34
+
35
+ if (data.results.length == 0)
36
+ return [];
37
+
38
+ var results = [];
39
+ for (var i = 0; i < data.results.length; i++)
40
+ results.push(new L.GeoSearch.Result(
41
+ data.results[i].geometry.location.lng(),
42
+ data.results[i].geometry.location.lat(),
43
+ data.results[i].formatted_address
44
+ ));
45
+
46
+ if(typeof callback == 'function')
47
+ callback(results);
48
+ });
49
+ },
50
+ });
@@ -0,0 +1,40 @@
1
+ /**
2
+ * L.Control.GeoSearch - search for an address and zoom to it's location
3
+ * L.GeoSearch.Provider.Nokia uses Nokia geocoding service
4
+ * https://github.com/smeijer/leaflet.control.geosearch
5
+ */
6
+
7
+ L.GeoSearch.Provider.Nokia = L.Class.extend({
8
+ options: {
9
+
10
+ },
11
+
12
+ initialize: function(options) {
13
+ options = L.Util.setOptions(this, options);
14
+ },
15
+
16
+ GetServiceUrl: function (qry) {
17
+ var parameters = L.Util.extend({
18
+ searchtext: qry,
19
+ jsoncallback: '?'
20
+ }, this.options);
21
+
22
+ return 'http://geo.nlp.nokia.com/search/6.2/geocode.json'
23
+ + L.Util.getParamString(parameters);
24
+ },
25
+
26
+ ParseJSON: function (data) {
27
+ if (data.Response.View.length == 0 || data.Response.View[0].Result.length == 0)
28
+ return [];
29
+
30
+ var results = [];
31
+ for (var i = 0; i < data.Response.View[0].Result.length; i++)
32
+ results.push(new L.GeoSearch.Result(
33
+ data.Response.View[0].Result[i].Location.DisplayPosition.Longitude,
34
+ data.Response.View[0].Result[i].Location.DisplayPosition.Latitude,
35
+ data.Response.View[0].Result[i].Location.Address.Label
36
+ ));
37
+
38
+ return results;
39
+ }
40
+ });
@@ -0,0 +1,40 @@
1
+ /**
2
+ * L.Control.GeoSearch - search for an address and zoom to it's location
3
+ * L.GeoSearch.Provider.OpenStreetMap uses openstreetmap geocoding service
4
+ * https://github.com/smeijer/leaflet.control.geosearch
5
+ */
6
+
7
+ L.GeoSearch.Provider.OpenStreetMap = L.Class.extend({
8
+ options: {
9
+
10
+ },
11
+
12
+ initialize: function(options) {
13
+ options = L.Util.setOptions(this, options);
14
+ },
15
+
16
+ GetServiceUrl: function (qry) {
17
+ var parameters = L.Util.extend({
18
+ q: qry,
19
+ format: 'json'
20
+ }, this.options);
21
+
22
+ return 'http://nominatim.openstreetmap.org/search'
23
+ + L.Util.getParamString(parameters);
24
+ },
25
+
26
+ ParseJSON: function (data) {
27
+ if (data.length == 0)
28
+ return [];
29
+
30
+ var results = [];
31
+ for (var i = 0; i < data.length; i++)
32
+ results.push(new L.GeoSearch.Result(
33
+ data[i].lon,
34
+ data[i].lat,
35
+ data[i].display_name
36
+ ));
37
+
38
+ return results;
39
+ }
40
+ });
@@ -0,0 +1,38 @@
1
+ .leaflet-center {
2
+ width: 40%;
3
+ margin-left: auto;
4
+ margin-right: auto;
5
+ position: relative;
6
+ }
7
+ .leaflet-control-geosearch, .leaflet-control-geosearch ul {
8
+ border-radius: 7px;
9
+ background: none repeat scroll 0 0 rgba(0, 0, 0, 0.25);
10
+ margin: 10px 0 0 0;
11
+ padding: 5px;
12
+ width: 100%;
13
+ height: auto;
14
+ }
15
+ .leaflet-control-geosearch-msg ul {
16
+ list-style: none;
17
+ display: none;
18
+ height: auto;
19
+ background: none;
20
+ padding: 0;
21
+ }
22
+ .leaflet-control-geosearch ul li {
23
+ background: none repeat scroll 0 0 rgba(255, 255, 255, 0.75);
24
+ border-radius: 4px;
25
+ margin: 2px 0;
26
+ padding: 4px;
27
+ font: 12px arial;
28
+ text-indent: 4px;
29
+ }
30
+ .leaflet-container .leaflet-control-geosearch input {
31
+ width: 100%;
32
+ height: 28px;
33
+ padding: 0;
34
+ text-indent: 8px;
35
+ background: rgba(255, 255, 255, 0.75);
36
+ border-radius: 4px;
37
+ border: none;
38
+ }
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: leaflet-geosearch-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Klaas Endrikat
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-24 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Integrates the Leaflet GeoSearch plugin with Rails asset pipeline
15
+ email:
16
+ - klaas.endrikat@googlemail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - leaflet-geosearch-rails.gemspec
27
+ - lib/leaflet-geosearch-rails.rb
28
+ - lib/leaflet-geosearch-rails/version.rb
29
+ - vendor/assets/javascripts/leaflet.geosearch.js
30
+ - vendor/assets/javascripts/leaflet.geosearch.provider.bing.js
31
+ - vendor/assets/javascripts/leaflet.geosearch.provider.esri.js
32
+ - vendor/assets/javascripts/leaflet.geosearch.provider.google.js
33
+ - vendor/assets/javascripts/leaflet.geosearch.provider.nokia.js
34
+ - vendor/assets/javascripts/leaflet.geosearch.provider.openstreetmap.js
35
+ - vendor/assets/stylesheets/leaflet.geosearch.css
36
+ homepage: https://github.com/kendrikat/leaflet-geosearch-rails
37
+ licenses:
38
+ - MIT
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 1.8.24
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: Leaflet GeoSearch plugin for Rails
61
+ test_files: []