You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2839 lines
89 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("paper"));
  4. else if(typeof define === 'function' && define.amd)
  5. define(["paper"], factory);
  6. else if(typeof exports === 'object')
  7. exports["MetroFlow"] = factory(require("paper"));
  8. else
  9. root["MetroFlow"] = factory(root["paper"]);
  10. })(this, function(__WEBPACK_EXTERNAL_MODULE_1__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, {
  50. /******/ configurable: false,
  51. /******/ enumerable: true,
  52. /******/ get: getter
  53. /******/ });
  54. /******/ }
  55. /******/ };
  56. /******/
  57. /******/ // getDefaultExport function for compatibility with non-harmony modules
  58. /******/ __webpack_require__.n = function(module) {
  59. /******/ var getter = module && module.__esModule ?
  60. /******/ function getDefault() { return module['default']; } :
  61. /******/ function getModuleExports() { return module; };
  62. /******/ __webpack_require__.d(getter, 'a', getter);
  63. /******/ return getter;
  64. /******/ };
  65. /******/
  66. /******/ // Object.prototype.hasOwnProperty.call
  67. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  68. /******/
  69. /******/ // __webpack_public_path__
  70. /******/ __webpack_require__.p = "";
  71. /******/
  72. /******/ // Load entry module and return exports
  73. /******/ return __webpack_require__(__webpack_require__.s = 14);
  74. /******/ })
  75. /************************************************************************/
  76. /******/ ([
  77. /* 0 */
  78. /***/ (function(module, exports) {
  79. var DisplaySettings = {
  80. isDebug: false,
  81. };
  82. function uuidv4() {
  83. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  84. var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
  85. return v.toString(16);
  86. });
  87. }
  88. var Observable = {
  89. Observable: function() {
  90. this.observers = [];
  91. return this;
  92. },
  93. registerObserver: function(observer) {
  94. var index = this.observers.indexOf(observer);
  95. if (index === -1) {
  96. this.observers.push(observer);
  97. }
  98. },
  99. unregisterObserver: function(observer) {
  100. var index = this.observers.indexOf(observer);
  101. if (index > -1) {
  102. this.observers.splice(index, 1);
  103. }
  104. },
  105. notifyAllObservers: function() {
  106. for (var i = 0; i < this.observers.length; i++) {
  107. this.observers[i].notify(this);
  108. }
  109. },
  110. notifyBeforeRemove: function() {
  111. for (var i = 0; i < this.observers.length; i++) {
  112. this.observers[i].notifyRemove(this);
  113. }
  114. },
  115. };
  116. function Observer(notify, notifyRemove) {
  117. return {
  118. notify: notify,
  119. notifyRemove: notifyRemove,
  120. }
  121. };
  122. module.exports = {
  123. DisplaySettings: DisplaySettings,
  124. Observer: Observer,
  125. Observable: Observable,
  126. uuidv4: uuidv4,
  127. };
  128. /***/ }),
  129. /* 1 */
  130. /***/ (function(module, exports) {
  131. module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
  132. /***/ }),
  133. /* 2 */
  134. /***/ (function(module, exports) {
  135. var fillColor = "white";
  136. var strokeWidth = 8;
  137. var stationRadius = 1*strokeWidth;
  138. var selectionColor = rgbToHex(0, 100, 0);
  139. function componentToHex(c) {
  140. var hex = c.toString(16);
  141. return hex.length == 1 ? "0" + hex : hex;
  142. }
  143. function rgbToHex(r, g, b) {
  144. return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
  145. }
  146. var MapStyle = {
  147. };
  148. var TrackStyle = {
  149. };
  150. var SegmentStyle = {
  151. strokeColor: rgbToHex(255, 0, 0),
  152. strokeWidth: strokeWidth,
  153. selectionColor: selectionColor,
  154. fullySelected: false
  155. };
  156. var StationStyle = {
  157. strokeColor: rgbToHex(0, 0, 0),
  158. strokeWidth: strokeWidth/2,
  159. fillColor: fillColor,
  160. stationRadius: stationRadius,
  161. selectionColor: selectionColor,
  162. fullySelected: false
  163. };
  164. var StationMinorStyle = {
  165. strokeColor: SegmentStyle.strokeColor,
  166. strokeWidth: SegmentStyle.strokeWidth,
  167. selectionColor: selectionColor,
  168. minorStationSize: SegmentStyle.strokeWidth * 2.0,
  169. fullySelected: false
  170. };
  171. function createStationStyle() {
  172. var newStyle = {};
  173. Object.keys(StationStyle).forEach(function(key) {
  174. newStyle[key] = StationStyle[key];
  175. });
  176. return newStyle;
  177. }
  178. function createStationMinorStyle() {
  179. var newStyle = {};
  180. Object.keys(StationMinorStyle).forEach(function(key) {
  181. newStyle[key] = StationMinorStyle[key];
  182. });
  183. return newStyle;
  184. }
  185. function createSegmentStyle() {
  186. var newStyle = {};
  187. Object.keys(SegmentStyle).forEach(function(key) {
  188. newStyle[key] = SegmentStyle[key];
  189. });
  190. return newStyle;
  191. }
  192. module.exports = {
  193. createStationStyle: createStationStyle,
  194. createSegmentStyle: createSegmentStyle,
  195. createStationMinorStyle: createStationMinorStyle,
  196. rgbToHex: rgbToHex,
  197. };
  198. /***/ }),
  199. /* 3 */
  200. /***/ (function(module, exports, __webpack_require__) {
  201. util = __webpack_require__(0);
  202. var arcRadius = 8.0;
  203. var minStraight = 4.0*arcRadius;
  204. var Segment = {
  205. Segment: function(stationA, stationB, style) {
  206. // console.log('Segment.Segment()', stationA, stationB);
  207. this.stationA = stationA;
  208. this.stationB = stationB;
  209. this.stations = [stationA, stationB];
  210. this.stationsAuto = [];
  211. this.stationsUser = [stationA, stationB];
  212. this.style = style;
  213. this.id = util.uuidv4();
  214. this.path = null;
  215. this.isSelected = false;
  216. return this;
  217. },
  218. addStationAuto: function(station) {
  219. this.stationsAuto.push(station);
  220. this.stations.push(station);
  221. },
  222. addStationUser: function(station) {
  223. this.stationsUser.push(station);
  224. this.stations.push(station);
  225. },
  226. begin: function() {
  227. return this.stationA.position;
  228. },
  229. end: function() {
  230. return this.stationB.position;
  231. },
  232. direction: function() {
  233. return this.end() - this.begin();
  234. },
  235. center: function() {
  236. return this.begin() + (this.end() - this.begin())/2;
  237. },
  238. length: function() {
  239. return this.path.length;
  240. },
  241. getOffsetOf: function(position) {
  242. console.assert(position.x);
  243. console.assert(this.path, this);
  244. var position = this.path.getNearestPoint(position);
  245. return this.path.getOffsetOf(position);
  246. },
  247. toggleSelect: function() {
  248. if (this.isSelected) {
  249. this.deselect();
  250. } else {
  251. this.select();
  252. }
  253. },
  254. select: function() {
  255. this.isSelected = true;
  256. },
  257. deselect: function() {
  258. this.isSelected = false;
  259. },
  260. removeStation: function(id) {
  261. var station = this.findStation(id);
  262. if (!station) {
  263. return;
  264. }
  265. var pos = this.stations.indexOf(station);
  266. if (pos > -1) {
  267. this.stations.splice(pos, 1);
  268. }
  269. pos = this.stationsAuto.indexOf(station);
  270. if (pos > -1) {
  271. this.stationsAuto.splice(pos, 1);
  272. }
  273. pos = this.stationsUser.indexOf(station);
  274. if (pos > -1) {
  275. this.stationsUser.splice(pos, 1);
  276. }
  277. },
  278. getAllOnSegmentStations: function() {
  279. var stations = [];
  280. stations = stations.concat(this.stationsAuto);
  281. stations = stations.concat(this.stationsUser);
  282. var pos = stations.indexOf(this.stationA);
  283. if (pos != -1) {
  284. stations.splice(pos, 1);
  285. }
  286. var pos = stations.indexOf(this.stationB);
  287. if (pos != -1) {
  288. stations.splice(pos, 1);
  289. }
  290. return stations;
  291. },
  292. removeAllOnSegmentStations: function() {
  293. var stationsRemoved = [];
  294. var onSegementStations = this.getAllOnSegmentStations();
  295. for (var i in onSegementStations) {
  296. var station = onSegementStations[i];
  297. var pos = this.stationsAuto.indexOf(station);
  298. this.stationsAuto.splice(pos, 1);
  299. pos = this.stationsUser.indexOf(station);
  300. this.stationsUser.splice(pos, 1);
  301. stationsRemoved.push(station);
  302. }
  303. for (var i in stationsRemoved) {
  304. var pos = this.stations.indexOf(stationsRemoved[i]);
  305. if (pos != -1) {
  306. this.stations.splice(pos, 1);
  307. }
  308. }
  309. return stationsRemoved;
  310. },
  311. createNewPath: function() {
  312. var path = new Path();
  313. path.strokeColor = this.style.strokeColor;
  314. if (this.isSelected) {
  315. path.strokeColor = this.style.selectionColor;
  316. }
  317. path.strokeWidth = this.style.strokeWidth;
  318. path.strokeCap = 'round';
  319. path.strokeJoin = 'round';
  320. path.fullySelected = util.DisplaySettings.isDebug;
  321. return path;
  322. },
  323. getNearestStation: function(position, direction) {
  324. console.assert(position.x);
  325. var offsetPosition = this.getOffsetOf(position);
  326. var differenceMin = 1.0e99;
  327. var station = null;
  328. var stationOffset = null;
  329. for (var i in this.stationsUser) {
  330. var offset = this.getOffsetOf(this.stationsUser[i].position);
  331. var difference = (offset - offsetPosition) * direction;
  332. if (difference > 0 && difference < differenceMin) {
  333. differenceMin = difference;
  334. station = this.stationsUser[i];
  335. stationOffset = offset;
  336. }
  337. }
  338. return {station: station, offset: stationOffset};
  339. },
  340. getNextStation: function(position) {
  341. var direction = 1;
  342. var stationInfo = this.getNearestStation(position, direction);
  343. if (!stationInfo.station) {
  344. stationInfo.station = this.stationB;
  345. }
  346. return stationInfo;
  347. },
  348. getPreviousStation: function(position) {
  349. var direction = -1;
  350. var stationInfo = this.getNearestStation(position, direction);
  351. if (!stationInfo.station) {
  352. stationInfo.station = this.stationA;
  353. }
  354. return stationInfo;
  355. },
  356. getStationsBetween: function(stationA, stationB) {
  357. var offsetA = this.getOffsetOf(stationA.position);
  358. var offsetB = this.getOffsetOf(stationB.position);
  359. var stations = [];
  360. for (var i in this.stationsAuto) {
  361. var station = this.stationsAuto[i];
  362. var offset = this.getOffsetOf(station.position);
  363. if (offset >= offsetA && offset <= offsetB) {
  364. stations.push(station);
  365. }
  366. }
  367. return stations;
  368. },
  369. findStation: function(id) {
  370. for (var i in this.stations) {
  371. if (this.stations[i].id === id) {
  372. return this.stations[i];
  373. }
  374. }
  375. return null;
  376. },
  377. createPath: function(previous) {
  378. this.path = null;
  379. var stationVector = this.end() - this.begin();
  380. var maxDistance = Math.min(Math.abs(stationVector.x), Math.abs(stationVector.y)) - minStraight;
  381. var straightBegin = Math.abs(stationVector.y) - maxDistance;
  382. var straightEnd = Math.abs(stationVector.x) - maxDistance;
  383. straightBegin = Math.max(straightBegin, minStraight);
  384. straightEnd = Math.max(straightEnd, minStraight);
  385. // TODO: this is ugly and might not always work, needs to be vector based
  386. var arcBeginRel = new Point(0, straightBegin)*Math.sign(stationVector.y);
  387. var arcEndRel = new Point(straightEnd, 0)*Math.sign(stationVector.x);
  388. if (previous) {
  389. var tangentEndLastPath = previous.path.getTangentAt(previous.path.length);
  390. var inSameDirectionOutX = (Math.sign(stationVector.x) - tangentEndLastPath.x) !== 0;
  391. var inSameDirectionOutY = (Math.sign(stationVector.y) - tangentEndLastPath.y) !== 0;
  392. if (tangentEndLastPath.x !== 0 && !inSameDirectionOutX) {
  393. arcBeginRel = new Point(straightEnd, 0)*Math.sign(stationVector.x);
  394. arcEndRel = new Point(0, straightBegin)*Math.sign(stationVector.y);
  395. } else if (tangentEndLastPath.y !== 0 && inSameDirectionOutY) {
  396. arcBeginRel = new Point(straightEnd, 0)*Math.sign(stationVector.x);
  397. arcEndRel = new Point(0, straightBegin)*Math.sign(stationVector.y);
  398. }
  399. }
  400. var differenceXY = Math.abs(Math.abs(stationVector.normalize().x) - Math.abs(stationVector.normalize().y)); // is almost diagonal line?
  401. var needsArc = (differenceXY > 0.02) && Math.abs(stationVector.x) > minStraight+arcRadius*2 && Math.abs(stationVector.y) > minStraight+arcRadius*2;
  402. if (needsArc) {
  403. var arcEnd = this.end() - arcEndRel;
  404. var arcBegin = this.begin() + arcBeginRel;
  405. var beginPoint1 = arcBegin - arcBeginRel.normalize()*arcRadius;
  406. var beginPoint2 = arcBegin + (arcEnd-arcBegin).normalize()*arcRadius;
  407. var endPoint1 = arcEnd - (arcEnd-arcBegin).normalize()*arcRadius;
  408. var endPoint2 = arcEnd + arcEndRel.normalize()*arcRadius;
  409. this.path = this.createNewPath();
  410. this.path.add(this.begin());
  411. this.path.add(beginPoint1);
  412. this.path.quadraticCurveTo(arcBegin, beginPoint2);
  413. this.path.add(endPoint1);
  414. this.path.quadraticCurveTo(arcEnd, endPoint2);
  415. this.path.add(this.end());
  416. } else {
  417. this.path = this.createNewPath();
  418. this.path.add(this.begin());
  419. this.path.add(this.end());
  420. }
  421. if (util.DisplaySettings.isDebug) {
  422. var debugPointRadius = 4;
  423. var center = (stationVector)/2.0 + this.begin();
  424. var centerCircle = new Path.Circle(center, debugPointRadius);
  425. centerCircle.strokeWidth = 1;
  426. centerCircle.strokeColor = 'green';
  427. centerCircle.fillColor = 'green';
  428. centerCircle.remove();
  429. var arcBeginCircle = new Path.Circle(arcBegin, debugPointRadius);
  430. arcBeginCircle.style = centerCircle.style;
  431. arcBeginCircle.strokeColor = 'green';
  432. arcBeginCircle.fillColor = 'green';
  433. var arcEndCircle = new Path.Circle(arcEnd, debugPointRadius);
  434. arcEndCircle.style = arcBeginCircle.style;
  435. }
  436. this.path.sendToBack();
  437. },
  438. draw: function(previous, drawSettings) {
  439. // console.log('segment.draw()');
  440. var notifyObservers = !drawSettings.fast;
  441. this.stationA.updatePosition(this, notifyObservers);
  442. this.stationB.updatePosition(this, notifyObservers);
  443. this.createPath(previous);
  444. for (var i in this.stationsUser) {
  445. var station = this.stationsUser[i];
  446. station.updatePosition(this, notifyObservers);
  447. }
  448. for (var i in this.stationsAuto) {
  449. var station = this.stationsAuto[i];
  450. station.updatePosition(this, notifyObservers);
  451. }
  452. if (notifyObservers) {
  453. this.notifyAllObservers(this);
  454. }
  455. // path.fullySelected = true;
  456. // return path;
  457. },
  458. };
  459. function createSegment(stationA, stationB, style) {
  460. console.log('createSegment');
  461. var observable = Object.create(util.Observable).Observable();
  462. var segment = Object.assign(observable, Segment);
  463. segment = segment.Segment(stationA, stationB, style);
  464. return segment;
  465. }
  466. module.exports = {
  467. createSegment: createSegment,
  468. minStraight: minStraight,
  469. arcRadius: arcRadius,
  470. };
  471. /***/ }),
  472. /* 4 */
  473. /***/ (function(module, exports, __webpack_require__) {
  474. util = __webpack_require__(0);
  475. metrotrack = __webpack_require__(5);
  476. metroconnection = __webpack_require__(7);
  477. var DrawSettings = {
  478. text: true,
  479. fast: false,
  480. calcTextPositions: false,
  481. minorStationText: false,
  482. };
  483. function createDrawSettings() {
  484. var drawSettings = {};
  485. Object.keys(DrawSettings).forEach(function(key) {
  486. drawSettings[key] = DrawSettings[key];
  487. });
  488. return drawSettings;
  489. }
  490. var Map = {
  491. Map: function() {
  492. this.tracks = [];
  493. this.connections = [];
  494. return this;
  495. },
  496. createTrack: function() {
  497. console.log('map.createTrack()');
  498. var newTrack = metrotrack.createTrack();
  499. this.tracks.push(newTrack);
  500. return newTrack;
  501. },
  502. createConnection: function(stationA, stationB) {
  503. console.log('map.createConnection()');
  504. if (stationA.id === stationB.id) {
  505. return null
  506. }
  507. var newConnection = metroconnection.createConnection(stationA, stationB);
  508. this.connections.push(newConnection);
  509. return newConnection;
  510. },
  511. removeStation: function(id) {
  512. for (var i in this.tracks) {
  513. this.tracks[i].removeStation(id);
  514. }
  515. for (var i = this.connections.length - 1; i >= 0; i--) {
  516. if (this.connections[i].stationA.id === id || this.connections[i].stationB.id === id) {
  517. this.connections.splice(i, 1);
  518. }
  519. }
  520. },
  521. stations: function() {
  522. var stations = [];
  523. for (var i in this.tracks) {
  524. stations = stations.concat(this.tracks[i].stations);
  525. }
  526. return stations;
  527. },
  528. segments: function() {
  529. var segments = [];
  530. for (var i in this.tracks) {
  531. segments = segments.concat(this.tracks[i].segments);
  532. }
  533. return segments;
  534. },
  535. draw: function(drawSettings) {
  536. console.time("map.draw");
  537. project.clear();
  538. for (var i in this.tracks) {
  539. this.tracks[i].draw(drawSettings);
  540. }
  541. for (var i in this.connections) {
  542. this.connections[i].draw();
  543. }
  544. if (drawSettings.text) {
  545. var paths = [];
  546. if (!drawSettings.fast) {
  547. paths = this.allPaths();
  548. console.log("map.draw() paths.length", paths.length);
  549. }
  550. this.drawStationNames(paths, drawSettings);
  551. }
  552. console.timeEnd("map.draw");
  553. },
  554. clear: function() {
  555. this.tracks = [];
  556. },
  557. drawStationNames: function(paths, drawSettings) {
  558. for (var i in this.tracks) {
  559. this.tracks[i].drawStationNames(paths, drawSettings);
  560. }
  561. },
  562. allPaths: function() {
  563. var paths = [];
  564. for (var i in this.tracks) {
  565. paths = paths.concat(this.tracks[i].allPaths());
  566. }
  567. for (var i in this.connections) {
  568. paths = paths.concat(this.connections[i].allPaths());
  569. }
  570. return paths;
  571. },
  572. findStation: function(id) {
  573. for (var i in this.tracks) {
  574. var station = this.tracks[i].findStation(id);
  575. if (station) {
  576. return station;
  577. }
  578. }
  579. return null;
  580. },
  581. findStationByPathId: function(id) {
  582. for (var i in this.tracks) {
  583. var track = this.tracks[i];
  584. var station = track.findStationByPathId(id);
  585. if (station) {
  586. return {station: station, track: track};
  587. }
  588. }
  589. return {station: null, track: null};
  590. },
  591. findSegment: function(id) {
  592. for (var i in this.tracks) {
  593. var track = this.tracks[i];
  594. var segment = track.findSegment(id);
  595. if (segment) {
  596. return {segment: segment, track: track};
  597. }
  598. }
  599. return {segment: null, track: null};
  600. },
  601. findSegmentByPathId: function(id) {
  602. for (var i in this.tracks) {
  603. var track = this.tracks[i];
  604. var segment = track.findSegmentByPathId(id);
  605. if (segment) {
  606. return {segment: segment, track: track};
  607. }
  608. }
  609. return {segment: null, track: null};
  610. },
  611. findTrack: function(id) {
  612. for (var i in this.tracks) {
  613. if (this.tracks[i].id === id) {
  614. return this.tracks[i];
  615. }
  616. }
  617. return null;
  618. },
  619. notifyAllStationsAndSegments: function () {
  620. var stations = this.stations();
  621. for (var i in stations) {
  622. stations[i].notifyAllObservers();
  623. }
  624. var segments = this.segments();
  625. for (var i in segments) {
  626. segments[i].notifyAllObservers();
  627. }
  628. }
  629. };
  630. function createMap() {
  631. var observable = Object.create(util.Observable).Observable();
  632. var map = Object.assign(observable, Map);
  633. map = map.Map();
  634. return map;
  635. }
  636. module.exports = {
  637. createMap: createMap,
  638. createDrawSettings: createDrawSettings,
  639. };
  640. /***/ }),
  641. /* 5 */
  642. /***/ (function(module, exports, __webpack_require__) {
  643. __webpack_require__(1);
  644. var util = __webpack_require__(0);
  645. var metrosegment = __webpack_require__(3);
  646. var metrostation = __webpack_require__(6);
  647. var metrostyles = __webpack_require__(2);
  648. var Track = {
  649. Track: function() {
  650. this.segments = [];
  651. this.id = util.uuidv4();
  652. this.stations = [];
  653. this.stationsMajor = [];
  654. this.stationsMinor = [];
  655. this.segmentStyle = metrostyles.createSegmentStyle();
  656. this.stationStyle = metrostyles.createStationStyle();
  657. this.stationMinorStyle = metrostyles.createStationMinorStyle();
  658. this.stationMinorStyle.strokeColor = this.segmentStyle.strokeColor;
  659. return this;
  660. },
  661. setStationRadius: function(radius) {
  662. this.stationStyle.stationRadius = radius;
  663. },
  664. setStationStrokeWidth: function(strokeWidth) {
  665. this.stationStyle.strokeWidth = strokeWidth;
  666. },
  667. setSegmentStyle: function(style) {
  668. this.segmentStyle = style;
  669. this.stationMinorStyle.strokeWidth = this.segmentStyle.strokeWidth;
  670. this.stationMinorStyle.strokeColor = this.segmentStyle.strokeColor;
  671. this.stationMinorStyle.minorStationSize = this.segmentStyle.strokeWidth * 2.0;
  672. },
  673. setStationStyle: function(style) {
  674. this.stationStyle = style;
  675. },
  676. createStationFree: function(position, previousStation) {
  677. var station = metrostation.createStationFree(position, this.stationStyle);
  678. if (previousStation) {
  679. this.createSegment(previousStation, station)
  680. }
  681. this.stations.push(station);
  682. this.stationsMajor.push(station);
  683. console.log('create station', station.id);
  684. this.notifyAllObservers();
  685. return station;
  686. },
  687. createStationOnSegment: function(segment, offsetFactor) {
  688. var station = metrostation.createStationSegment(offsetFactor, this.stationStyle);
  689. this.stations.push(station);
  690. this.stationsMajor.push(station);
  691. segment.addStationUser(station);
  692. this.notifyAllObservers();
  693. return station;
  694. },
  695. createSegment: function(stationA, stationB) {
  696. console.log('track.createSegment', stationA.id, stationB.id);
  697. var segment = metrosegment.createSegment(stationA, stationB, this.segmentStyle);
  698. this.segments.push(segment);
  699. this.notifyAllObservers();
  700. return segment;
  701. },
  702. createStationMinorOnSegmentId: function(position, segmentId) {
  703. var segment = this.findSegment(segmentId);
  704. position = segment.path.getNearestPoint(position);
  705. return this.createStationMinor(position, segment);
  706. },
  707. createStationMinor: function(position, segment) {
  708. var station = metrostation.createStationMinor(position, segment.stationA, segment.stationB, this.stationMinorStyle);
  709. segment.addStationAuto(station);
  710. station.setPosition(position, segment);
  711. this.stations.push(station);
  712. this.stationsMinor.push(station);
  713. this.notifyAllObservers();
  714. return station;
  715. },
  716. segmentToStation: function(station) {
  717. for (var i in this.segments) {
  718. var segment = this.segments[i];
  719. if (segment.stationB.id === station.id) {
  720. return segment;
  721. }
  722. }
  723. return null;
  724. },
  725. segmentFromStation: function(station) {
  726. for (var i in this.segments) {
  727. var segment = this.segments[i];
  728. if (segment.stationA.id === station.id) {
  729. return segment;
  730. }
  731. }
  732. return null;
  733. },
  734. lastAddedStation: function() {
  735. if (this.stationsMajor.length === 0) {
  736. return null;
  737. }
  738. return this.stationsMajor[this.stationsMajor.length - 1];
  739. },
  740. connectedStations: function(station) {
  741. var stations = [];
  742. for (var i in this.segments) {
  743. var segment = this.segments[i];
  744. if (station.id === segment.stationA.id) {
  745. stations.push(segment.stationB);
  746. }
  747. if (station.id === segment.stationB.id) {
  748. stations.push(segment.stationA);
  749. }
  750. }
  751. return stations;
  752. },
  753. allPaths: function() {
  754. var paths = [];
  755. for (var i in this.segments) {
  756. paths.push(this.segments[i].path);
  757. }
  758. return paths;
  759. },
  760. draw: function(drawSettings) {
  761. // console.log('track.draw()');
  762. for (var i in this.segments) {
  763. var segment = this.segments[i];
  764. var previous = this.segmentToStation(segment.stationA);
  765. segment.draw(previous, drawSettings);
  766. }
  767. for (var i in this.stationsMinor) {
  768. var stationMinor = this.stationsMinor[i];
  769. var segment = this.findSegmentForStationMinor(stationMinor);
  770. this.stationsMinor[i].draw(segment);
  771. }
  772. for (var i in this.stationsMajor) {
  773. this.stationsMajor[i].draw();
  774. }
  775. // this.notifyAllObservers(this);
  776. },
  777. createText: function(station, positionRelative) {
  778. var text = new PointText(station.position + positionRelative);
  779. text.justification = 'left';
  780. text.fillColor = 'black';
  781. text.content = station.name;
  782. return text;
  783. },
  784. preventIntersectionSegments: function(text, station, paths, positions) {
  785. if (!paths) {
  786. return positions[0];
  787. }
  788. var positionsTried = 0;
  789. var intersects = true;
  790. while (intersects && positionsTried < positions.length) {
  791. intersects = false;
  792. for (var j in paths) {
  793. if (positionsTried >= positions.length-1) {
  794. break;
  795. }
  796. var path = paths[j];
  797. intersects = text.intersects(path);
  798. if (intersects) {
  799. var textOld = text;
  800. positionsTried++;
  801. text = this.createText(station, positions[positionsTried]);
  802. text.fontSize = textOld.fontSize;
  803. textOld.remove();
  804. break;
  805. }
  806. }
  807. }
  808. return positions[positionsTried];
  809. },
  810. drawStationNames: function(paths, drawSettings) {
  811. var fontSize = 14;
  812. this.drawMajorStationNames(paths, fontSize, drawSettings.calcTextPositions);
  813. fontSize = 10;
  814. if (drawSettings.minorStationText) {
  815. this.drawMinorStationNames(fontSize);
  816. }
  817. },
  818. drawMajorStationNames: function(paths, fontSize, calcTextPositions) {
  819. for (var i in this.stationsMajor) {
  820. var station = this.stationsMajor[i];
  821. if (!calcTextPositions && station.textPositionRel) {
  822. text = this.createText(station, station.textPositionRel);
  823. text.fontSize = fontSize;
  824. continue;
  825. }
  826. var stationRadius = station.style.stationRadius + station.style.strokeWidth;
  827. var defaultPosition = new Point(stationRadius, fontSize / 4.0)
  828. var text = this.createText(station, defaultPosition);
  829. text.fontSize = fontSize;
  830. if (!calcTextPositions) {
  831. continue;
  832. } else {
  833. console.log('recalc best text position');
  834. var positions = [];
  835. positions.push(defaultPosition);
  836. positions.push(new Point(-stationRadius - text.bounds.width, fontSize / 4.0));
  837. positions.push(new Point(0, -stationRadius * 1.2));
  838. positions.push(new Point(stationRadius, -stationRadius * 0.8));
  839. positions.push(new Point(-text.bounds.width, -stationRadius * 1.2));
  840. positions.push(new Point(-text.bounds.width-stationRadius, -stationRadius * 0.8));
  841. positions.push(new Point(0, stationRadius * 2.2));
  842. positions.push(new Point(stationRadius, stationRadius * 1.4));
  843. positions.push(new Point(-text.bounds.width, stationRadius * 2.2));
  844. positions.push(new Point(-text.bounds.width-stationRadius, stationRadius * 1.2));
  845. var pathsToUse = paths;
  846. if (paths.length === 0) {
  847. pathsToUse = this.stationSegmentPaths(station);
  848. }
  849. station.textPositionRel = this.preventIntersectionSegments(text, station, pathsToUse, positions);
  850. }
  851. }
  852. },
  853. stationSegmentPaths: function(station) {
  854. var segmentTo = this.segmentToStation(station);
  855. var segmentFrom = this.segmentFromStation(station);
  856. var segments = [];
  857. if (segmentTo) {
  858. segments.push(segmentTo);
  859. }
  860. if (segmentFrom) {
  861. segments.push(segmentFrom);
  862. }
  863. var pathsLocal = [];
  864. for (var i in segments) {
  865. for (var j in segments[i].paths) {
  866. pathsLocal.push(segments[i].paths[j]);
  867. }
  868. }
  869. return pathsLocal;
  870. },
  871. drawMinorStationNames: function(fontSize) {
  872. for (var i in this.stationsMinor) {
  873. var station = this.stationsMinor[i];
  874. var stationLineDirection = station.direction();
  875. var xOffset = 0;
  876. var position = station.direction()*station.style.minorStationSize*1.2;
  877. var text = this.createText(station, position);
  878. text.fontSize = fontSize;
  879. if (stationLineDirection.x < 0) {
  880. xOffset = -text.bounds.width;
  881. text.position += new Point(xOffset, 0);
  882. }
  883. if (stationLineDirection.y > 0.01) {
  884. yOffset = text.bounds.height/1.5;
  885. text.position += new Point(0, yOffset);
  886. }
  887. }
  888. },
  889. findStationByPathId: function(id) {
  890. for (var i in this.stations) {
  891. var stationId = this.stations[i].path.id;
  892. if (stationId === id) {
  893. return this.stations[i];
  894. }
  895. }
  896. return null;
  897. },
  898. findStation: function(id) {
  899. for (var i in this.stations) {
  900. if (this.stations[i].id === id) {
  901. return this.stations[i];
  902. }
  903. }
  904. return null;
  905. },
  906. removeStation: function(id) {
  907. console.log('track.removeStation() on track:', this.id);
  908. function removeFromTrackState(track, id) {
  909. var station = track.findStation(id);
  910. if (station) {
  911. console.log('track.removeStation()', station);
  912. var pos = track.stations.indexOf(station);
  913. if (pos > -1) {
  914. station.notifyBeforeRemove();
  915. track.stations.splice(pos, 1);
  916. }
  917. pos = track.stationsMajor.indexOf(station);
  918. if (pos > -1) {
  919. station.notifyBeforeRemove();
  920. track.stationsMajor.splice(pos, 1);
  921. }
  922. pos = track.stationsMinor.indexOf(station);
  923. if (pos > -1) {
  924. station.notifyBeforeRemove();
  925. track.stationsMinor.splice(pos, 1);
  926. }
  927. }
  928. }
  929. removeFromTrackState(this, id);
  930. for (var i = this.segments.length - 1; i >= 0; i--) { // loop backwards because we splice the array
  931. var segment = this.segments[i];
  932. if (segment.stationA.id === id || segment.stationB.id === id) {
  933. var pos = this.segments.indexOf(segment);
  934. if (pos > -1) {
  935. var stationsRemoved = segment.removeAllOnSegmentStations();
  936. for (var j in stationsRemoved) {
  937. removeFromTrackState(this, stationsRemoved[j].id);
  938. }
  939. this.segments.splice(pos, 1);
  940. }
  941. } else {
  942. segment.removeStation(id);
  943. }
  944. }
  945. return ;
  946. },
  947. findSegmentByPathId: function(id) {
  948. for (var i in this.segments) {
  949. if (this.segments[i].path.id === id) {
  950. return this.segments[i];
  951. }
  952. }
  953. return null;
  954. },
  955. findSegment: function(id) {
  956. for (var i in this.segments) {
  957. if (this.segments[i].id === id) {
  958. return this.segments[i];
  959. }
  960. }
  961. return null;
  962. },
  963. findSegmentBetweenStations: function(stationA, stationB) {
  964. for (var i in this.segments) {
  965. if (stationA.id === this.segments[i].stationA.id
  966. && stationB.id === this.segments[i].stationB.id) {
  967. return this.segments[i];
  968. }
  969. }
  970. return null;
  971. },
  972. findSegmentForStationMinor: function(stationMinor) {
  973. return this.findSegmentBetweenStations(stationMinor.stationA, stationMinor.stationB);
  974. },
  975. findSegmentsForStation: function(station) {
  976. var segments = [];
  977. for (var i in this.segments) {
  978. var index = this.segments[i].stations.indexOf(station);
  979. if (index != -1) {
  980. segments.push(this.segments[i]);
  981. }
  982. }
  983. return segments;
  984. }
  985. };
  986. function createTrack() {
  987. var observable = Object.create(util.Observable).Observable();
  988. var track = Object.assign(observable, Track);
  989. track = track.Track();
  990. return track;
  991. }
  992. module.exports = {
  993. createTrack: createTrack,
  994. };
  995. /***/ }),
  996. /* 6 */
  997. /***/ (function(module, exports, __webpack_require__) {
  998. __webpack_require__(1);
  999. util = __webpack_require__(0);
  1000. styles = __webpack_require__(2);
  1001. var Station = {
  1002. Station: function(position, style) {
  1003. console.log('new station for point', position);
  1004. this.position = position;
  1005. this.offsetFactor = null;
  1006. this.style = style;
  1007. this.id = util.uuidv4().substring(0, 8);
  1008. this.path = null;
  1009. this.isSelected = false;
  1010. this.name = "station";
  1011. this.textPositionRel = null;
  1012. this.doSnap = true;
  1013. return this;
  1014. },
  1015. toggleSelect: function() {
  1016. if (this.isSelected) {
  1017. this.deselect();
  1018. } else {
  1019. this.select();
  1020. }
  1021. },
  1022. select: function() {
  1023. this.isSelected = true;
  1024. },
  1025. deselect: function() {
  1026. this.isSelected = false;
  1027. },
  1028. setPosition: function(position, segment) {
  1029. this.doSetPosition(position, segment);
  1030. this.textPositionRel = null;
  1031. this.notifyAllObservers();
  1032. },
  1033. };
  1034. var StationPainter = {
  1035. draw: function() {
  1036. this.path = new Path.Circle(this.position, this.style.stationRadius);
  1037. if (this.isSelected) {
  1038. this.path.strokeColor = this.style.selectionColor;
  1039. } else {
  1040. this.path.strokeColor = this.style.strokeColor;
  1041. }
  1042. this.path.strokeWidth = this.style.strokeWidth;
  1043. this.path.fillColor = this.style.fillColor;
  1044. this.path.bringToFront();
  1045. },
  1046. };
  1047. var StationMinorPainter = {
  1048. draw: function(segment) {
  1049. var minorStationSize = this.style.minorStationSize;
  1050. this.path = new Path.Line(this.position, this.position + this.normalUnit*minorStationSize);
  1051. this.path.strokeColor = this.style.strokeColor;
  1052. this.path.strokeWidth = this.style.strokeWidth;
  1053. // this.path.fillColor = this.style.fillColor;
  1054. },
  1055. direction: function() {
  1056. return (this.path.lastSegment.point - this.path.firstSegment.point).normalize();
  1057. }
  1058. };
  1059. var StationPositionSegmentAuto = {
  1060. doSetPosition: function(position, segment) {
  1061. this.position = position;
  1062. },
  1063. updatePosition: function(segment, notifyObservers) {
  1064. // console.log('=======================================');
  1065. // console.log('StationPositionSegmentAuto.updatePosition');
  1066. // console.log('this.position', this.position);
  1067. // console.log('segment', segment);
  1068. var offsetFactor = segment.getOffsetOf(this.position) / segment.length();
  1069. var offset = segment.path.length * offsetFactor;
  1070. this.position = segment.path.getPointAt(offset);
  1071. var previousStationInfo = segment.getPreviousStation(this.position);
  1072. // console.log('previousStationInfo', previousStationInfo.station.id);
  1073. var offsetA = previousStationInfo.offset;
  1074. var nextStationInfo = segment.getNextStation(this.position);
  1075. var stationsAuto = segment.getStationsBetween(previousStationInfo.station, nextStationInfo.station);
  1076. var nStations = stationsAuto.length;
  1077. var offsetB = nextStationInfo.offset;
  1078. // console.log('nextStationInfo', nextStationInfo.station.id);
  1079. var totalLength = offsetB - offsetA;
  1080. // console.log('totalLength', totalLength);
  1081. // console.log('segment.length', segment.length());
  1082. var distanceBetweenStations = totalLength/(nStations+1);
  1083. var orderNr = stationsAuto.indexOf(this);
  1084. var stationOffset = distanceBetweenStations * (orderNr+1) + offsetA;
  1085. // console.log('stationsAuto', stationsAuto);
  1086. // console.log('orderNr', orderNr);
  1087. // console.log('stationOffset', stationOffset);
  1088. var position = segment.path.getPointAt(stationOffset);
  1089. console.assert(position);
  1090. if (position) {
  1091. this.position = position;
  1092. }
  1093. this.offsetFactor = segment.getOffsetOf(position) / segment.length();
  1094. // console.log('segment.getOffsetOf(this.position)', segment.getOffsetOf(this.position));
  1095. // console.log('offsetFactor', this.offsetFactor);
  1096. this.normalUnit = segment.path.getNormalAt(stationOffset);
  1097. if (notifyObservers) {
  1098. this.notifyAllObservers();
  1099. }
  1100. return this.position;
  1101. }
  1102. };
  1103. var StationPositionSegmentUser = {
  1104. doSetPosition: function(position, segment) {
  1105. this.offsetFactor = segment.getOffsetOf(position) / segment.length();
  1106. },
  1107. updatePosition: function(segment, notifyObservers) {
  1108. var distanceStation = segment.path.length * this.offsetFactor;
  1109. this.position = segment.path.getPointAt(distanceStation);
  1110. if (notifyObservers) {
  1111. this.notifyAllObservers();
  1112. }
  1113. return this.position;
  1114. }
  1115. };
  1116. var StationPositionFree = {
  1117. doSetPosition: function(position, segment) {
  1118. this.position = position;
  1119. },
  1120. updatePosition: function(segment, notifyObservers) {
  1121. if (notifyObservers) {
  1122. this.notifyAllObservers();
  1123. }
  1124. return this.position;
  1125. }
  1126. };
  1127. function createStationFree(position, style) {
  1128. var observable = Object.create(util.Observable).Observable();
  1129. var station = Object.assign(observable, Station, StationPositionFree, StationPainter);
  1130. if (!style) {
  1131. style = styles.createStationStyle();
  1132. }
  1133. station = station.Station(position, style);
  1134. return station;
  1135. }
  1136. function createStationSegment(offsetFactor, style) {
  1137. console.log('createStationMinor');
  1138. var observable = Object.create(util.Observable).Observable();
  1139. var station = Object.assign(observable, Station, StationPositionSegmentUser, StationPainter);
  1140. station = station.Station(new Point(0, 0), style);
  1141. station.offsetFactor = offsetFactor;
  1142. station.doSnap = false;
  1143. return station;
  1144. }
  1145. function createStationMinor(position, stationA, stationB, style) {
  1146. console.log('createStationMinor');
  1147. var observable = Object.create(util.Observable).Observable();
  1148. var station = Object.assign(observable, Station, StationPositionSegmentAuto, StationMinorPainter);
  1149. station = station.Station(position, style);
  1150. station.stationA = stationA;
  1151. station.stationB = stationB;
  1152. station.name = "minor station";
  1153. station.doSnap = false;
  1154. return station;
  1155. }
  1156. module.exports = {
  1157. createStationFree: createStationFree,
  1158. createStationSegment: createStationSegment,
  1159. createStationMinor: createStationMinor,
  1160. };
  1161. /***/ }),
  1162. /* 7 */
  1163. /***/ (function(module, exports, __webpack_require__) {
  1164. util = __webpack_require__(0);
  1165. styles = __webpack_require__(2);
  1166. var Connection = {
  1167. Connection: function(stationA, stationB) {
  1168. this.stationA = stationA;
  1169. this.stationB = stationB;
  1170. this.id = util.uuidv4();
  1171. this.paths = [];
  1172. return this;
  1173. },
  1174. allPaths: function() {
  1175. return this.paths;
  1176. },
  1177. draw: function() {
  1178. var stationRadiusA = this.stationA.style.stationRadius;
  1179. var stationRadiusB = this.stationB.style.stationRadius;
  1180. var stationStrokeWidthA = this.stationA.style.strokeWidth;
  1181. var stationStrokeWidthB = this.stationB.style.strokeWidth;
  1182. var stationStrokeWidth = Math.min(stationStrokeWidthA, stationStrokeWidthB);
  1183. var stationRadius = Math.min(stationRadiusA, stationRadiusB);
  1184. var difference = this.stationB.position - this.stationA.position;
  1185. var size = new Size(difference.length-stationRadius, stationRadius-stationStrokeWidth/2);
  1186. var offset = new Point(-stationRadius/2, stationRadius/2-stationStrokeWidth/4);
  1187. var rectangle = new Path.Rectangle(this.stationA.position - offset, size);
  1188. rectangle.fillColor = styles.rgbToHex(255, 255, 255);
  1189. rectangle.strokeWidth = 0;
  1190. rectangle.rotate(difference.angle, this.stationA.position);
  1191. var offset = difference.normalize().rotate(90) * stationRadius/2;
  1192. var offsetA1 = offset + difference.normalize()*(stationRadiusA-stationStrokeWidthA/2);
  1193. var offsetB1 = offset - difference.normalize()*(stationRadiusB-stationStrokeWidthB/2);
  1194. var offsetA2 = offset - difference.normalize()*(stationRadiusA-stationStrokeWidthA/2);
  1195. var offsetB2 = offset + difference.normalize()*(stationRadiusB-stationStrokeWidthB/2);
  1196. var line1 = new Path(this.stationA.position + offsetA1, this.stationB.position + offsetB1);
  1197. var line2 = new Path(this.stationA.position - offsetA2, this.stationB.position - offsetB2);
  1198. line1.strokeColor = this.stationA.style.strokeColor;
  1199. line2.strokeColor = this.stationA.style.strokeColor;
  1200. line1.strokeWidth = stationStrokeWidth;
  1201. line2.strokeWidth = stationStrokeWidth;
  1202. this.paths = [];
  1203. this.paths.push(rectangle);
  1204. this.paths.push(line1);
  1205. this.paths.push(line2);
  1206. },
  1207. };
  1208. function createConnection(stationA, stationB) {
  1209. var observable = Object.create(util.Observable).Observable();
  1210. var connection = Object.assign(observable, Connection);
  1211. connection = connection.Connection(stationA, stationB);
  1212. return connection;
  1213. }
  1214. module.exports = {
  1215. createConnection: createConnection,
  1216. };
  1217. /***/ }),
  1218. /* 8 */
  1219. /***/ (function(module, exports, __webpack_require__) {
  1220. var metromap = __webpack_require__(4);
  1221. function saveMap(map) {
  1222. var mapData = {};
  1223. mapData.tracks = [];
  1224. mapData.connections = [];
  1225. for (var i in map.tracks) {
  1226. var trackData = createTrackData(map.tracks[i]);
  1227. mapData.tracks.push(trackData);
  1228. }
  1229. for (var i in map.connections) {
  1230. var connectionData = createConnectionData(map.connections[i]);
  1231. mapData.connections.push(connectionData);
  1232. }
  1233. console.log(mapData);
  1234. var mapJSONString = JSON.stringify(mapData);
  1235. return mapJSONString;
  1236. }
  1237. function createTrackData(track) {
  1238. var trackData = {};
  1239. trackData.id = track.id;
  1240. trackData.segmentStyle = track.segmentStyle;
  1241. trackData.stationStyle = track.stationStyle;
  1242. trackData.segments = [];
  1243. trackData.stationsMinor = [];
  1244. for (var j in track.segments) {
  1245. var segmentData = createSegmentData(track.segments[j]);
  1246. trackData.segments.push(segmentData)
  1247. }
  1248. return trackData;
  1249. }
  1250. function createConnectionData(connection) {
  1251. var connectionData = {
  1252. stationA: connection.stationA.id,
  1253. stationB: connection.stationB.id,
  1254. id: connection.id,
  1255. };
  1256. return connectionData;
  1257. }
  1258. function createSegmentData(segment) {
  1259. var stationsUserData = [];
  1260. for (var i in segment.stationsUser) {
  1261. stationsUserData.push(createStationData(segment.stationsUser[i]));
  1262. }
  1263. var stationsAutoData = [];
  1264. for (var i in segment.stationsAuto) {
  1265. stationsAutoData.push(createStationData(segment.stationsAuto[i]));
  1266. }
  1267. var segmentData = {
  1268. stationA: createStationData(segment.stationA),
  1269. stationB: createStationData(segment.stationB),
  1270. stationsUser: stationsUserData,
  1271. stationsAuto: stationsAutoData,
  1272. id: segment.id,
  1273. };
  1274. return segmentData;
  1275. }
  1276. function createStationData(station) {
  1277. var stationData = {
  1278. position: {x: station.position.x, y: station.position.y},
  1279. id: station.id,
  1280. name: station.name,
  1281. offsetFactor: station.offsetFactor,
  1282. };
  1283. return stationData;
  1284. }
  1285. function createStationMinorData(station) {
  1286. var stationData = {
  1287. position: {x: station.position.x, y: station.position.y},
  1288. id: station.id,
  1289. name: station.name,
  1290. stationA: station.stationA.id,
  1291. stationB: station.stationB.id,
  1292. };
  1293. return stationData;
  1294. }
  1295. function loadMap(mapJSON) {
  1296. console.log('loadMap');
  1297. if (!mapJSON) {
  1298. // mapJSON = '{"tracks":[{"id":"15479b48-a900-438b-a0fa-2da8c77729af","stations":[{"position":{"x":200,"y":165},"id":"b4212813","name":"station"},{"position":{"x":535,"y":424},"id":"adc99f13","name":"station"},{"position":{"x":806,"y":119},"id":"ebad26f4","name":"station"}],"stationsMinor":[{"position":{"x":274.22056274847716,"y":269.22056274847716},"id":"712c3721","name":"station","stationA":"b4212813","stationB":"adc99f13"},{"position":{"x":341.3700576850888,"y":336.3700576850888},"id":"fb50a4e2","name":"station","stationA":"b4212813","stationB":"adc99f13"},{"position":{"x":408.5195526217004,"y":403.5195526217004},"id":"6c52a2bb","name":"station","stationA":"b4212813","stationB":"adc99f13"},{"position":{"x":634.7959415460184,"y":354.2040584539816},"id":"2f8dadac","name":"station","stationA":"adc99f13","stationB":"ebad26f4"},{"position":{"x":697.5208152801713,"y":291.4791847198287},"id":"f99d3a55","name":"station","stationA":"adc99f13","stationB":"ebad26f4"},{"position":{"x":760.2456890143242,"y":228.7543109856758},"id":"61b3fb5a","name":"station","stationA":"adc99f13","stationB":"ebad26f4"}]},{"id":"e93fb48a-518f-4f29-aa6f-1e395233cc09","stations":[{"position":{"x":209,"y":104},"id":"ce3ea5bf","name":"station"},{"position":{"x":400,"y":104},"id":"2ce21052","name":"station"},{"position":{"x":928,"y":354},"id":"292957b8","name":"station"}],"stationsMinor":[{"position":{"x":272.6666666666667,"y":104},"id":"6fee351c","name":"station","stationA":"ce3ea5bf","stationB":"2ce21052"},{"position":{"x":336.3333333333333,"y":104},"id":"325fe14a","name":"station","stationA":"ce3ea5bf","stationB":"2ce21052"},{"position":{"x":542.2817459305202,"y":104},"id":"074eef3a","name":"station","stationA":"2ce21052","stationB":"292957b8"},{"position":{"x":684.5634918610405,"y":104},"id":"1fba151c","name":"station","stationA":"2ce21052","stationB":"292957b8"},{"position":{"x":820.3205448016022,"y":216.3205448016022},"id":"5a39e0ba","name":"station","stationA":"2ce21052","stationB":"292957b8"}]}]}'
  1299. mapJSON = '{"tracks":[{"id":"3794c750-6605-49df-b810-aa5b0ebb42e8","segmentStyle":{"strokeColor":"red","strokeWidth":8,"selectionColor":"green","fullySelected":false},"stations":[{"position":{"x":152,"y":239},"id":"3fe7243d","name":"station"},{"position":{"x":687,"y":495},"id":"995a2376","name":"station"}],"stationsMinor":[]},{"id":"6fe22ae9-cd61-4705-aa2d-c457e11901e9","segmentStyle":{"strokeColor":"blue","strokeWidth":8,"selectionColor":"green","fullySelected":false},"stations":[{"position":{"x":174,"y":142},"id":"8cb86074","name":"station"},{"position":{"x":764,"y":433},"id":"882322b8","name":"station"}],"stationsMinor":[]}]}';
  1300. mapJSON = JSON.parse(mapJSON);
  1301. }
  1302. var map = metromap.createMap();
  1303. for (var i in mapJSON.tracks) {
  1304. var track = loadTrack(map, mapJSON.tracks[i]);
  1305. }
  1306. for (var i in mapJSON.connections) {
  1307. var connection = loadConnections(map, mapJSON.connections[i]);
  1308. }
  1309. return map;
  1310. }
  1311. function loadConnections(map, connectionData) {
  1312. console.log('load connections');
  1313. var stationA = map.findStation(connectionData.stationA);
  1314. var stationB = map.findStation(connectionData.stationB);
  1315. var connection = map.createConnection(stationA, stationB);
  1316. if (connection) {
  1317. connection.id = connectionData.id;
  1318. }
  1319. return connection;
  1320. }
  1321. function loadTrack(map, trackData) {
  1322. console.log('load track');
  1323. var track = map.createTrack();
  1324. track.id = trackData.id;
  1325. track.setSegmentStyle(trackData.segmentStyle);
  1326. track.setStationStyle(trackData.stationStyle);
  1327. for (var i in trackData.segments) {
  1328. var segmentData = trackData.segments[i];
  1329. loadSegment(map, track, segmentData);
  1330. }
  1331. return track;
  1332. }
  1333. function loadSegment(map, track, segmentData) {
  1334. console.log('load segment');
  1335. var stationAPoint = new Point(segmentData.stationA.position.x, segmentData.stationA.position.y);
  1336. var stationBPoint = new Point(segmentData.stationB.position.x, segmentData.stationB.position.y);
  1337. var stationA = map.findStation(segmentData.stationA.id);
  1338. var stationB = map.findStation(segmentData.stationB.id);
  1339. var segment = null;
  1340. if (stationA && stationB) {
  1341. segment = track.createSegment(stationA, stationB);
  1342. } else if (stationA) {
  1343. stationB = track.createStationFree(stationBPoint, stationA);
  1344. stationB.id = segmentData.stationB.id;
  1345. stationB.name = segmentData.stationB.name;
  1346. segment = track.findSegmentsForStation(stationB)[0];
  1347. } else if (stationB) {
  1348. stationA = track.createStationFree(stationAPoint);
  1349. stationA.id = segmentData.stationA.id;
  1350. stationA.name = segmentData.stationA.name;
  1351. segment = track.createSegment(stationA, stationB);
  1352. } else {
  1353. stationA = track.createStationFree(stationAPoint);
  1354. stationA.id = segmentData.stationA.id;
  1355. stationA.name = segmentData.stationA.name;
  1356. stationB = track.createStationFree(stationBPoint);
  1357. stationB.id = segmentData.stationB.id;
  1358. stationB.name = segmentData.stationB.name;
  1359. segment = track.createSegment(stationA, stationB);
  1360. }
  1361. console.assert(segment);
  1362. for (var i in segmentData.stationsUser) {
  1363. var stationData = segmentData.stationsUser[i];
  1364. if (segment.stationA.id === stationData.id || segment.stationB.id === stationData.id) {
  1365. continue;
  1366. }
  1367. var offsetFactor = segmentData.offsetFactor;
  1368. var station = track.createStationOnSegment(segment, offsetFactor);
  1369. station.offsetFactor = stationData.offsetFactor;
  1370. station.id = stationData.id;
  1371. station.name = stationData.name;
  1372. }
  1373. for (var i in segmentData.stationsAuto) {
  1374. var stationData = segmentData.stationsAuto[i];
  1375. var station = track.createStationMinor(stationData.position, segment);
  1376. station.id = stationData.id;
  1377. station.name = stationData.name;
  1378. }
  1379. }
  1380. module.exports = {
  1381. saveMap: saveMap,
  1382. loadMap: loadMap,
  1383. };
  1384. /***/ }),
  1385. /* 9 */
  1386. /***/ (function(module, exports, __webpack_require__) {
  1387. __webpack_require__(1);
  1388. var util = __webpack_require__(0);
  1389. var map = __webpack_require__(4);
  1390. var track = __webpack_require__(5);
  1391. var segment = __webpack_require__(3);
  1392. var station = __webpack_require__(6);
  1393. var connection = __webpack_require__(7);
  1394. var styles = __webpack_require__(2);
  1395. var snap = __webpack_require__(10);
  1396. var serialize = __webpack_require__(8);
  1397. var revision = __webpack_require__(11);
  1398. var zoom = __webpack_require__(12);
  1399. var interaction = __webpack_require__(13);
  1400. module.exports = {
  1401. util: util,
  1402. map: map,
  1403. track: track,
  1404. segment: segment,
  1405. station: station,
  1406. connection: connection,
  1407. snap: snap,
  1408. styles: styles,
  1409. serialize: serialize,
  1410. revision: revision,
  1411. interaction: interaction,
  1412. zoom: zoom,
  1413. };
  1414. /***/ }),
  1415. /* 10 */
  1416. /***/ (function(module, exports, __webpack_require__) {
  1417. util = __webpack_require__(0);
  1418. metrosegment = __webpack_require__(3);
  1419. function snapPosition(track, station, position) {
  1420. var snapDistance = metrosegment.minStraight+metrosegment.arcRadius*2.0;
  1421. var stations = track.connectedStations(station);
  1422. if (stations.length === 0 && track.lastAddedStation()) {
  1423. stations.push(track.lastAddedStation());
  1424. }
  1425. var nearestX = null;
  1426. var nearestY = null;
  1427. var minDistanceX = 1e99;
  1428. var minDistanceY = 1e99;
  1429. for (var i in stations) {
  1430. var stationVector = position - stations[i].position;
  1431. var deltaX = Math.abs(stationVector.x);
  1432. if (deltaX < minDistanceX) {
  1433. nearestX = stations[i];
  1434. minDistanceX = deltaX;
  1435. }
  1436. var deltaY = Math.abs(stationVector.y);
  1437. if (deltaY < minDistanceY) {
  1438. nearestY = stations[i];
  1439. minDistanceY = deltaY;
  1440. }
  1441. }
  1442. var snapX = position.x;
  1443. if (minDistanceX < snapDistance) {
  1444. snapX = nearestX.position.x;
  1445. }
  1446. var snapY = position.y;
  1447. if (minDistanceY < snapDistance) {
  1448. snapY = nearestY.position.y;
  1449. }
  1450. return new Point(snapX, snapY);
  1451. }
  1452. module.exports = {
  1453. snapPosition: snapPosition,
  1454. };
  1455. /***/ }),
  1456. /* 11 */
  1457. /***/ (function(module, exports, __webpack_require__) {
  1458. __webpack_require__(1);
  1459. util = __webpack_require__(0);
  1460. serialize = __webpack_require__(8);
  1461. var maxRevisions = 100;
  1462. var revisions = [];
  1463. var currentRevision = -1;
  1464. function createRevision(map) {
  1465. console.log('createRevision');
  1466. currentRevision++;
  1467. var mapDataString = serialize.saveMap(map);
  1468. if (currentRevision >= revisions.length) {
  1469. revisions.push(mapDataString);
  1470. } else {
  1471. revisions[currentRevision] = mapDataString;
  1472. revisions.splice(currentRevision+1, revisions.length-currentRevision-1);
  1473. }
  1474. while (revisions.length > maxRevisions) {
  1475. revisions.shift();
  1476. currentRevision--;
  1477. }
  1478. console.log('currentRevision', currentRevision);
  1479. }
  1480. function undo(map) {
  1481. if (currentRevision <= 0) {
  1482. return map;
  1483. }
  1484. currentRevision--;
  1485. var last = revisions[currentRevision];
  1486. map = serialize.loadMap(JSON.parse(last));
  1487. return map;
  1488. }
  1489. function redo(map) {
  1490. if (currentRevision+1 >= revisions.length) {
  1491. return map;
  1492. }
  1493. currentRevision++;
  1494. var next = revisions[currentRevision];
  1495. map = serialize.loadMap(JSON.parse(next));
  1496. return map;
  1497. }
  1498. function hasUndo() {
  1499. return currentRevision > 0;
  1500. }
  1501. function hasRedo() {
  1502. return currentRevision+1 < revisions.length;
  1503. }
  1504. function clearRevisions() {
  1505. revisions = [];
  1506. currentRevision = -1;
  1507. }
  1508. module.exports = {
  1509. createRevision: createRevision,
  1510. clearRevisions: clearRevisions,
  1511. undo: undo,
  1512. redo: redo,
  1513. hasUndo: hasUndo,
  1514. hasRedo: hasRedo
  1515. };
  1516. /***/ }),
  1517. /* 12 */
  1518. /***/ (function(module, exports, __webpack_require__) {
  1519. __webpack_require__(1);
  1520. var map = null;
  1521. function setNewMap(newMap) {
  1522. map = newMap;
  1523. }
  1524. function enableZoomOnCanvas(newMap) {
  1525. map = newMap;
  1526. $("canvas").bind("wheel", function(event) {
  1527. var point = new Point(event.clientX, event.clientY);
  1528. zoom(-event.originalEvent.deltaY, point);
  1529. function allowedZoom(zoom) {
  1530. if (zoom !== paper.view.zoom)
  1531. {
  1532. paper.view.zoom = zoom;
  1533. return zoom;
  1534. }
  1535. return null;
  1536. }
  1537. function zoom(delta, point) {
  1538. if (!delta) return;
  1539. var oldZoom = paper.view.zoom;
  1540. var oldCenter = paper.view.center;
  1541. var viewPos = paper.view.viewToProject(point);
  1542. var newZoom = delta > 0 ? oldZoom * 1.05 : oldZoom / 1.05;
  1543. if (!allowedZoom(newZoom)) {
  1544. return;
  1545. }
  1546. var zoomScale = oldZoom / newZoom;
  1547. var centerAdjust = viewPos.subtract(oldCenter);
  1548. var offset = viewPos.subtract(centerAdjust.multiply(zoomScale)).subtract(oldCenter);
  1549. paper.view.center = view.center.add(offset);
  1550. map.notifyAllStationsAndSegments();
  1551. }
  1552. });
  1553. }
  1554. module.exports = {
  1555. enableZoomOnCanvas: enableZoomOnCanvas,
  1556. setNewMap: setNewMap,
  1557. };
  1558. /***/ }),
  1559. /* 13 */
  1560. /***/ (function(module, exports, __webpack_require__) {
  1561. __webpack_require__(1);
  1562. var util = __webpack_require__(0);
  1563. var map = null;
  1564. function setCurrentMap(currentMap) {
  1565. map = currentMap;
  1566. }
  1567. function showStationContextMenu(stationId) {
  1568. $('#' + stationId).contextMenu();
  1569. }
  1570. function showStationInfo(station) {
  1571. var $div = $('<div class="station-info">id:' + station.id + '</div>');
  1572. $div.css('top', $('#' + station.id).css("top"));
  1573. $div.css('left', $('#' + station.id).css("left"));
  1574. $('#overlay-content').append($div);
  1575. }
  1576. function hideStationInfoAll() {
  1577. $(".station-info").hide();
  1578. }
  1579. function showSegmentContextMenu(segmentId, position) {
  1580. $('#segment-' + segmentId).data('position', position);
  1581. $('#segment-' + segmentId).contextMenu();
  1582. }
  1583. function createStationMinorElement(station, track) {
  1584. $("#overlay").append("<div class=\"station\" id=\"" + station.id + "\" data-station-id=\"" + station.id + "\"></div>")
  1585. }
  1586. function createMapElements(map, onRemoveStation) {
  1587. $("#overlay").empty();
  1588. var mapElements = [];
  1589. for (var i in map.tracks) {
  1590. var trackElements = createTrackElements(map.tracks[i], onRemoveStation);
  1591. mapElements.push({track: map.tracks[i], stationElements: trackElements.stationElements, segmentElements: trackElements.segmentElements});
  1592. }
  1593. return mapElements
  1594. }
  1595. function createTrackElements(track) {
  1596. var stationElements = [];
  1597. for (var i in track.stations) {
  1598. var stationElement = createStationElement(track.stations[i], track);
  1599. stationElements.push(stationElement);
  1600. }
  1601. var segmentElements = createSegmentElements(track);
  1602. return {stationElements: stationElements, segmentElements: segmentElements};
  1603. }
  1604. function createStationElement(station, track) {
  1605. $("#overlay").append("<div class=\"station\" id=\"" + station.id + "\" data-station-id=\"" + station.id + "\"></div>")
  1606. var stationElement = $("#" + station.id);
  1607. updateElementPosition(stationElement, station);
  1608. updateStyle();
  1609. createStationObserver();
  1610. function updateElementPosition(stationElement, station) {
  1611. var viewPosition = paper.view.projectToView(station.position);
  1612. stationElement.css('top', (viewPosition.y - stationElement.width()/2) + 'px');
  1613. stationElement.css('left', (viewPosition.x - stationElement.height()/2) + 'px');
  1614. }
  1615. function updateStyle() {
  1616. if (util.DisplaySettings.isDebug) {
  1617. stationElement.css('border-width', '1px');
  1618. } else {
  1619. stationElement.css('border-width', '0px');
  1620. }
  1621. }
  1622. function createStationObserver() {
  1623. var stationObserver = new util.Observer(
  1624. function(station) {
  1625. updateElementPosition(this.stationElement, station);
  1626. },
  1627. function(station) {
  1628. this.stationElement.remove();
  1629. }
  1630. );
  1631. stationObserver.stationElement = stationElement;
  1632. station.registerObserver(stationObserver);
  1633. }
  1634. return stationElement;
  1635. }
  1636. function createSegmentElements(track) {
  1637. console.log('createSegmentElements');
  1638. $(".segment").empty();
  1639. var elements = [];
  1640. for (var i in track.segments) {
  1641. var segment = track.segments[i];
  1642. var element = createSegmentElement(segment, track);
  1643. elements.push(element);
  1644. }
  1645. return elements;
  1646. }
  1647. function createSegmentElement(segment, track) {
  1648. var segmentElementId = "segment-" + segment.id;
  1649. $("#overlay").append("<div class=\"segment\" id=\"" + segmentElementId + "\" data-segment-id=\"" + segment.id + "\"></div>")
  1650. var segmentElement = $("#" + segmentElementId);
  1651. updateSegmentElementPosition(segmentElement, segment);
  1652. updateStyle();
  1653. createSegmentObserver();
  1654. function updateSegmentElementPosition(segmentElement, segment) {
  1655. var segmentCenterView = paper.view.projectToView(segment.center());
  1656. segmentElement.css('top', (segmentCenterView.y - segmentElement.width()/2) + 'px');
  1657. segmentElement.css('left', (segmentCenterView.x - segmentElement.height()/2) + 'px');
  1658. }
  1659. function updateStyle() {
  1660. if (util.DisplaySettings.isDebug) {
  1661. segmentElement.css('border-width', '1px');
  1662. } else {
  1663. segmentElement.css('border-width', '0px');
  1664. }
  1665. }
  1666. function createSegmentObserver() {
  1667. var segmentObserver = new util.Observer(
  1668. function(segment) {
  1669. updateSegmentElementPosition(this.segmentElement, segment);
  1670. },
  1671. function(segment) {
  1672. this.segmentElement.remove();
  1673. }
  1674. );
  1675. segmentObserver.segmentElement = segmentElement;
  1676. segment.registerObserver(segmentObserver);
  1677. }
  1678. return segmentElement;
  1679. }
  1680. module.exports = {
  1681. createMapElements: createMapElements,
  1682. createTrackElements: createTrackElements,
  1683. createStationElement: createStationElement,
  1684. showStationInfo: showStationInfo,
  1685. hideStationInfoAll: hideStationInfoAll,
  1686. showStationContextMenu: showStationContextMenu,
  1687. showSegmentContextMenu: showSegmentContextMenu,
  1688. createSegmentElements: createSegmentElements,
  1689. setCurrentMap: setCurrentMap,
  1690. };
  1691. /***/ }),
  1692. /* 14 */
  1693. /***/ (function(module, exports, __webpack_require__) {
  1694. module.exports = __webpack_require__(15);
  1695. /***/ }),
  1696. /* 15 */
  1697. /***/ (function(module, exports, __webpack_require__) {
  1698. __webpack_require__(1);
  1699. var MetroFlow = __webpack_require__(9);
  1700. var sidebar = __webpack_require__(16);
  1701. var toolbar = __webpack_require__(17);
  1702. var contextmenu = __webpack_require__(18);
  1703. $(initialise);
  1704. // disable browser context menu
  1705. $('body').on('contextmenu', '#paperCanvas', function(e){ return false; });
  1706. var map = null;
  1707. var currentTrack = null;
  1708. var segmentClicked = null;
  1709. var selectedStation = null;
  1710. var connectionStationA = null;
  1711. var connectionStationB = null;
  1712. var drawSettings = null;
  1713. var drawSettingsDrag = null;
  1714. var drawSettingsFull = null;
  1715. var dragging = false;
  1716. var doSnap = true;
  1717. function resetState() {
  1718. map = null;
  1719. currentTrack = null;
  1720. segmentClicked = null;
  1721. selectedStation = null;
  1722. connectionStationA = null;
  1723. connectionStationB = null;
  1724. dragging = false;
  1725. }
  1726. var modes = {
  1727. majorstation: "majorstation",
  1728. minorstation: "minorstation",
  1729. select: "select",
  1730. createConnection: "createConnection"
  1731. };
  1732. var mode = modes.majorstation;
  1733. var hitOptions = {
  1734. segments: true,
  1735. stroke: true,
  1736. fill: true,
  1737. tolerance: 3
  1738. };
  1739. function initialise() {
  1740. drawSettings = MetroFlow.map.createDrawSettings();
  1741. drawSettings.minorStationText = true;
  1742. drawSettingsDrag = MetroFlow.map.createDrawSettings();
  1743. drawSettingsDrag.text = false;
  1744. drawSettingsDrag.fast = true;
  1745. drawSettingsFull = MetroFlow.map.createDrawSettings();
  1746. drawSettingsFull.text = true;
  1747. drawSettingsFull.fast = false;
  1748. drawSettingsFull.calcTextPositions = true;
  1749. drawSettingsFull.minorStationText = true;
  1750. initialiseToolbarActions();
  1751. var newMap = MetroFlow.map.createMap();
  1752. setNewMap(newMap);
  1753. setCurrentTrack(createTrack());
  1754. // MetroFlow.zoom.enableZoomOnCanvas(map);
  1755. }
  1756. function setNewMap(newMap) {
  1757. map = newMap;
  1758. MetroFlow.interaction.setCurrentMap(newMap);
  1759. // MetroFlow.zoom.setNewMap(newMap);
  1760. }
  1761. function onRemoveStation(stationId) {
  1762. selectedStation = null;
  1763. map.removeStation(stationId);
  1764. map.draw(drawSettings);
  1765. }
  1766. function createTrack() {
  1767. var track = map.createTrack();
  1768. sidebar.notifyTrackChanged(track);
  1769. return track;
  1770. }
  1771. function setCurrentTrack(track) {
  1772. if (!track || (currentTrack && currentTrack.id === track.id)) {
  1773. return;
  1774. }
  1775. if (selectedStation) {
  1776. selectedStation.deselect();
  1777. }
  1778. currentTrack = track;
  1779. sidebar.setCurrentTrack(track);
  1780. }
  1781. function getStationClicked(hitResult, allowSwitchTrack) {
  1782. var path = hitResult.item;
  1783. var result = map.findStationByPathId(path.id);
  1784. var stationClicked = result.station;
  1785. if (allowSwitchTrack) {
  1786. setCurrentTrack(result.track);
  1787. }
  1788. return stationClicked;
  1789. }
  1790. function getSegmentClicked(hitResult) {
  1791. var path = hitResult.item;
  1792. var segments = path.segments;
  1793. if (!segments) {
  1794. return null;
  1795. }
  1796. var result = map.findSegmentByPathId(segments[0].path.id);
  1797. var segmentClicked = result.segment;
  1798. setCurrentTrack(result.track);
  1799. return segmentClicked;
  1800. }
  1801. function onRightClick(event) {
  1802. var hitResult = project.hitTest(event.point, hitOptions);
  1803. if (!hitResult) {
  1804. return;
  1805. }
  1806. var stationClicked = getStationClicked(hitResult);
  1807. if (stationClicked) { // right mouse
  1808. MetroFlow.interaction.showStationContextMenu(stationClicked.id);
  1809. // MetroFlow.interaction.hideStationInfoAll();
  1810. // MetroFlow.interaction.showStationInfo(stationClicked);
  1811. return;
  1812. }
  1813. var segmentClicked = getSegmentClicked(hitResult);
  1814. if (segmentClicked) { // right mouse
  1815. MetroFlow.interaction.showSegmentContextMenu(segmentClicked.id);
  1816. return;
  1817. }
  1818. }
  1819. function selectStation(stationClicked) {
  1820. if (selectedStation && stationClicked.id !== selectedStation.id) {
  1821. selectedStation.deselect();
  1822. }
  1823. stationClicked.toggleSelect();
  1824. selectedStation = stationClicked;
  1825. map.draw(drawSettings);
  1826. }
  1827. function onClickMajorStationMode(event) {
  1828. console.log('onClickMajorStation');
  1829. var hitResult = project.hitTest(event.point, hitOptions);
  1830. if (hitResult) {
  1831. var stationClicked = getStationClicked(hitResult, false);
  1832. if (stationClicked && selectedStation) {
  1833. console.log('station clicked');
  1834. if (stationClicked.id !== selectedStation.id) {
  1835. currentTrack.createSegment(stationClicked, selectedStation);
  1836. }
  1837. map.draw(drawSettings);
  1838. MetroFlow.revision.createRevision(map);
  1839. return;
  1840. }
  1841. var segmentClicked = getSegmentClicked(hitResult);
  1842. if (segmentClicked) {
  1843. var offsetFactor = segmentClicked.getOffsetOf(event.point) / segmentClicked.length();
  1844. var stationNew = currentTrack.createStationOnSegment(segmentClicked, offsetFactor);
  1845. map.draw(drawSettings);
  1846. MetroFlow.revision.createRevision(map);
  1847. // TODO: create elements based on track/map observer in interaction
  1848. var stationElement = MetroFlow.interaction.createStationElement(stationNew, currentTrack, onRemoveStation);
  1849. contextmenu.createStationContextMenu(stationElement.attr('id'), onRemoveStation);
  1850. return;
  1851. }
  1852. } else {
  1853. if (!selectedStation) {
  1854. selectedStation = currentTrack.lastAddedStation();
  1855. }
  1856. var stationNew = currentTrack.createStationFree(event.point, selectedStation);
  1857. if (doSnap) {
  1858. var position = MetroFlow.snap.snapPosition(currentTrack, stationNew, event.point);
  1859. stationNew.setPosition(position);
  1860. }
  1861. selectStation(stationNew);
  1862. // TODO: create elements based on track/map observer in interaction
  1863. var stationElement = MetroFlow.interaction.createStationElement(stationNew, currentTrack, onRemoveStation);
  1864. contextmenu.createStationContextMenu(stationElement.attr('id'), onRemoveStation);
  1865. var segmentElements = MetroFlow.interaction.createSegmentElements(currentTrack);
  1866. for (var i in segmentElements) {
  1867. var element = segmentElements[i];
  1868. contextmenu.createSegmentContextMenu(element.attr('id'), createStationMinorOnMap);
  1869. }
  1870. MetroFlow.revision.createRevision(map);
  1871. return;
  1872. }
  1873. }
  1874. function createStationMinorOnMap(position, segmentId) {
  1875. var segmentInfo = map.findSegment(segmentId);
  1876. segmentInfo.track.createStationMinorOnSegmentId(position, segmentId);
  1877. map.draw(drawSettings);
  1878. MetroFlow.revision.createRevision(map);
  1879. }
  1880. function onClickMinorStationMode(event) {
  1881. console.log('onClickMinorStationMode');
  1882. var hitResult = project.hitTest(event.point, hitOptions);
  1883. if (hitResult) {
  1884. var path = hitResult.item;
  1885. if (hitResult.type === "stroke" || path) {
  1886. console.log('stroke hit');
  1887. segmentClicked = getSegmentClicked(hitResult);
  1888. if (segmentClicked) {
  1889. createStationMinorOnMap(event.point, segmentClicked.id);
  1890. } else {
  1891. console.log('warning: no segment clicked');
  1892. }
  1893. }
  1894. }
  1895. }
  1896. function onClickSelectMode(event) {
  1897. var hitResult = project.hitTest(event.point, hitOptions);
  1898. if (hitResult) {
  1899. var stationClicked = getStationClicked(hitResult, true);
  1900. if (stationClicked) {
  1901. console.log('selectedStation', selectedStation);
  1902. selectStation(stationClicked);
  1903. return;
  1904. }
  1905. var segmentClicked = getSegmentClicked(hitResult);
  1906. if (segmentClicked) {
  1907. console.log('segment clicked');
  1908. segmentClicked.toggleSelect();
  1909. map.draw(drawSettings);
  1910. return;
  1911. }
  1912. }
  1913. }
  1914. function onClickCreateConnectionMode(event) {
  1915. console.log('onClickCreateConnectionMode');
  1916. var hitResult = project.hitTest(event.point, hitOptions);
  1917. if (!hitResult) {
  1918. return;
  1919. }
  1920. var stationClicked = getStationClicked(hitResult, false);
  1921. if (!stationClicked) {
  1922. return
  1923. }
  1924. if (!connectionStationA) {
  1925. connectionStationA = stationClicked;
  1926. connectionStationA.select();
  1927. map.draw(drawSettings);
  1928. } else {
  1929. connectionStationB = stationClicked;
  1930. if (connectionStationA.id === connectionStationB.id) {
  1931. connectionStationB = null;
  1932. return;
  1933. }
  1934. console.log('create new connection', connectionStationA.id, connectionStationB.id);
  1935. map.createConnection(connectionStationA, connectionStationB);
  1936. connectionStationA.deselect();
  1937. map.draw(drawSettings);
  1938. MetroFlow.revision.createRevision(map);
  1939. connectionStationA = null;
  1940. connectionStationB = null;
  1941. }
  1942. }
  1943. var startPosition = null;
  1944. function onMouseDown(event) {
  1945. startPosition = event.point;
  1946. if (event.event.which === 3) { // right mouse
  1947. onRightClick(event);
  1948. return;
  1949. }
  1950. if (mode === modes.majorstation) {
  1951. onClickMajorStationMode(event);
  1952. } else if (mode === modes.minorstation) {
  1953. selectedStation = null;
  1954. onClickMinorStationMode(event);
  1955. } else if (mode === modes.select) {
  1956. onClickSelectMode(event);
  1957. } else if (mode === modes.createConnection) {
  1958. onClickCreateConnectionMode(event);
  1959. }
  1960. }
  1961. function onMouseUp(event) {
  1962. if (dragging) {
  1963. map.draw(drawSettings);
  1964. MetroFlow.revision.createRevision(map);
  1965. dragging = false;
  1966. }
  1967. }
  1968. function onMouseDrag(event) {
  1969. dragging = true;
  1970. console.log('onMouseDrag');
  1971. // if (mode == modes.select) {
  1972. // console.log('panning', event.delta);
  1973. // var offset = startPosition - event.point;
  1974. // paper.view.center = view.center.add(offset);
  1975. // return;
  1976. // }
  1977. if (selectedStation) {
  1978. var position = event.point;
  1979. if (doSnap && selectedStation.doSnap) {
  1980. position = MetroFlow.snap.snapPosition(currentTrack, selectedStation, event.point);
  1981. }
  1982. var segments = currentTrack.findSegmentsForStation(selectedStation);
  1983. console.assert(segments[0]);
  1984. selectedStation.setPosition(position, segments[0]);
  1985. selectedStation.select();
  1986. map.draw(drawSettingsDrag);
  1987. }
  1988. }
  1989. function initialiseToolbarActions() {
  1990. console.log('initialiseToolbarActions');
  1991. toolbar.setMajorStationButtonAction(majorStationButtonClicked);
  1992. toolbar.setMinorStationButtonAction(minorStationButtonClicked);
  1993. toolbar.setSelectButtonAction(selectButtonClicked);
  1994. toolbar.setNewTrackButtonAction(newTrackButtonClicked);
  1995. toolbar.setNewConnectionAction(newConnectionButtionClicked);
  1996. toolbar.setCalcTextPositionsAction(calcTextPositionButtonClicked);
  1997. toolbar.setToggleSnapAction(snapCheckboxClicked);
  1998. toolbar.setUndoAction(onUndoButtonClicked);
  1999. toolbar.setRedoAction(onRedoButtonClicked);
  2000. toolbar.setSaveMapAction(saveMapClicked);
  2001. toolbar.setLoadMapAction(loadMapClicked);
  2002. sidebar.setToggleMinorNamesAction(minorNamesCheckboxClicked);
  2003. sidebar.setToggleDebugAction(debugCheckboxClicked);
  2004. sidebar.setExampleMapAction(loadExampleMapClicked);
  2005. sidebar.setTrackColorChangeAction(onTrackColorChanged);
  2006. sidebar.setTrackWidthSliderChangeAction(onTrackWidthChanged);
  2007. sidebar.setStationRadiusSliderChangeAction(onStationRadiusChanged);
  2008. sidebar.setStationStrokeWidthSliderChangeAction(onStationStrokeWidthChanged);
  2009. sidebar.setStationStrokeColorChangeAction(onStationStrokeColorChanged);
  2010. sidebar.setTrackChangeAction(onTrackChanged);
  2011. function onTrackChanged(track) {
  2012. map.draw(drawSettings);
  2013. }
  2014. function majorStationButtonClicked() {
  2015. console.log('major station drawing selected');
  2016. mode = modes.majorstation;
  2017. }
  2018. function minorStationButtonClicked() {
  2019. console.log('minor station drawing selected');
  2020. mode = modes.minorstation;
  2021. }
  2022. function selectButtonClicked() {
  2023. console.log('selection mode selected');
  2024. mode = modes.select;
  2025. }
  2026. function newTrackButtonClicked() {
  2027. console.log('new track button clicked');
  2028. selectedStation = null;
  2029. var newTrack = createTrack();
  2030. MetroFlow.revision.createRevision(map);
  2031. var segmentStyle = styles.createSegmentStyle();
  2032. segmentStyle.strokeColor = styles.rgbToHex(0, 0, 255);
  2033. newTrack.segmentStyle = segmentStyle;
  2034. setCurrentTrack(newTrack);
  2035. }
  2036. function newConnectionButtionClicked() {
  2037. console.log('new connection button clicked');
  2038. connectionStationA = null;
  2039. connectionStationB = null;
  2040. mode = modes.createConnection;
  2041. }
  2042. function calcTextPositionButtonClicked() {
  2043. console.log('calc text position button clicked');
  2044. map.draw(drawSettingsFull);
  2045. }
  2046. function snapCheckboxClicked(event) {
  2047. console.log('snap clicked', event.target.checked);
  2048. doSnap = event.target.checked;
  2049. map.draw(drawSettingsFull);
  2050. }
  2051. function minorNamesCheckboxClicked(event) {
  2052. console.log('minor names clicked', event.target.checked);
  2053. drawSettings.minorStationText = event.target.checked;
  2054. drawSettingsFull.minorStationText = event.target.checked;
  2055. map.draw(drawSettingsFull);
  2056. }
  2057. function debugCheckboxClicked(event) {
  2058. console.log('debug clicked', event.target.checked);
  2059. MetroFlow.util.DisplaySettings.isDebug = event.target.checked;
  2060. map.draw(drawSettings);
  2061. if (MetroFlow.util.DisplaySettings.isDebug) {
  2062. $(".station").css('border-width', '1px');
  2063. $(".segment").css('border-width', '1px');
  2064. } else {
  2065. $(".station").css('border-width', '0px');
  2066. $(".segment").css('border-width', '0px');
  2067. }
  2068. map.draw(drawSettingsFull);
  2069. }
  2070. function saveMapClicked() {
  2071. console.log('save map button clicked');
  2072. var mapJSONString = MetroFlow.serialize.saveMap(map);
  2073. var data = "text/json;charset=utf-8," + encodeURIComponent(mapJSONString);
  2074. var a = document.createElement('a');
  2075. a.href = 'data:' + data;
  2076. a.download = 'data.json';
  2077. a.innerHTML = 'download JSON';
  2078. // var container = document.getElementById('toolbar');
  2079. // container.appendChild(a);
  2080. a.click();
  2081. }
  2082. function loadMapClicked(event) {
  2083. console.log('load map button clicked');
  2084. prepareLoadMap();
  2085. readSingleFile(event);
  2086. function readSingleFile(event) {
  2087. var file = event.target.files[0];
  2088. if (!file) {
  2089. return;
  2090. }
  2091. var reader = new FileReader();
  2092. reader.onload = function(event) {
  2093. var contents = event.target.result;
  2094. displayContents(contents);
  2095. };
  2096. reader.readAsText(file);
  2097. }
  2098. function displayContents(contents) {
  2099. loadMapJson(JSON.parse(contents));
  2100. }
  2101. }
  2102. function prepareLoadMap() {
  2103. console.log('create revision before clear');
  2104. MetroFlow.revision.createRevision(map);
  2105. project.clear();
  2106. resetState();
  2107. }
  2108. function finishLoadMap(newMap) {
  2109. newMap.draw(drawSettingsFull);
  2110. MetroFlow.revision.createRevision(newMap);
  2111. var mapElements = MetroFlow.interaction.createMapElements(newMap, onRemoveStation);
  2112. createContextMenusMapElements(mapElements);
  2113. }
  2114. function createContextMenusMapElements(mapElements) {
  2115. for (var i in mapElements) {
  2116. var track = mapElements[i].track;
  2117. var stationElements = mapElements[i].stationElements;
  2118. var segmentElements = mapElements[i].segmentElements;
  2119. for (var j in segmentElements) {
  2120. contextmenu.createSegmentContextMenu(segmentElements[j].attr('id'), track);
  2121. }
  2122. for (var j in stationElements) {
  2123. contextmenu.createStationContextMenu(stationElements[j].attr('id'), onRemoveStation);
  2124. }
  2125. }
  2126. }
  2127. function loadMapJson(json) {
  2128. var newMap = MetroFlow.serialize.loadMap(json);
  2129. setNewMap(newMap);
  2130. if (newMap.tracks.length > 0) {
  2131. setCurrentTrack(newMap.tracks[0]);
  2132. }
  2133. finishLoadMap(newMap);
  2134. }
  2135. function loadMapFile(filepath) {
  2136. console.log('loadMapFile');
  2137. $.getJSON(filepath, function(json) {
  2138. loadMapJson(json);
  2139. });
  2140. }
  2141. function loadExampleMapClicked(filename) {
  2142. prepareLoadMap();
  2143. loadMapFile("src/maps/" + filename);
  2144. }
  2145. function prepareUndoRedo() {
  2146. var currentTrackId = null;
  2147. if (currentTrack) {
  2148. currentTrackId = currentTrack.id;
  2149. }
  2150. project.clear();
  2151. resetState();
  2152. return currentTrackId;
  2153. }
  2154. function finaliseUndoRedo(currentTrackId) {
  2155. var track = null;
  2156. if (currentTrackId) {
  2157. track = map.findTrack(currentTrackId);
  2158. }
  2159. if (track && map.tracks) {
  2160. track = map.tracks[map.tracks.length-1];
  2161. } else {
  2162. track = createTrack();
  2163. }
  2164. setCurrentTrack(track);
  2165. map.draw(drawSettingsFull);
  2166. MetroFlow.interaction.createMapElements(map, onRemoveStation);
  2167. for (var i in map.tracks) {
  2168. sidebar.notifyTrackChanged(map.tracks[i]);
  2169. }
  2170. }
  2171. function onUndoButtonClicked() {
  2172. if (!MetroFlow.revision.hasUndo()) {
  2173. console.log('NO UNDO AVAILABLE');
  2174. return;
  2175. }
  2176. var currentTrackId = prepareUndoRedo();
  2177. setNewMap(MetroFlow.revision.undo(map));
  2178. finaliseUndoRedo(currentTrackId);
  2179. }
  2180. function onRedoButtonClicked() {
  2181. if (!MetroFlow.revision.hasRedo()) {
  2182. console.log('NO REDO AVAILABLE');
  2183. return;
  2184. }
  2185. var currentTrackId = prepareUndoRedo();
  2186. setNewMap(MetroFlow.revision.redo(map));
  2187. finaliseUndoRedo(currentTrackId);
  2188. }
  2189. function onTrackColorChanged(color) {
  2190. console.log('onTrackColorChanged');
  2191. var segmentStyle = currentTrack.segmentStyle;
  2192. segmentStyle.strokeColor = color;
  2193. currentTrack.setSegmentStyle(segmentStyle);
  2194. map.draw(drawSettings);
  2195. }
  2196. function onTrackWidthChanged(value) {
  2197. var segmentStyle = currentTrack.segmentStyle;
  2198. segmentStyle.strokeWidth = value;
  2199. currentTrack.setSegmentStyle(segmentStyle);
  2200. map.draw(drawSettings);
  2201. }
  2202. function onStationRadiusChanged(radius) {
  2203. console.log('onStationRadiusChanged', radius);
  2204. currentTrack.stationStyle.stationRadius = radius;
  2205. map.draw(drawSettings);
  2206. }
  2207. function onStationStrokeWidthChanged(strokeWidth) {
  2208. currentTrack.stationStyle.strokeWidth = strokeWidth;
  2209. map.draw(drawSettings);
  2210. }
  2211. function onStationStrokeColorChanged(color) {
  2212. currentTrack.stationStyle.strokeColor = color;
  2213. map.draw(drawSettings);
  2214. }
  2215. }
  2216. tool.onMouseDown = onMouseDown;
  2217. tool.onMouseUp = onMouseUp;
  2218. tool.onMouseDrag = onMouseDrag;
  2219. tool.onKeyDown = onKeyDown;
  2220. /***/ }),
  2221. /* 16 */
  2222. /***/ (function(module, exports, __webpack_require__) {
  2223. __webpack_require__(1);
  2224. __webpack_require__(9);
  2225. var currentTrack = null;
  2226. function setCurrentTrack(track) {
  2227. if (currentTrack && currentTrack.id === track.id) {
  2228. return;
  2229. }
  2230. var colorPicker = document.getElementById("track-color-picker");
  2231. colorPicker.value = track.segmentStyle.strokeColor;
  2232. document.getElementById("station-stroke-color-picker").value = track.stationStyle.strokeColor;
  2233. $("#track-width-slider").slider('value', track.segmentStyle.strokeWidth);
  2234. $("#station-radius-slider").slider('value', track.stationStyle.stationRadius);
  2235. $("#station-stroke-width-slider").slider('value', track.stationStyle.strokeWidth);
  2236. currentTrack = track;
  2237. updateTableTrack(track);
  2238. }
  2239. function setExampleMapAction(callback) {
  2240. $("#button-example-map1").bind("click", loadFilename);
  2241. $("#button-example-map2").bind("click", loadFilename);
  2242. function loadFilename() {
  2243. var filename = $(this).data("filename");
  2244. console.log(filename);
  2245. callback(filename);
  2246. }
  2247. }
  2248. function setTrackColorChangeAction(callback) {
  2249. var colorPicker = document.getElementById("track-color-picker");
  2250. colorPicker.addEventListener("input", watchColorPicker, false);
  2251. colorPicker.addEventListener("change", watchColorPicker, false);
  2252. function watchColorPicker(event) {
  2253. var color = event.target.value;
  2254. callback(color);
  2255. }
  2256. }
  2257. function setTrackWidthSliderChangeAction(callback) {
  2258. $("#track-width-slider").slider({
  2259. slide: watchSlider,
  2260. change: watchSlider,
  2261. min: 0,
  2262. max: 20,
  2263. step: 0.5,
  2264. });
  2265. function watchSlider(event, ui) {
  2266. console.log(ui.value);
  2267. callback(ui.value);
  2268. }
  2269. }
  2270. function setStationRadiusSliderChangeAction(callback) {
  2271. $("#station-radius-slider").slider({
  2272. slide: watchSlider,
  2273. change: watchSlider,
  2274. min: 0,
  2275. max: 20,
  2276. step: 0.5,
  2277. });
  2278. function watchSlider(event, ui) {
  2279. callback(ui.value);
  2280. }
  2281. }
  2282. function setStationStrokeWidthSliderChangeAction(callback) {
  2283. $("#station-stroke-width-slider").slider({
  2284. slide: watchSlider,
  2285. change: watchSlider,
  2286. min: 0,
  2287. max: 20,
  2288. step: 0.5,
  2289. });
  2290. function watchSlider(event, ui) {
  2291. callback(ui.value);
  2292. }
  2293. }
  2294. function setStationStrokeColorChangeAction(callback) {
  2295. var colorPicker = document.getElementById("station-stroke-color-picker");
  2296. colorPicker.addEventListener("input", watchColorPicker, false);
  2297. colorPicker.addEventListener("change", watchColorPicker, false);
  2298. function watchColorPicker(event) {
  2299. var color = event.target.value;
  2300. callback(color);
  2301. }
  2302. }
  2303. function showTracks(tracks) {
  2304. var sideBar = $("#sidebar");
  2305. }
  2306. function updateTableTrack(track) {
  2307. console.log('TrackObserver.trackChanged()');
  2308. if (!currentTrack || currentTrack.id !== track.id) {
  2309. return;
  2310. }
  2311. $("#track-table tbody").empty();
  2312. for (var i in track.stations) {
  2313. var station = track.stations[i];
  2314. addStationRow(station);
  2315. }
  2316. function addStationRow(station) {
  2317. var markup = "<tr><td><input id='station-row-" + station.id + "' type='text' name='station' value='" + station.name + "' data-stationid='" + station.id + "'></td></tr>";
  2318. $("#track-table tbody").append(markup);
  2319. $("#station-row-" + station.id).bind("change", stationNameInputChange)
  2320. }
  2321. function stationNameInputChange() {
  2322. console.log("stationNameInputChange");
  2323. var stationId = $(this).data("stationid");
  2324. console.log('stationid', stationId);
  2325. var station = track.findStation(stationId);
  2326. console.log('station', station);
  2327. console.log('value', $(this).val());
  2328. station.name = $(this).val();
  2329. signalTrackInfoChanged(currentTrack);
  2330. }
  2331. }
  2332. function notifyTrackChanged(track) {
  2333. var trackObserver = new util.Observer(
  2334. updateTableTrack,
  2335. function(track) {
  2336. return;
  2337. }
  2338. );
  2339. track.registerObserver(trackObserver);
  2340. }
  2341. var signalTrackInfoChanged = null;
  2342. function setTrackChangeAction(callback) {
  2343. signalTrackInfoChanged = callback;
  2344. }
  2345. function setToggleDebugAction(callback) {
  2346. $("#checkbox-debug").bind("click", callback);
  2347. }
  2348. function setToggleMinorNamesAction(callback) {
  2349. $("#checkbox-minor-station-names").bind("click", callback);
  2350. }
  2351. module.exports = {
  2352. notifyTrackChanged: notifyTrackChanged,
  2353. setExampleMapAction: setExampleMapAction,
  2354. setCurrentTrack: setCurrentTrack,
  2355. setTrackColorChangeAction: setTrackColorChangeAction,
  2356. setTrackWidthSliderChangeAction: setTrackWidthSliderChangeAction,
  2357. setStationRadiusSliderChangeAction: setStationRadiusSliderChangeAction,
  2358. setStationStrokeWidthSliderChangeAction: setStationStrokeWidthSliderChangeAction,
  2359. setStationStrokeColorChangeAction: setStationStrokeColorChangeAction,
  2360. setTrackChangeAction: setTrackChangeAction,
  2361. setToggleDebugAction: setToggleDebugAction,
  2362. setToggleMinorNamesAction: setToggleMinorNamesAction,
  2363. };
  2364. /***/ }),
  2365. /* 17 */
  2366. /***/ (function(module, exports) {
  2367. $(function() {
  2368. var buttonMajorStation = $("#button-major-station");
  2369. var buttonMinorStation = $("#button-minor-station");
  2370. var buttonSelect = $("#button-select");
  2371. buttonMajorStation.bind("click", function () {
  2372. console.log('major button');
  2373. });
  2374. buttonMinorStation.bind("click", function () {
  2375. console.log('minor button');
  2376. });
  2377. });
  2378. function setMajorStationButtonAction(callback) {
  2379. var buttonMajorStation = $("#button-major-station");
  2380. buttonMajorStation.bind("click", callback);
  2381. }
  2382. function setMinorStationButtonAction(callback) {
  2383. var buttonMinorStation = $("#button-minor-station");
  2384. buttonMinorStation.bind("click", callback);
  2385. }
  2386. function setSelectButtonAction(callback) {
  2387. var buttonSelect = $("#button-select");
  2388. buttonSelect.bind("click", callback);
  2389. }
  2390. function setNewTrackButtonAction(callback) {
  2391. var buttonNewTrack = $("#button-new-track");
  2392. buttonNewTrack.bind("click", callback);
  2393. }
  2394. function setNewConnectionAction(callback) {
  2395. var buttonNewConnection = $("#button-new-connection");
  2396. buttonNewConnection.bind("click", callback);
  2397. }
  2398. function setUndoAction(callback) {
  2399. $("#button-undo").bind("click", callback);
  2400. }
  2401. function setRedoAction(callback) {
  2402. $("#button-redo").bind("click", callback);
  2403. }
  2404. function setCalcTextPositionsAction(callback) {
  2405. $("#button-calc-text-positions").bind("click", callback);
  2406. }
  2407. function setToggleSnapAction(callback) {
  2408. $("#checkbox-snap").bind("click", callback);
  2409. }
  2410. function setSaveMapAction(callback) {
  2411. var button = $("#button-save-map");
  2412. button.bind("click", callback);
  2413. }
  2414. function setLoadMapAction(callback) {
  2415. document.getElementById('file-input')
  2416. .addEventListener('change', callback, false);
  2417. }
  2418. module.exports = {
  2419. setMajorStationButtonAction: setMajorStationButtonAction,
  2420. setMinorStationButtonAction: setMinorStationButtonAction,
  2421. setSelectButtonAction: setSelectButtonAction,
  2422. setNewTrackButtonAction: setNewTrackButtonAction,
  2423. setNewConnectionAction: setNewConnectionAction,
  2424. setUndoAction: setUndoAction,
  2425. setRedoAction: setRedoAction,
  2426. setToggleSnapAction: setToggleSnapAction,
  2427. setCalcTextPositionsAction: setCalcTextPositionsAction,
  2428. setSaveMapAction: setSaveMapAction,
  2429. setLoadMapAction: setLoadMapAction
  2430. };
  2431. /***/ }),
  2432. /* 18 */
  2433. /***/ (function(module, exports, __webpack_require__) {
  2434. __webpack_require__(9);
  2435. function createStationContextMenu(stationElementId, onRemoveStation) {
  2436. console.assert(stationElementId);
  2437. $.contextMenu({
  2438. selector: '#' + stationElementId,
  2439. trigger: 'none',
  2440. callback: function(key, options) {
  2441. if (key === "delete") {
  2442. var stationId = $(options.selector).data('station-id');
  2443. onRemoveStation(stationId);
  2444. }
  2445. },
  2446. items: {
  2447. "delete": {name: "Delete", icon: "delete"},
  2448. }
  2449. });
  2450. }
  2451. function createSegmentContextMenu(segmentElementId, onCreateStationMinor) {
  2452. $.contextMenu({
  2453. selector: '#' + segmentElementId,
  2454. trigger: 'none',
  2455. callback: function(key, options) {
  2456. var segmentId = $(options.selector).data('segment-id');
  2457. if (key === 'createMinorStation') {
  2458. var position = $(options.selector).data('position');
  2459. onCreateStationMinor(position, segmentId);
  2460. }
  2461. },
  2462. items: {
  2463. 'createMinorStation': {name: "Add minor station", icon: "add"},
  2464. }
  2465. });
  2466. }
  2467. module.exports = {
  2468. createStationContextMenu: createStationContextMenu,
  2469. createSegmentContextMenu: createSegmentContextMenu,
  2470. };
  2471. /***/ })
  2472. /******/ ]);
  2473. });