]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/index/element.js
Rename Browse javascript controllers to Element
[rails.git] / app / assets / javascripts / index / element.js
1 (function () {
2   OSM.Element = function () {
3     const page = {};
4
5     page.pushstate = page.popstate = function (path) {
6       OSM.loadSidebarContent(path);
7     };
8
9     return page;
10   };
11
12   OSM.MappedElement = function (map, type) {
13     const page = {};
14
15     page.pushstate = page.popstate = function (path, id, version) {
16       OSM.loadSidebarContent(path, function () {
17         addObject(type, id, version);
18       });
19     };
20
21     page.load = function (path, id, version) {
22       addObject(type, id, version, true);
23     };
24
25     function addObject(type, id, version, center) {
26       const hashParams = OSM.parseHash();
27       map.addObject({ type: type, id: parseInt(id, 10), version: version && parseInt(version, 10) }, function (bounds) {
28         if (!hashParams.center && bounds.isValid() &&
29             (center || !map.getBounds().contains(bounds))) {
30           OSM.router.withoutMoveListener(function () {
31             map.fitBounds(bounds);
32           });
33         }
34       });
35     }
36
37     page.unload = function () {
38       map.removeObject();
39     };
40
41     return page;
42   };
43 }());