]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/leaflet.note.js
Add clearer close action, refactor base layer code
[rails.git] / app / assets / javascripts / leaflet.note.js
index 43717f2c1acd0ea2fd335151e22e903892a50a09..68e09c88deb90a4403479d5b30660f53f04c522a 100644 (file)
@@ -1,39 +1,31 @@
-L.Control.Note = L.Control.extend({
-    options: {
-        position: 'topright',
-        title: 'Notes',
-    },
+L.OSM.note = function (options) {
+  var control = L.control(options);
 
-    onAdd: function (map) {
-        var className = 'leaflet-control-locate',
-            classNames = className + ' leaflet-control-zoom leaflet-bar leaflet-control',
-            container = L.DomUtil.create('div', classNames);
+  control.onAdd = function (map) {
+    var $container = $('<div>')
+      .attr('class', 'control-note');
 
-        var link = L.DomUtil.create('a', 'leaflet-bar-part leaflet-bar-part-single', container);
-        link.href = '#';
-        link.title = this.options.title;
+    $('<a>')
+      .attr('class', 'control-button')
+      .attr('href', '#')
+      .attr('title', 'Notes')
+      .html('<span class="icon note"></span>')
+      .on('click', toggle)
+      .appendTo($container);
 
-        L.DomEvent
-            .on(link, 'click', L.DomEvent.stopPropagation)
-            .on(link, 'click', L.DomEvent.preventDefault)
-            .on(link, 'click', this._toggle, this)
-            .on(link, 'dblclick', L.DomEvent.stopPropagation);
+    function toggle(e) {
+      e.stopPropagation();
+      e.preventDefault();
 
-        this.map = map;
-
-        return container;
-    },
-
-    // TODO: this relies on notesLayer on the map
-    _toggle: function() {
-        if (this.map.hasLayer(this.map.noteLayer)) {
-            this.map.removeLayer(this.map.noteLayer);
-        } else {
-            this.map.addLayer(this.map.noteLayer);
-        }
+      if (map.hasLayer(map.noteLayer)) {
+        map.removeLayer(map.noteLayer);
+      } else {
+        map.addLayer(map.noteLayer);
+      }
     }
-});
 
-L.control.note = function(options) {
-    return new L.Control.Note(options);
+    return $container[0];
+  };
+
+  return control;
 };