diff --git a/js-src/conquer/index.ts b/js-src/conquer/index.ts index 45b2e2b..5978037 100644 --- a/js-src/conquer/index.ts +++ b/js-src/conquer/index.ts @@ -211,6 +211,11 @@ export default class Conquer { window.setTimeout(() => { this.isFeatureEnabledMap[feature.getProperties().type] = true }, 100); + const candidateNode = this.getServerNodes()[feature.getProperties().type]; + if (candidateNode !== undefined) { + candidateNode.click(this.interfaceManager); + return; + } if (feature === this.currentPositionFeature) { this.onClickSelf() return diff --git a/js-src/conquer/interface/node-view.ts b/js-src/conquer/interface/node-view.ts new file mode 100644 index 0000000..7594d90 --- /dev/null +++ b/js-src/conquer/interface/node-view.ts @@ -0,0 +1,36 @@ +import AbstractTopBarInterface from '@burguillosinfo/conquer/interface/abstract-top-bar-interface' +import Conquer from '@burguillosinfo/conquer' +import MapNode from '@burguillosinfo/conquer/map-node' + +export default class NodeView extends AbstractTopBarInterface { + private node: MapNode; + private getNodeNameH2(): HTMLElement { + const element = this.getMainNode().querySelector('h2.node-name'); + if (!(element instanceof HTMLElement)) { + Conquer.fail('h2.node-name is not a H2 or does not exist.'); + } + return element; + } + + private getNodeDescriptionParagraph(): HTMLElement { + const element = this.getMainNode().querySelector('p.node-description'); + if (!(element instanceof HTMLElement)) { + Conquer.fail('p.node-description is not a P or does not exist.'); + } + return element; + } + + constructor(node: MapNode) { + super() + this.node = node; + } + public run() { + const mainNode = this.getMainNode() + const view = this.getNodeFromTemplateId('conquer-view-node-template') + mainNode.append(view) + this.getNodeNameH2().innerText = this.node.getName(); + this.getNodeDescriptionParagraph().innerText = this.node.getDescription(); + view.classList.remove('conquer-display-none') + mainNode.classList.remove('conquer-display-none') + } +} diff --git a/js-src/conquer/map-node.ts b/js-src/conquer/map-node.ts index 4b55faa..672d5de 100644 --- a/js-src/conquer/map-node.ts +++ b/js-src/conquer/map-node.ts @@ -5,11 +5,13 @@ import CircleStyle from 'ol/style/Circle' import Point from 'ol/geom/Point' import Fill from 'ol/style/Fill' import Stroke from 'ol/style/Stroke' +import InterfaceManager from '@burguillosinfo/conquer/interface-manager' +import NodeView from '@burguillosinfo/conquer/interface/node-view' @JsonObject() export default class MapNode { private feature: Feature | null = null; - + private callbacks: Record void>> = {} constructor( @JsonProperty() private uuid: string, @@ -21,7 +23,33 @@ export default class MapNode { @JsonProperty() private kind: string, ) { } - + + public click(interfaceManager: InterfaceManager): void { + const viewNodeInterface = new NodeView(this); + viewNodeInterface.on('close', () => { + interfaceManager.remove(viewNodeInterface); + }); + interfaceManager.push(viewNodeInterface); + this.runCallbacks('click'); + } + + public on(eventName: string, callback: () => void): void { + if (this.callbacks[eventName] === undefined) { + this.callbacks[eventName] = [] + } + this.callbacks[eventName].push(callback) + } + + protected runCallbacks(eventName: string) { + const callbacks = this.callbacks[eventName]; + if (callbacks === undefined) { + return + } + for (const callback of callbacks) { + callback() + } + } + public getType(): string { return this.type; } diff --git a/public/js/bundle.js b/public/js/bundle.js index 61c8ccb..62dbe82 100644 --- a/public/js/bundle.js +++ b/public/js/bundle.js @@ -89,7 +89,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ Conquer)\n/* harmony export */ });\n/* harmony import */ var ol_Map__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ol/Map */ \"./node_modules/ol/Map.js\");\n/* harmony import */ var ol_MapBrowserEvent__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ol/MapBrowserEvent */ \"./node_modules/ol/MapBrowserEvent.js\");\n/* harmony import */ var ol_View__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ol/View */ \"./node_modules/ol/View.js\");\n/* harmony import */ var ol_proj_Projection_js__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ol/proj/Projection.js */ \"./node_modules/ol/proj/Projection.js\");\n/* harmony import */ var ol_layer_Tile__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ol/layer/Tile */ \"./node_modules/ol/layer/Tile.js\");\n/* harmony import */ var ol_source_OSM__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ol/source/OSM */ \"./node_modules/ol/source/OSM.js\");\n/* harmony import */ var ol_proj__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ol/proj */ \"./node_modules/ol/proj.js\");\n/* harmony import */ var ol_Feature__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ol/Feature */ \"./node_modules/ol/Feature.js\");\n/* harmony import */ var ol_geom_Point__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ol/geom/Point */ \"./node_modules/ol/geom/Point.js\");\n/* harmony import */ var ol_layer_Vector__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ol/layer/Vector */ \"./node_modules/ol/layer/Vector.js\");\n/* harmony import */ var ol_source_Vector__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ol/source/Vector */ \"./node_modules/ol/source/Vector.js\");\n/* harmony import */ var ol_style_Stroke__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ol/style/Stroke */ \"./node_modules/ol/style/Stroke.js\");\n/* harmony import */ var ol_style_Fill__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ol/style/Fill */ \"./node_modules/ol/style/Fill.js\");\n/* harmony import */ var ol_style_Circle__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ol/style/Circle */ \"./node_modules/ol/style/Circle.js\");\n/* harmony import */ var ol_style_Style__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ol/style/Style */ \"./node_modules/ol/style/Style.js\");\n/* harmony import */ var _burguillosinfo_conquer_login__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @burguillosinfo/conquer/login */ \"./js-src/conquer/login.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_manager__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @burguillosinfo/conquer/interface-manager */ \"./js-src/conquer/interface-manager.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_self_player__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/self-player */ \"./js-src/conquer/interface/self-player.ts\");\n/* harmony import */ var _burguillosinfo_conquer_create_node__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @burguillosinfo/conquer/create-node */ \"./js-src/conquer/create-node.ts\");\n/* harmony import */ var _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @burguillosinfo/conquer/map-state */ \"./js-src/conquer/map-state.ts\");\n/* harmony import */ var _burguillosinfo_conquer_map_node__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @burguillosinfo/conquer/map-node */ \"./js-src/conquer/map-node.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_new_node__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/new-node */ \"./js-src/conquer/interface/new-node.ts\");\n/* harmony import */ var _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! @burguillosinfo/conquer/serializer */ \"./js-src/conquer/serializer.ts\");\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nclass Conquer {\n getServerNodes() {\n return this.serverNodes;\n }\n getState() {\n return this.state;\n }\n setState(state) {\n this.state = state;\n this.refreshState();\n }\n removeState(state) {\n this.state &= ~state;\n this.refreshState();\n }\n addState(state) {\n this.state |= state;\n this.refreshState();\n }\n refreshState() {\n this.createNodeObject.refreshState();\n return;\n }\n static start() {\n const conquerContainer = document.querySelector(\".conquer-container\");\n if (conquerContainer === null || !(conquerContainer instanceof HTMLDivElement)) {\n Conquer.fail('.conquer-container is not a div.');\n }\n const conquer = new Conquer(conquerContainer);\n conquer.run();\n }\n setCenterDisplaced(lat, lon) {\n if (this.firstSetCenter || !(this.state & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_MOVE)) {\n this.coordinate_1 = lon;\n this.coordinate_2 = lat;\n const olCoordinates = this.realCoordinatesToOl(lat, lon);\n const size = this.map.getSize();\n if (size === undefined) {\n return;\n }\n this.map.getView().centerOn(olCoordinates, size, [size[0] / 2, size[1] - 60]);\n this.firstSetCenter = false;\n }\n }\n static fail(error) {\n alert('Error de interfaz');\n throw new Error(error);\n }\n isStateCreatingNode() {\n return !!(this.getState() & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].CREATE_NODE);\n }\n isStateSelectWhereToCreateNode() {\n return !!(this.getState() & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].SELECT_WHERE_TO_CREATE_NODE);\n }\n async onClickWhereToCreateNode(event) {\n if (!(event instanceof ol_MapBrowserEvent__WEBPACK_IMPORTED_MODULE_9__[\"default\"])) {\n return;\n }\n const pixel = event.pixel;\n const coordinates = this.map.getCoordinateFromPixel(pixel);\n const newNodeUI = new _burguillosinfo_conquer_interface_new_node__WEBPACK_IMPORTED_MODULE_7__[\"default\"](coordinates);\n const oldState = this.getState();\n newNodeUI.on('close', () => {\n this.interfaceManager.remove(newNodeUI);\n this.setState(oldState);\n });\n this.interfaceManager.push(newNodeUI);\n this.removeState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].SELECT_WHERE_TO_CREATE_NODE);\n // const style = new Style({\n // image: new CircleStyle({\n // radius: 14,\n // fill: new Fill({color: 'white'}),\n // stroke: new Stroke({\n // color: 'gray',\n // width: 2,\n // })\n // })\n // })\n // const mapNode = new MapNode(style, feature, `server-node-${++this.createNodeCounter}`)\n // this.getServerNodes()[mapNode.getId()] = mapNode\n // this.refreshLayers()\n }\n isStateFillingFormCreateNode() {\n return !!(this.getState() & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FILLING_FORM_CREATE_NODE);\n }\n async onClickMap(event) {\n if (this.isStateCreatingNode() && this.isStateSelectWhereToCreateNode()) {\n this.onClickWhereToCreateNode(event);\n }\n if (!(this.getState() & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NORMAL)) {\n return;\n }\n if (this.vectorLayer === null) {\n return;\n }\n if (!(event instanceof ol_MapBrowserEvent__WEBPACK_IMPORTED_MODULE_9__[\"default\"])) {\n return;\n }\n if (event.dragging) {\n return;\n }\n const pixel = event.pixel;\n const features = this.map.getFeaturesAtPixel(pixel);\n const feature = features.length ? features[0] : undefined;\n if (feature === undefined) {\n return;\n }\n if (!(feature instanceof ol_Feature__WEBPACK_IMPORTED_MODULE_10__[\"default\"])) {\n return;\n }\n this.onClickFeature(feature);\n }\n async onClickSelf() {\n if (!(this.state & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NORMAL)) {\n return;\n }\n const selfPlayerUI = new _burguillosinfo_conquer_interface_self_player__WEBPACK_IMPORTED_MODULE_3__[\"default\"](!!(this.getState() & (_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_MOVE | _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_ROTATION)));\n selfPlayerUI.on('close', () => {\n this.interfaceManager.remove(selfPlayerUI);\n });\n selfPlayerUI.on('enable-explorer-mode', () => {\n console.log('hola');\n this.addState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_MOVE);\n this.addState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_ROTATION);\n });\n selfPlayerUI.on('disable-explorer-mode', () => {\n this.removeState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_MOVE);\n this.removeState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_ROTATION);\n });\n selfPlayerUI.on('createNodeStart', () => {\n this.addState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].CREATE_NODE);\n this.removeState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NORMAL);\n });\n this.interfaceManager.push(selfPlayerUI);\n this.selfPlayerUI = selfPlayerUI;\n }\n async onClickFeature(feature) {\n if (this.isFeatureEnabledMap[feature.getProperties().type] === undefined) {\n this.isFeatureEnabledMap[feature.getProperties().type] = true;\n }\n if (!this.isFeatureEnabledMap[feature.getProperties().type]) {\n return;\n }\n this.isFeatureEnabledMap[feature.getProperties().type] = false;\n window.setTimeout(() => {\n this.isFeatureEnabledMap[feature.getProperties().type] = true;\n }, 100);\n if (feature === this.currentPositionFeature) {\n this.onClickSelf();\n return;\n }\n }\n async onLoginSuccess() {\n this.clearIntervalSendCoordinates();\n this.createIntervalSendCoordinates();\n this.clearIntervalPollNearbyNodes();\n this.createIntervalPollNearbyNodes();\n }\n clearIntervalPollNearbyNodes() {\n if (this.intervalPollNearbyNodes !== null) {\n window.clearInterval(this.intervalPollNearbyNodes);\n this.intervalPollNearbyNodes = null;\n }\n }\n getNearbyNodes() {\n const urlNodes = new URL('/conquer/node/near', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n fetch(urlNodes).then(async (response) => {\n let responseBody;\n try {\n responseBody = await response.json();\n }\n catch (error) {\n console.error('Error parseando json: ' + responseBody);\n console.error(error);\n return;\n }\n if (response.status !== 200) {\n console.error(responseBody.error);\n return;\n }\n const serverNodes = {};\n const nodes = _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_8__[\"default\"].deserialize(responseBody, _burguillosinfo_conquer_map_node__WEBPACK_IMPORTED_MODULE_6__[\"default\"]);\n if (!(nodes instanceof Array)) {\n console.error('Received null instead of node list.');\n return;\n }\n for (const node of nodes) {\n if (!(node instanceof _burguillosinfo_conquer_map_node__WEBPACK_IMPORTED_MODULE_6__[\"default\"])) {\n console.error('Received node is not a MapNode.');\n continue;\n }\n serverNodes[node.getId()] = node;\n }\n this.serverNodes = serverNodes;\n this.refreshLayers();\n });\n }\n createIntervalPollNearbyNodes() {\n this.getNearbyNodes();\n this.intervalPollNearbyNodes = window.setInterval(() => {\n this.getNearbyNodes();\n }, 40000);\n }\n createIntervalSendCoordinates() {\n this.intervalSendCoordinates = window.setInterval(() => {\n this.sendCoordinatesToServer();\n }, 40000);\n }\n sendCoordinatesToServer() {\n const urlLog = new URL('/conquer/user/coordinates', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n fetch(urlLog, {\n method: 'POST',\n body: JSON.stringify([\n this.coordinate_1,\n this.coordinate_2,\n ]),\n }).then(async (res) => {\n let responseBody;\n try {\n responseBody = await res.json();\n }\n catch (error) {\n console.error('Error parseando json: ' + responseBody);\n console.error(error);\n return;\n }\n if (res.status !== 200) {\n console.error(responseBody.error);\n }\n }).catch((error) => {\n console.error(error);\n });\n }\n runPreStartState() {\n const createNodeObject = new _burguillosinfo_conquer_create_node__WEBPACK_IMPORTED_MODULE_4__[\"default\"](this);\n this.createNodeObject = createNodeObject;\n const interfaceManager = new _burguillosinfo_conquer_interface_manager__WEBPACK_IMPORTED_MODULE_2__[\"default\"]();\n this.interfaceManager = interfaceManager;\n const conquerLogin = new _burguillosinfo_conquer_login__WEBPACK_IMPORTED_MODULE_1__[\"default\"](interfaceManager);\n conquerLogin.on('login', () => {\n this.onLoginSuccess();\n });\n conquerLogin.on('logout', () => {\n this.onLogout();\n });\n conquerLogin.start();\n this.conquerLogin = conquerLogin;\n }\n onLogout() {\n this.clearIntervalSendCoordinates();\n this.clearIntervalPollNearbyNodes();\n }\n clearIntervalSendCoordinates() {\n if (this.intervalSendCoordinates !== null) {\n window.clearInterval(this.intervalSendCoordinates);\n this.intervalSendCoordinates = null;\n }\n }\n async run() {\n this.runPreStartState();\n this.setState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NORMAL);\n const conquerContainer = this.conquerContainer;\n //layer.on('prerender', (evt) => {\n // // return\n // if (evt.context) {\n // const context = evt.context as CanvasRenderingContext2D\n // context.filter = 'grayscale(80%) invert(100%) '\n // context.globalCompositeOperation = 'source-over'\n // }\n //})\n //layer.on('postrender', (evt) => {\n // if (evt.context) {\n // const context = evt.context as CanvasRenderingContext2D\n // context.filter = 'none'\n // }\n //})\n ol_proj__WEBPACK_IMPORTED_MODULE_0__.useGeographic();\n const osm = new ol_source_OSM__WEBPACK_IMPORTED_MODULE_11__[\"default\"]();\n osm.setUrls([`${window.location.protocol}//${window.location.hostname}:${window.location.port}/conquer/tile/{z}/{x}/{y}.png`]);\n this.map = new ol_Map__WEBPACK_IMPORTED_MODULE_12__[\"default\"]({\n target: conquerContainer,\n layers: [\n new ol_layer_Tile__WEBPACK_IMPORTED_MODULE_13__[\"default\"]({\n source: osm\n })\n ],\n view: new ol_View__WEBPACK_IMPORTED_MODULE_14__[\"default\"]({\n zoom: 19,\n maxZoom: 22,\n }),\n });\n this.setLocationChangeTriggers();\n this.setRotationChangeTriggers();\n }\n setRotationChangeTriggers() {\n if (window.DeviceOrientationEvent) {\n window.addEventListener(\"deviceorientation\", (event) => {\n if (event.alpha !== null && event.beta !== null && event.gamma !== null) {\n this.onRotate(event.alpha, event.beta, event.gamma);\n }\n }, true);\n }\n }\n addCurrentLocationMarkerToMap(currentLatitude, currentLongitude) {\n const currentPositionFeature = new ol_Feature__WEBPACK_IMPORTED_MODULE_10__[\"default\"]({\n type: 'currentPositionFeature',\n geometry: new ol_geom_Point__WEBPACK_IMPORTED_MODULE_15__[\"default\"](this.realCoordinatesToOl(currentLatitude, currentLongitude))\n });\n this.currentPositionFeature = currentPositionFeature;\n }\n processLocation(location) {\n this.currentLatitude = location.coords.latitude;\n this.currentLongitude = location.coords.longitude;\n if (location.coords.heading !== null && (this.alpha != 0 || this.beta != 0 || this.gamma != 0) && !this.disableSetRotationOffset) {\n this.disableSetRotationOffset = true;\n this.heading = location.coords.heading;\n this.rotationOffset = this.compassHeading(this.alpha, this.beta, this.gamma) + (location.coords.heading * Math.PI * 2) / 360;\n }\n this.setCenterDisplaced(this.currentLatitude, this.currentLongitude);\n this.addCurrentLocationMarkerToMap(this.currentLatitude, this.currentLongitude);\n this.refreshLayers();\n }\n async refreshLayers() {\n if (this.currentPositionFeature === null) {\n return;\n }\n const styles = {\n currentPositionFeature: new ol_style_Style__WEBPACK_IMPORTED_MODULE_16__[\"default\"]({\n image: new ol_style_Circle__WEBPACK_IMPORTED_MODULE_17__[\"default\"]({\n radius: 14,\n fill: new ol_style_Fill__WEBPACK_IMPORTED_MODULE_18__[\"default\"]({ color: 'white' }),\n stroke: new ol_style_Stroke__WEBPACK_IMPORTED_MODULE_19__[\"default\"]({\n color: 'blue',\n width: 2,\n })\n })\n })\n };\n const features = [this.currentPositionFeature];\n for (const key in this.getServerNodes()) {\n styles[key] = this.getServerNodes()[key].getStyle();\n features.push(this.getServerNodes()[key].getFeature());\n }\n const vectorLayer = new ol_layer_Vector__WEBPACK_IMPORTED_MODULE_20__[\"default\"]({\n source: new ol_source_Vector__WEBPACK_IMPORTED_MODULE_21__[\"default\"]({\n features: features\n }),\n });\n if (this.vectorLayer !== null) {\n this.map.removeLayer(this.vectorLayer);\n this.vectorLayer = null;\n }\n vectorLayer.setStyle((feature) => {\n return styles[feature.getProperties().type];\n });\n this.map.addLayer(vectorLayer);\n this.vectorLayer = vectorLayer;\n this.map.on('click', (event) => {\n this.onClickMap(event);\n });\n }\n setLocationChangeTriggers() {\n window.setInterval(() => {\n this.disableSetRotationOffset = false;\n }, 10000);\n this.currentPositionFeature = null;\n window.setTimeout(() => {\n window.setInterval(() => {\n navigator.geolocation.getCurrentPosition((location) => {\n this.processLocation(location);\n }, () => {\n return;\n }, {\n enableHighAccuracy: true,\n });\n }, 3000);\n }, 1000);\n // const initialLatitude = 37.58237\n //const initialLongitude = -5.96766\n const initialLongitude = 2.500845037550267;\n const initialLatitude = 48.81050698635832;\n this.setCenterDisplaced(initialLatitude, initialLongitude);\n this.addCurrentLocationMarkerToMap(initialLatitude, initialLongitude);\n this.refreshLayers();\n navigator.geolocation.watchPosition((location) => {\n this.processLocation(location);\n }, (err) => {\n return;\n }, {\n enableHighAccuracy: true,\n });\n }\n realCoordinatesToOl(lat, lon) {\n return ol_proj__WEBPACK_IMPORTED_MODULE_0__.transform([lon, lat], new ol_proj_Projection_js__WEBPACK_IMPORTED_MODULE_22__[\"default\"]({ code: \"WGS84\" }), new ol_proj_Projection_js__WEBPACK_IMPORTED_MODULE_22__[\"default\"]({ code: \"EPSG:900913\" }));\n }\n compassHeading(alpha, beta, gamma) {\n const alphaRad = alpha * (Math.PI / 180);\n return alphaRad;\n }\n logToServer(logValue) {\n const urlLog = new URL('/conquer/log', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n urlLog.searchParams.append('log', logValue);\n fetch(urlLog).then(() => {\n return;\n }).catch((error) => {\n console.error(error);\n });\n }\n onRotate(alpha, beta, gamma) {\n if (this.enabledOnRotate) {\n this.alpha = alpha;\n this.beta = beta;\n this.gamma = gamma;\n this.enabledOnRotate = false;\n if (this.firstSetRotation || !(this.state & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_ROTATION)) {\n this.map.getView().setRotation((this.compassHeading(alpha, beta, gamma) - this.rotationOffset));\n this.firstSetRotation = false;\n }\n window.setTimeout(() => {\n this.enabledOnRotate = true;\n }, 10);\n }\n this.setCenterDisplaced(this.currentLatitude, this.currentLongitude);\n }\n constructor(conquerContainer) {\n this.intervalSendCoordinates = null;\n this.rotationOffset = 0;\n this.heading = 0;\n this.disableSetRotationOffset = false;\n this.vectorLayer = null;\n this.alpha = 0;\n this.beta = 0;\n this.gamma = 0;\n this.selfPlayerUI = null;\n this.firstSetCenter = true;\n this.firstSetRotation = true;\n this.state = _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NOTHING;\n this.serverNodes = {};\n this.coordinate_1 = 0;\n this.coordinate_2 = 0;\n this.createNodeCounter = 0;\n this.isFeatureEnabledMap = {};\n this.intervalPollNearbyNodes = null;\n this.enabledOnRotate = true;\n this.conquerContainer = conquerContainer;\n }\n}\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/index.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ Conquer)\n/* harmony export */ });\n/* harmony import */ var ol_Map__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ol/Map */ \"./node_modules/ol/Map.js\");\n/* harmony import */ var ol_MapBrowserEvent__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ol/MapBrowserEvent */ \"./node_modules/ol/MapBrowserEvent.js\");\n/* harmony import */ var ol_View__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(/*! ol/View */ \"./node_modules/ol/View.js\");\n/* harmony import */ var ol_proj_Projection_js__WEBPACK_IMPORTED_MODULE_22__ = __webpack_require__(/*! ol/proj/Projection.js */ \"./node_modules/ol/proj/Projection.js\");\n/* harmony import */ var ol_layer_Tile__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(/*! ol/layer/Tile */ \"./node_modules/ol/layer/Tile.js\");\n/* harmony import */ var ol_source_OSM__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ol/source/OSM */ \"./node_modules/ol/source/OSM.js\");\n/* harmony import */ var ol_proj__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ol/proj */ \"./node_modules/ol/proj.js\");\n/* harmony import */ var ol_Feature__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ol/Feature */ \"./node_modules/ol/Feature.js\");\n/* harmony import */ var ol_geom_Point__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(/*! ol/geom/Point */ \"./node_modules/ol/geom/Point.js\");\n/* harmony import */ var ol_layer_Vector__WEBPACK_IMPORTED_MODULE_20__ = __webpack_require__(/*! ol/layer/Vector */ \"./node_modules/ol/layer/Vector.js\");\n/* harmony import */ var ol_source_Vector__WEBPACK_IMPORTED_MODULE_21__ = __webpack_require__(/*! ol/source/Vector */ \"./node_modules/ol/source/Vector.js\");\n/* harmony import */ var ol_style_Stroke__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(/*! ol/style/Stroke */ \"./node_modules/ol/style/Stroke.js\");\n/* harmony import */ var ol_style_Fill__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(/*! ol/style/Fill */ \"./node_modules/ol/style/Fill.js\");\n/* harmony import */ var ol_style_Circle__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(/*! ol/style/Circle */ \"./node_modules/ol/style/Circle.js\");\n/* harmony import */ var ol_style_Style__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(/*! ol/style/Style */ \"./node_modules/ol/style/Style.js\");\n/* harmony import */ var _burguillosinfo_conquer_login__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @burguillosinfo/conquer/login */ \"./js-src/conquer/login.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_manager__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @burguillosinfo/conquer/interface-manager */ \"./js-src/conquer/interface-manager.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_self_player__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/self-player */ \"./js-src/conquer/interface/self-player.ts\");\n/* harmony import */ var _burguillosinfo_conquer_create_node__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @burguillosinfo/conquer/create-node */ \"./js-src/conquer/create-node.ts\");\n/* harmony import */ var _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @burguillosinfo/conquer/map-state */ \"./js-src/conquer/map-state.ts\");\n/* harmony import */ var _burguillosinfo_conquer_map_node__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! @burguillosinfo/conquer/map-node */ \"./js-src/conquer/map-node.ts\");\n/* harmony import */ var _burguillosinfo_conquer_interface_new_node__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/new-node */ \"./js-src/conquer/interface/new-node.ts\");\n/* harmony import */ var _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! @burguillosinfo/conquer/serializer */ \"./js-src/conquer/serializer.ts\");\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nclass Conquer {\n getServerNodes() {\n return this.serverNodes;\n }\n getState() {\n return this.state;\n }\n setState(state) {\n this.state = state;\n this.refreshState();\n }\n removeState(state) {\n this.state &= ~state;\n this.refreshState();\n }\n addState(state) {\n this.state |= state;\n this.refreshState();\n }\n refreshState() {\n this.createNodeObject.refreshState();\n return;\n }\n static start() {\n const conquerContainer = document.querySelector(\".conquer-container\");\n if (conquerContainer === null || !(conquerContainer instanceof HTMLDivElement)) {\n Conquer.fail('.conquer-container is not a div.');\n }\n const conquer = new Conquer(conquerContainer);\n conquer.run();\n }\n setCenterDisplaced(lat, lon) {\n if (this.firstSetCenter || !(this.state & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_MOVE)) {\n this.coordinate_1 = lon;\n this.coordinate_2 = lat;\n const olCoordinates = this.realCoordinatesToOl(lat, lon);\n const size = this.map.getSize();\n if (size === undefined) {\n return;\n }\n this.map.getView().centerOn(olCoordinates, size, [size[0] / 2, size[1] - 60]);\n this.firstSetCenter = false;\n }\n }\n static fail(error) {\n alert('Error de interfaz');\n throw new Error(error);\n }\n isStateCreatingNode() {\n return !!(this.getState() & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].CREATE_NODE);\n }\n isStateSelectWhereToCreateNode() {\n return !!(this.getState() & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].SELECT_WHERE_TO_CREATE_NODE);\n }\n async onClickWhereToCreateNode(event) {\n if (!(event instanceof ol_MapBrowserEvent__WEBPACK_IMPORTED_MODULE_9__[\"default\"])) {\n return;\n }\n const pixel = event.pixel;\n const coordinates = this.map.getCoordinateFromPixel(pixel);\n const newNodeUI = new _burguillosinfo_conquer_interface_new_node__WEBPACK_IMPORTED_MODULE_7__[\"default\"](coordinates);\n const oldState = this.getState();\n newNodeUI.on('close', () => {\n this.interfaceManager.remove(newNodeUI);\n this.setState(oldState);\n });\n this.interfaceManager.push(newNodeUI);\n this.removeState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].SELECT_WHERE_TO_CREATE_NODE);\n // const style = new Style({\n // image: new CircleStyle({\n // radius: 14,\n // fill: new Fill({color: 'white'}),\n // stroke: new Stroke({\n // color: 'gray',\n // width: 2,\n // })\n // })\n // })\n // const mapNode = new MapNode(style, feature, `server-node-${++this.createNodeCounter}`)\n // this.getServerNodes()[mapNode.getId()] = mapNode\n // this.refreshLayers()\n }\n isStateFillingFormCreateNode() {\n return !!(this.getState() & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FILLING_FORM_CREATE_NODE);\n }\n async onClickMap(event) {\n if (this.isStateCreatingNode() && this.isStateSelectWhereToCreateNode()) {\n this.onClickWhereToCreateNode(event);\n }\n if (!(this.getState() & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NORMAL)) {\n return;\n }\n if (this.vectorLayer === null) {\n return;\n }\n if (!(event instanceof ol_MapBrowserEvent__WEBPACK_IMPORTED_MODULE_9__[\"default\"])) {\n return;\n }\n if (event.dragging) {\n return;\n }\n const pixel = event.pixel;\n const features = this.map.getFeaturesAtPixel(pixel);\n const feature = features.length ? features[0] : undefined;\n if (feature === undefined) {\n return;\n }\n if (!(feature instanceof ol_Feature__WEBPACK_IMPORTED_MODULE_10__[\"default\"])) {\n return;\n }\n this.onClickFeature(feature);\n }\n async onClickSelf() {\n if (!(this.state & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NORMAL)) {\n return;\n }\n const selfPlayerUI = new _burguillosinfo_conquer_interface_self_player__WEBPACK_IMPORTED_MODULE_3__[\"default\"](!!(this.getState() & (_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_MOVE | _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_ROTATION)));\n selfPlayerUI.on('close', () => {\n this.interfaceManager.remove(selfPlayerUI);\n });\n selfPlayerUI.on('enable-explorer-mode', () => {\n console.log('hola');\n this.addState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_MOVE);\n this.addState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_ROTATION);\n });\n selfPlayerUI.on('disable-explorer-mode', () => {\n this.removeState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_MOVE);\n this.removeState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_ROTATION);\n });\n selfPlayerUI.on('createNodeStart', () => {\n this.addState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].CREATE_NODE);\n this.removeState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NORMAL);\n });\n this.interfaceManager.push(selfPlayerUI);\n this.selfPlayerUI = selfPlayerUI;\n }\n async onClickFeature(feature) {\n if (this.isFeatureEnabledMap[feature.getProperties().type] === undefined) {\n this.isFeatureEnabledMap[feature.getProperties().type] = true;\n }\n if (!this.isFeatureEnabledMap[feature.getProperties().type]) {\n return;\n }\n this.isFeatureEnabledMap[feature.getProperties().type] = false;\n window.setTimeout(() => {\n this.isFeatureEnabledMap[feature.getProperties().type] = true;\n }, 100);\n const candidateNode = this.getServerNodes()[feature.getProperties().type];\n if (candidateNode !== undefined) {\n candidateNode.click(this.interfaceManager);\n return;\n }\n if (feature === this.currentPositionFeature) {\n this.onClickSelf();\n return;\n }\n }\n async onLoginSuccess() {\n this.clearIntervalSendCoordinates();\n this.createIntervalSendCoordinates();\n this.clearIntervalPollNearbyNodes();\n this.createIntervalPollNearbyNodes();\n }\n clearIntervalPollNearbyNodes() {\n if (this.intervalPollNearbyNodes !== null) {\n window.clearInterval(this.intervalPollNearbyNodes);\n this.intervalPollNearbyNodes = null;\n }\n }\n getNearbyNodes() {\n const urlNodes = new URL('/conquer/node/near', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n fetch(urlNodes).then(async (response) => {\n let responseBody;\n try {\n responseBody = await response.json();\n }\n catch (error) {\n console.error('Error parseando json: ' + responseBody);\n console.error(error);\n return;\n }\n if (response.status !== 200) {\n console.error(responseBody.error);\n return;\n }\n const serverNodes = {};\n const nodes = _burguillosinfo_conquer_serializer__WEBPACK_IMPORTED_MODULE_8__[\"default\"].deserialize(responseBody, _burguillosinfo_conquer_map_node__WEBPACK_IMPORTED_MODULE_6__[\"default\"]);\n if (!(nodes instanceof Array)) {\n console.error('Received null instead of node list.');\n return;\n }\n for (const node of nodes) {\n if (!(node instanceof _burguillosinfo_conquer_map_node__WEBPACK_IMPORTED_MODULE_6__[\"default\"])) {\n console.error('Received node is not a MapNode.');\n continue;\n }\n serverNodes[node.getId()] = node;\n }\n this.serverNodes = serverNodes;\n this.refreshLayers();\n });\n }\n createIntervalPollNearbyNodes() {\n this.getNearbyNodes();\n this.intervalPollNearbyNodes = window.setInterval(() => {\n this.getNearbyNodes();\n }, 40000);\n }\n createIntervalSendCoordinates() {\n this.intervalSendCoordinates = window.setInterval(() => {\n this.sendCoordinatesToServer();\n }, 40000);\n }\n sendCoordinatesToServer() {\n const urlLog = new URL('/conquer/user/coordinates', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n fetch(urlLog, {\n method: 'POST',\n body: JSON.stringify([\n this.coordinate_1,\n this.coordinate_2,\n ]),\n }).then(async (res) => {\n let responseBody;\n try {\n responseBody = await res.json();\n }\n catch (error) {\n console.error('Error parseando json: ' + responseBody);\n console.error(error);\n return;\n }\n if (res.status !== 200) {\n console.error(responseBody.error);\n }\n }).catch((error) => {\n console.error(error);\n });\n }\n runPreStartState() {\n const createNodeObject = new _burguillosinfo_conquer_create_node__WEBPACK_IMPORTED_MODULE_4__[\"default\"](this);\n this.createNodeObject = createNodeObject;\n const interfaceManager = new _burguillosinfo_conquer_interface_manager__WEBPACK_IMPORTED_MODULE_2__[\"default\"]();\n this.interfaceManager = interfaceManager;\n const conquerLogin = new _burguillosinfo_conquer_login__WEBPACK_IMPORTED_MODULE_1__[\"default\"](interfaceManager);\n conquerLogin.on('login', () => {\n this.onLoginSuccess();\n });\n conquerLogin.on('logout', () => {\n this.onLogout();\n });\n conquerLogin.start();\n this.conquerLogin = conquerLogin;\n }\n onLogout() {\n this.clearIntervalSendCoordinates();\n this.clearIntervalPollNearbyNodes();\n }\n clearIntervalSendCoordinates() {\n if (this.intervalSendCoordinates !== null) {\n window.clearInterval(this.intervalSendCoordinates);\n this.intervalSendCoordinates = null;\n }\n }\n async run() {\n this.runPreStartState();\n this.setState(_burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NORMAL);\n const conquerContainer = this.conquerContainer;\n //layer.on('prerender', (evt) => {\n // // return\n // if (evt.context) {\n // const context = evt.context as CanvasRenderingContext2D\n // context.filter = 'grayscale(80%) invert(100%) '\n // context.globalCompositeOperation = 'source-over'\n // }\n //})\n //layer.on('postrender', (evt) => {\n // if (evt.context) {\n // const context = evt.context as CanvasRenderingContext2D\n // context.filter = 'none'\n // }\n //})\n ol_proj__WEBPACK_IMPORTED_MODULE_0__.useGeographic();\n const osm = new ol_source_OSM__WEBPACK_IMPORTED_MODULE_11__[\"default\"]();\n osm.setUrls([`${window.location.protocol}//${window.location.hostname}:${window.location.port}/conquer/tile/{z}/{x}/{y}.png`]);\n this.map = new ol_Map__WEBPACK_IMPORTED_MODULE_12__[\"default\"]({\n target: conquerContainer,\n layers: [\n new ol_layer_Tile__WEBPACK_IMPORTED_MODULE_13__[\"default\"]({\n source: osm\n })\n ],\n view: new ol_View__WEBPACK_IMPORTED_MODULE_14__[\"default\"]({\n zoom: 19,\n maxZoom: 22,\n }),\n });\n this.setLocationChangeTriggers();\n this.setRotationChangeTriggers();\n }\n setRotationChangeTriggers() {\n if (window.DeviceOrientationEvent) {\n window.addEventListener(\"deviceorientation\", (event) => {\n if (event.alpha !== null && event.beta !== null && event.gamma !== null) {\n this.onRotate(event.alpha, event.beta, event.gamma);\n }\n }, true);\n }\n }\n addCurrentLocationMarkerToMap(currentLatitude, currentLongitude) {\n const currentPositionFeature = new ol_Feature__WEBPACK_IMPORTED_MODULE_10__[\"default\"]({\n type: 'currentPositionFeature',\n geometry: new ol_geom_Point__WEBPACK_IMPORTED_MODULE_15__[\"default\"](this.realCoordinatesToOl(currentLatitude, currentLongitude))\n });\n this.currentPositionFeature = currentPositionFeature;\n }\n processLocation(location) {\n this.currentLatitude = location.coords.latitude;\n this.currentLongitude = location.coords.longitude;\n if (location.coords.heading !== null && (this.alpha != 0 || this.beta != 0 || this.gamma != 0) && !this.disableSetRotationOffset) {\n this.disableSetRotationOffset = true;\n this.heading = location.coords.heading;\n this.rotationOffset = this.compassHeading(this.alpha, this.beta, this.gamma) + (location.coords.heading * Math.PI * 2) / 360;\n }\n this.setCenterDisplaced(this.currentLatitude, this.currentLongitude);\n this.addCurrentLocationMarkerToMap(this.currentLatitude, this.currentLongitude);\n this.refreshLayers();\n }\n async refreshLayers() {\n if (this.currentPositionFeature === null) {\n return;\n }\n const styles = {\n currentPositionFeature: new ol_style_Style__WEBPACK_IMPORTED_MODULE_16__[\"default\"]({\n image: new ol_style_Circle__WEBPACK_IMPORTED_MODULE_17__[\"default\"]({\n radius: 14,\n fill: new ol_style_Fill__WEBPACK_IMPORTED_MODULE_18__[\"default\"]({ color: 'white' }),\n stroke: new ol_style_Stroke__WEBPACK_IMPORTED_MODULE_19__[\"default\"]({\n color: 'blue',\n width: 2,\n })\n })\n })\n };\n const features = [this.currentPositionFeature];\n for (const key in this.getServerNodes()) {\n styles[key] = this.getServerNodes()[key].getStyle();\n features.push(this.getServerNodes()[key].getFeature());\n }\n const vectorLayer = new ol_layer_Vector__WEBPACK_IMPORTED_MODULE_20__[\"default\"]({\n source: new ol_source_Vector__WEBPACK_IMPORTED_MODULE_21__[\"default\"]({\n features: features\n }),\n });\n if (this.vectorLayer !== null) {\n this.map.removeLayer(this.vectorLayer);\n this.vectorLayer = null;\n }\n vectorLayer.setStyle((feature) => {\n return styles[feature.getProperties().type];\n });\n this.map.addLayer(vectorLayer);\n this.vectorLayer = vectorLayer;\n this.map.on('click', (event) => {\n this.onClickMap(event);\n });\n }\n setLocationChangeTriggers() {\n window.setInterval(() => {\n this.disableSetRotationOffset = false;\n }, 10000);\n this.currentPositionFeature = null;\n window.setTimeout(() => {\n window.setInterval(() => {\n navigator.geolocation.getCurrentPosition((location) => {\n this.processLocation(location);\n }, () => {\n return;\n }, {\n enableHighAccuracy: true,\n });\n }, 3000);\n }, 1000);\n // const initialLatitude = 37.58237\n //const initialLongitude = -5.96766\n const initialLongitude = 2.500845037550267;\n const initialLatitude = 48.81050698635832;\n this.setCenterDisplaced(initialLatitude, initialLongitude);\n this.addCurrentLocationMarkerToMap(initialLatitude, initialLongitude);\n this.refreshLayers();\n navigator.geolocation.watchPosition((location) => {\n this.processLocation(location);\n }, (err) => {\n return;\n }, {\n enableHighAccuracy: true,\n });\n }\n realCoordinatesToOl(lat, lon) {\n return ol_proj__WEBPACK_IMPORTED_MODULE_0__.transform([lon, lat], new ol_proj_Projection_js__WEBPACK_IMPORTED_MODULE_22__[\"default\"]({ code: \"WGS84\" }), new ol_proj_Projection_js__WEBPACK_IMPORTED_MODULE_22__[\"default\"]({ code: \"EPSG:900913\" }));\n }\n compassHeading(alpha, beta, gamma) {\n const alphaRad = alpha * (Math.PI / 180);\n return alphaRad;\n }\n logToServer(logValue) {\n const urlLog = new URL('/conquer/log', window.location.protocol + '//' + window.location.hostname + ':' + window.location.port);\n urlLog.searchParams.append('log', logValue);\n fetch(urlLog).then(() => {\n return;\n }).catch((error) => {\n console.error(error);\n });\n }\n onRotate(alpha, beta, gamma) {\n if (this.enabledOnRotate) {\n this.alpha = alpha;\n this.beta = beta;\n this.gamma = gamma;\n this.enabledOnRotate = false;\n if (this.firstSetRotation || !(this.state & _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].FREE_ROTATION)) {\n this.map.getView().setRotation((this.compassHeading(alpha, beta, gamma) - this.rotationOffset));\n this.firstSetRotation = false;\n }\n window.setTimeout(() => {\n this.enabledOnRotate = true;\n }, 10);\n }\n this.setCenterDisplaced(this.currentLatitude, this.currentLongitude);\n }\n constructor(conquerContainer) {\n this.intervalSendCoordinates = null;\n this.rotationOffset = 0;\n this.heading = 0;\n this.disableSetRotationOffset = false;\n this.vectorLayer = null;\n this.alpha = 0;\n this.beta = 0;\n this.gamma = 0;\n this.selfPlayerUI = null;\n this.firstSetCenter = true;\n this.firstSetRotation = true;\n this.state = _burguillosinfo_conquer_map_state__WEBPACK_IMPORTED_MODULE_5__[\"default\"].NOTHING;\n this.serverNodes = {};\n this.coordinate_1 = 0;\n this.coordinate_2 = 0;\n this.createNodeCounter = 0;\n this.isFeatureEnabledMap = {};\n this.intervalPollNearbyNodes = null;\n this.enabledOnRotate = true;\n this.conquerContainer = conquerContainer;\n }\n}\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/index.ts?"); /***/ }), @@ -148,6 +148,17 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ }), +/***/ "./js-src/conquer/interface/node-view.ts": +/*!***********************************************!*\ + !*** ./js-src/conquer/interface/node-view.ts ***! + \***********************************************/ +/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { + +"use strict"; +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (/* binding */ NodeView)\n/* harmony export */ });\n/* harmony import */ var _burguillosinfo_conquer_interface_abstract_top_bar_interface__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/abstract-top-bar-interface */ \"./js-src/conquer/interface/abstract-top-bar-interface.ts\");\n/* harmony import */ var _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @burguillosinfo/conquer */ \"./js-src/conquer/index.ts\");\n\n\nclass NodeView extends _burguillosinfo_conquer_interface_abstract_top_bar_interface__WEBPACK_IMPORTED_MODULE_0__[\"default\"] {\n getNodeNameH2() {\n const element = this.getMainNode().querySelector('h2.node-name');\n if (!(element instanceof HTMLElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_1__[\"default\"].fail('h2.node-name is not a H2 or does not exist.');\n }\n return element;\n }\n getNodeDescriptionParagraph() {\n const element = this.getMainNode().querySelector('p.node-description');\n if (!(element instanceof HTMLElement)) {\n _burguillosinfo_conquer__WEBPACK_IMPORTED_MODULE_1__[\"default\"].fail('p.node-description is not a P or does not exist.');\n }\n return element;\n }\n constructor(node) {\n super();\n this.node = node;\n }\n run() {\n const mainNode = this.getMainNode();\n const view = this.getNodeFromTemplateId('conquer-view-node-template');\n mainNode.append(view);\n this.getNodeNameH2().innerText = this.node.getName();\n this.getNodeDescriptionParagraph().innerText = this.node.getDescription();\n view.classList.remove('conquer-display-none');\n mainNode.classList.remove('conquer-display-none');\n }\n}\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/interface/node-view.ts?"); + +/***/ }), + /***/ "./js-src/conquer/interface/self-player.ts": /*!*************************************************!*\ !*** ./js-src/conquer/interface/self-player.ts ***! @@ -177,7 +188,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! typescript-json-serializer */ \"./node_modules/typescript-json-serializer/dist/index.esm.js\");\n/* harmony import */ var ol_style_Style__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ol/style/Style */ \"./node_modules/ol/style/Style.js\");\n/* harmony import */ var ol_Feature__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ol/Feature */ \"./node_modules/ol/Feature.js\");\n/* harmony import */ var ol_style_Circle__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ol/style/Circle */ \"./node_modules/ol/style/Circle.js\");\n/* harmony import */ var ol_geom_Point__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ol/geom/Point */ \"./node_modules/ol/geom/Point.js\");\n/* harmony import */ var ol_style_Fill__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ol/style/Fill */ \"./node_modules/ol/style/Fill.js\");\n/* harmony import */ var ol_style_Stroke__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ol/style/Stroke */ \"./node_modules/ol/style/Stroke.js\");\nvar __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nvar __metadata = (undefined && undefined.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};\nvar __param = (undefined && undefined.__param) || function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};\n\n\n\n\n\n\n\nlet MapNode = class MapNode {\n constructor(uuid, coordinate_1, coordinate_2, type, name, description, kind) {\n this.uuid = uuid;\n this.coordinate_1 = coordinate_1;\n this.coordinate_2 = coordinate_2;\n this.type = type;\n this.name = name;\n this.description = description;\n this.kind = kind;\n this.feature = null;\n }\n getType() {\n return this.type;\n }\n getName() {\n return this.name;\n }\n getDescription() {\n return this.description;\n }\n getId() {\n return 'node-' + this.uuid;\n }\n getFeature() {\n if (this.feature === null) {\n console.log(this.coordinate_1);\n console.log(this.coordinate_2);\n this.feature = new ol_Feature__WEBPACK_IMPORTED_MODULE_1__[\"default\"]({\n geometry: new ol_geom_Point__WEBPACK_IMPORTED_MODULE_2__[\"default\"]([this.coordinate_1, this.coordinate_2]),\n type: 'node-' + this.uuid,\n });\n }\n return this.feature;\n }\n getStyle() {\n return new ol_style_Style__WEBPACK_IMPORTED_MODULE_3__[\"default\"]({\n image: new ol_style_Circle__WEBPACK_IMPORTED_MODULE_4__[\"default\"]({\n radius: 14,\n fill: new ol_style_Fill__WEBPACK_IMPORTED_MODULE_5__[\"default\"]({ color: 'white' }),\n stroke: new ol_style_Stroke__WEBPACK_IMPORTED_MODULE_6__[\"default\"]({\n color: 'gray',\n width: 2,\n })\n })\n });\n }\n};\nMapNode = __decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonObject)(),\n __param(0, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(1, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(2, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(3, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(4, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(5, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(6, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __metadata(\"design:paramtypes\", [String, Number, Number, String, String, String, String])\n], MapNode);\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (MapNode);\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/map-node.ts?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! typescript-json-serializer */ \"./node_modules/typescript-json-serializer/dist/index.esm.js\");\n/* harmony import */ var ol_style_Style__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ol/style/Style */ \"./node_modules/ol/style/Style.js\");\n/* harmony import */ var ol_Feature__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ol/Feature */ \"./node_modules/ol/Feature.js\");\n/* harmony import */ var ol_style_Circle__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ol/style/Circle */ \"./node_modules/ol/style/Circle.js\");\n/* harmony import */ var ol_geom_Point__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ol/geom/Point */ \"./node_modules/ol/geom/Point.js\");\n/* harmony import */ var ol_style_Fill__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ol/style/Fill */ \"./node_modules/ol/style/Fill.js\");\n/* harmony import */ var ol_style_Stroke__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ol/style/Stroke */ \"./node_modules/ol/style/Stroke.js\");\n/* harmony import */ var _burguillosinfo_conquer_interface_node_view__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @burguillosinfo/conquer/interface/node-view */ \"./js-src/conquer/interface/node-view.ts\");\nvar __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {\n var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nvar __metadata = (undefined && undefined.__metadata) || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};\nvar __param = (undefined && undefined.__param) || function (paramIndex, decorator) {\n return function (target, key) { decorator(target, key, paramIndex); }\n};\n\n\n\n\n\n\n\n\nlet MapNode = class MapNode {\n constructor(uuid, coordinate_1, coordinate_2, type, name, description, kind) {\n this.uuid = uuid;\n this.coordinate_1 = coordinate_1;\n this.coordinate_2 = coordinate_2;\n this.type = type;\n this.name = name;\n this.description = description;\n this.kind = kind;\n this.feature = null;\n this.callbacks = {};\n }\n click(interfaceManager) {\n const viewNodeInterface = new _burguillosinfo_conquer_interface_node_view__WEBPACK_IMPORTED_MODULE_1__[\"default\"](this);\n viewNodeInterface.on('close', () => {\n interfaceManager.remove(viewNodeInterface);\n });\n interfaceManager.push(viewNodeInterface);\n this.runCallbacks('click');\n }\n on(eventName, callback) {\n if (this.callbacks[eventName] === undefined) {\n this.callbacks[eventName] = [];\n }\n this.callbacks[eventName].push(callback);\n }\n runCallbacks(eventName) {\n const callbacks = this.callbacks[eventName];\n if (callbacks === undefined) {\n return;\n }\n for (const callback of callbacks) {\n callback();\n }\n }\n getType() {\n return this.type;\n }\n getName() {\n return this.name;\n }\n getDescription() {\n return this.description;\n }\n getId() {\n return 'node-' + this.uuid;\n }\n getFeature() {\n if (this.feature === null) {\n console.log(this.coordinate_1);\n console.log(this.coordinate_2);\n this.feature = new ol_Feature__WEBPACK_IMPORTED_MODULE_2__[\"default\"]({\n geometry: new ol_geom_Point__WEBPACK_IMPORTED_MODULE_3__[\"default\"]([this.coordinate_1, this.coordinate_2]),\n type: 'node-' + this.uuid,\n });\n }\n return this.feature;\n }\n getStyle() {\n return new ol_style_Style__WEBPACK_IMPORTED_MODULE_4__[\"default\"]({\n image: new ol_style_Circle__WEBPACK_IMPORTED_MODULE_5__[\"default\"]({\n radius: 14,\n fill: new ol_style_Fill__WEBPACK_IMPORTED_MODULE_6__[\"default\"]({ color: 'white' }),\n stroke: new ol_style_Stroke__WEBPACK_IMPORTED_MODULE_7__[\"default\"]({\n color: 'gray',\n width: 2,\n })\n })\n });\n }\n};\nMapNode = __decorate([\n (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonObject)(),\n __param(0, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(1, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(2, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(3, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(4, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(5, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __param(6, (0,typescript_json_serializer__WEBPACK_IMPORTED_MODULE_0__.JsonProperty)()),\n __metadata(\"design:paramtypes\", [String, Number, Number, String, String, String, String])\n], MapNode);\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (MapNode);\n\n\n//# sourceURL=webpack://BurguillosInfo/./js-src/conquer/map-node.ts?"); /***/ }), diff --git a/templates/conquer/index.html.ep b/templates/conquer/index.html.ep index 3157efb..e1f4829 100644 --- a/templates/conquer/index.html.ep +++ b/templates/conquer/index.html.ep @@ -15,6 +15,13 @@ %= include 'conquer/_interface-with-top-bar-template'; %= include 'conquer/_login-template'; %= include 'conquer/_register-template'; +
+
+

Vista de nodo.

+

+

+
+