├── .gitignore ├── dist ├── distance │ ├── distance-icon.png │ ├── leaflet-control.css │ └── leaflet-control.js ├── validators │ ├── jquery-sources-control.js │ ├── jquery-errors-control.js │ ├── jstree-errors-control.js │ └── leaflet-layer.js └── weather │ └── leaflet-layer.js ├── package.json ├── Cakefile ├── LICENSE ├── src ├── validators │ ├── jstree-errors-control.coffee │ ├── jquery-sources-control.coffee │ ├── jquery-errors-control.coffee │ └── leaflet-layer.coffee ├── distance │ └── leaflet-control.coffee └── weather │ └── leaflet-layer.coffee ├── README.md └── examples ├── distance.html ├── weather.html ├── weather-imperial.html ├── validators.html └── validators-jstree.html /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | -------------------------------------------------------------------------------- /dist/distance/distance-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alno/osm-js-libs/HEAD/dist/distance/distance-icon.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "osm-js-libs", 3 | "description": "JavaScript libraries for OpenStreetMap applications", 4 | "version": "0.1.0", 5 | "author": "alno", 6 | "licenses": 7 | [{ 8 | "type": "MIT", 9 | "url": "https://github.com/maccman/spine/blob/master/LICENSE" 10 | }], 11 | "repository": { 12 | "type" : "git", 13 | "url": "http://github.com/alno/osm-js-libs.git" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Cakefile: -------------------------------------------------------------------------------- 1 | {print} = require 'util' 2 | {spawn} = require 'child_process' 3 | 4 | task 'build', 'Build dist/ from src/', -> 5 | coffee = spawn 'coffee', ['-c', '-o', 'dist', 'src'] 6 | coffee.stderr.on 'data', (data) -> 7 | process.stderr.write data.toString() 8 | coffee.stdout.on 'data', (data) -> 9 | print data.toString() 10 | coffee.on 'exit', (code) -> 11 | callback?() if code is 0 12 | 13 | task 'watch', 'Watch src/ for changes', -> 14 | coffee = spawn 'coffee', ['-w', '-c', '-o', 'dist', 'src'] 15 | coffee.stderr.on 'data', (data) -> 16 | process.stderr.write data.toString() 17 | coffee.stdout.on 'data', (data) -> 18 | print data.toString() 19 | -------------------------------------------------------------------------------- /dist/distance/leaflet-control.css: -------------------------------------------------------------------------------- 1 | .leaflet-control-distance { 2 | -moz-border-radius: 7px; 3 | -webkit-border-radius: 7px; 4 | border-radius: 7px; 5 | padding: 5px; 6 | background: rgba(0, 0, 0, 0.25); 7 | } 8 | 9 | .leaflet-control-distance a { 10 | background-color: rgba(255, 255, 255, 0.75); 11 | background-position: 50% 50%; 12 | background-repeat: no-repeat; 13 | background-image: url(distance-icon.png); 14 | display: block; 15 | -moz-border-radius: 4px; 16 | -webkit-border-radius: 4px; 17 | border-radius: 4px; 18 | width: 19px; 19 | height: 19px; 20 | } 21 | 22 | .leaflet-control-distance a:hover { 23 | background-color: #fff; 24 | } 25 | 26 | .leaflet-control-distance a.active { 27 | background-color: rgba(255, 255, 0, 0.75); 28 | } 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Alexey Noskov (alexey.noskov@gmail.com) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /src/validators/jstree-errors-control.coffee: -------------------------------------------------------------------------------- 1 | 2 | class JstreeValidatorErrorsControl 3 | 4 | constructor: (@elem, @layer, @options = {}) -> 5 | @elem.jstree( 6 | plugins: [ "json_data", "checkbox", "ui" ] 7 | json_data: 8 | data: 9 | @nodeJson(e) for e in @options.errors 10 | checkbox: 11 | override_ui: true 12 | ).bind("change_state.check_box.jstree", @stateChanged).bind("loaded.jstree", @stateChanged) 13 | 14 | @tree = jQuery.jstree._reference(@elem) 15 | @stateChanged() 16 | 17 | nodeJson: (err) -> 18 | data: err.name 19 | attr: 20 | "data-error-type": err.type 21 | children: @nodeJson(chd) for chd in (err.children or []) 22 | 23 | stateChanged: => 24 | for node in @tree.get_checked(null, true) when $(node).data('error-type') 25 | @layer.enableError $(node).data('error-type') 26 | 27 | for node in @tree.get_unchecked(null, true) when $(node).data('error-type') 28 | @layer.disableError $(node).data('error-type') 29 | 30 | jQuery.fn.validatorErrorsControl = (layer, options) -> 31 | @each -> 32 | new JstreeValidatorErrorsControl($(@), layer, options) 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JavaScript libraries for OpenStreetMap applications 2 | 3 | ## Usage 4 | 5 | ### Validators Leaflet layer 6 | 7 | Add validators layer to your Leaflet map by: 8 | 9 | map.addLayer(new OsmJs.Validators.LeafletLayer(config)) 10 | 11 | Where example config is: 12 | 13 | { 14 | validators: [{ 15 | "name": "Отладочный валидатор", 16 | "url": "http://alno.name:4567/validate?minlat={minlat}&minlon={minlon}&maxlat={maxlat}&maxlon={maxlon}", 17 | "offset_limit": true, 18 | "jsonp": true, 19 | "types": { 20 | "test_error": {"text": "Тестовая ошибка"} 21 | } 22 | }] 23 | } 24 | 25 | ### OpenWeatherMap weather layer 26 | 27 | ### Leaflet distance control 28 | 29 | Icon for distance control from here: http://findicons.com/icon/178351/ruler_2 30 | 31 | ## Building 32 | 33 | Install coffee-script first: 34 | 35 | sudo npm install --global coffee-script 36 | 37 | Then call: 38 | 39 | cake build 40 | 41 | That's all, now you have your updated library in dist/ 42 | 43 | ## Contributors 44 | 45 | * Alexey Noskov ({alno}[https://github.com/alno]) 46 | 47 | Copyright © 2012 Alexey Noskov, released under the {MIT license}[http://www.opensource.org/licenses/MIT] 48 | -------------------------------------------------------------------------------- /src/validators/jquery-sources-control.coffee: -------------------------------------------------------------------------------- 1 | 2 | class JqueryValidatorSourcesControl 3 | 4 | constructor: (@elem, @layer, @options = {}) -> 5 | @sources = [] 6 | 7 | if @options.sources 8 | for source in @options.sources 9 | @sources.push(source) 10 | 11 | for url, source of @layer.sources when @sources.indexOf(source) < 0 12 | @sources.push(source) 13 | 14 | @layer.on 'sourceadd', (e) => 15 | @sources.push(e.source) if @sources.indexOf(e.source) < 0 16 | @update() 17 | 18 | @layer.on 'sourceremove', @update, @ 19 | 20 | @update() 21 | 22 | update: -> 23 | @elem.html('') 24 | 25 | for source in @sources 26 | @elem.append(@buildListItem(source)) 27 | 28 | buildListItem: (source) -> 29 | cb = $('') 30 | cb.attr('checked', 'checked') if @layer.sources[source.url] 31 | cb.change => 32 | if cb.attr('checked') 33 | @layer.addSource(source) 34 | else 35 | @layer.removeSource(source) 36 | 37 | tx = $('') 38 | tx.text(source.name) 39 | 40 | li = $('
  • ') 41 | li.append(cb) 42 | li.append(tx) 43 | li 44 | 45 | 46 | jQuery.fn.validatorSourcesControl = (layer, options) -> 47 | @each -> 48 | new JqueryValidatorSourcesControl($(@), layer, options) 49 | -------------------------------------------------------------------------------- /examples/distance.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Leaflet distance example 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
    17 | 18 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /examples/weather.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Leaflet weather example 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
    16 | 17 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/validators/jquery-errors-control.coffee: -------------------------------------------------------------------------------- 1 | 2 | class JqueryValidatorErrorsControl 3 | 4 | constructor: (@elem, @layer, @options = {}) -> 5 | @errors = @options.errors 6 | 7 | @update() 8 | 9 | update: -> 10 | @elem.html('') 11 | 12 | for error in @errors 13 | @elem.append(@buildListItem(error)) 14 | 15 | buildListItem: (error) -> 16 | ul = $('