source: src/mapservice/src-gen/openapi_server/static/js/GnuBoat.Webserver.js@ 5e4cb73

debian/bullseye
Last change on this file since 5e4cb73 was 5e4cb73, checked in by Joachim Langenbach <joachim.langenbach@…>, 8 years ago

Refactored mapservice

  • mapservice is a connexion python webservice with openapi defined api
  • mapservice-webclient is a angular app, consuming the openapi webservice mapservice
  • Property mode set to 100644
File size: 4.8 KB
RevLine 
[2fa2ef8]1/*
2
[883b4a5]3 Copyright (C) 2018 - 2019 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
[2fa2ef8]4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 MA 02110-1301 USA.
19
20*/
21
22/** @namespace GnuBoat JavaScript namespace */
23var GnuBoat = GnuBoat || {};
24/** @namespace GnuBoat Webserver JavaScript namespace */
25GnuBoat.Webserver = GnuBoat.Webserver || {};
26
27GnuBoat.Webserver.initialize = function()
28{
29 GnuBoat.Webserver.private.mapSetup();
[3a89adb]30 $("#loginForm").validate({
31 rules: {
32 loginUsername: {
33 required: true
34 },
35 loginPassword: {
36 required: true
37 }
38 },
39 submitHandler: function(form){
40 GnuBoat.Webserver.login(form);
41 }
42 });
43
44 $("#login").hide();
45 $("#myWaters").hide();
46 $("#linkMyGnuboat").click(function(){ $("#mapViewport").hide(); GnuBoat.Webserver.loginCheck(); });
47 $("#linkMap").click(function(){ $("#mapViewport").show(); });
48}
49
50/**
51 * @brief Sets the webservice base url, used by any other functions
52 */
53GnuBoat.Webserver.setServer = function(baseUrl)
54{
55 if(baseUrl.slice(-1) != "/")
56 baseUrl += "/";
57 GnuBoat.Webserver.private.serverBaseUrl = baseUrl;
[2fa2ef8]58}
59
60GnuBoat.Webserver.private = {
[3a89adb]61 loggedin: false,
[2fa2ef8]62 map: null,
63 mapSetup: function ()
64 {
[883b4a5]65 GnuBoat.Webserver.private.map = L.map('mapViewport').setView([48.43, 10.04], 17);
[2fa2ef8]66
67 var layer_openstreetmap = L.tileLayer(
68 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
[46f871f]69 { attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>, <a href="http://www.openseamap.org">OpenSeaMap</a>, <a href="http://gnuboat.engsas.de">GNUBoat</a> contributors'}
[2fa2ef8]70 ).addTo(GnuBoat.Webserver.private.map);
71 var layer_openseamap = L.tileLayer(
72 'http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png',
73 {attribute: '&copy; <a href="http://www.openseamap.org">OpenSeaMap</a> contributors'}
74 ).addTo(GnuBoat.Webserver.private.map);
75
[883b4a5]76 // add GNUBoat layers
[c5b13e1]77 var layer_gnuboat_accuracy_low = L.tileLayer(
78 './tiles/gnuboat_10_100/{z}/{x}/{y}.png',
79 {tms: true, opacity: 0.5, zIndex: 98, attribute: '&copy; <a href="http://gnuboat.engsas.de">GNUBoat</a> contributors'}
[883b4a5]80 );
[c5b13e1]81 var layer_gnuboat_accuracy_high = L.tileLayer(
82 './tiles/gnuboat_100_100/{z}/{x}/{y}.png',
83 {tms: true, opacity: 0.5, zIndex: 98, attribute: '&copy; <a href="http://gnuboat.engsas.de">GNUBoat</a> contributors'}
84 ).addTo(GnuBoat.Webserver.private.map);
[2fa2ef8]85
86 // add layer control
[883b4a5]87 var baselayers = {
88 "Map": layer_openstreetmap,
89 };
90 // overlays
91 var overlays = {"Seamarks": layer_openseamap,
[c5b13e1]92 "GNUBoat Low Accuracy": layer_gnuboat_accuracy_low,
93 "GNUBoat High Accuracy": layer_gnuboat_accuracy_high,
[883b4a5]94 };
[2fa2ef8]95 GnuBoat.Webserver.private.mapControl = L.control.layers(
[883b4a5]96 baselayers, overlays,
[2fa2ef8]97 {hideSingleBase: true, sortLayers: true, }
98 ).addTo(GnuBoat.Webserver.private.map);
99
100 // add scale
101 L.control.scale().addTo(GnuBoat.Webserver.private.map);
102 }
[3a89adb]103};
104
105GnuBoat.Webserver.login = function(form)
106{
107 Cookies.set('username', $("#loginUsername").val());
108 Cookies.set('password', $("#loginPassword").val());
109 GnuBoat.Webserver.private.loggedin = false;
110
111 // getting my waters
112 $.ajax({
113 headers: {
114// manager: Cookies.get('username')
115 manager: "bla"
116 },
117 dataType: "json",
118 url: GnuBoat.Webserver.private.serverBaseUrl +'waters',
119 }).done(function(data) {
120 GnuBoat.Webserver.private.loggedin = true;
121 GnuBoat.Webserver.loginCheck();
122
123 $("#myWatersDiv").empty();
124 if(data.length < 1){
125 $("<p>No Waters found!</p>").appendTo("#myWatersDiv");
126 }
127 else{
128 $('<select id="myWatersSelect" class="pure-input-1"></select>').appendTo("#myWatersDiv");
129 data.forEach(function(value, index){
130 $("<option value=\""+ value.water_id +"\">"+ value.name +"</option>").appendTo("#myWatersSelect");
131 })
132 }
133 $("#myWaters").show();
134 }).fail(function() {
135 alert('request failed');
136 });
137};
138
139GnuBoat.Webserver.loginCheck = function()
140{
141 console.log([Cookies.get('username'), Cookies.get('username') == undefined, Cookies.get('password'), Cookies.get('password') == undefined, GnuBoat.Webserver.private.loggedin]);
142 if(Cookies.get('username') == undefined || Cookies.get('password') == undefined || !GnuBoat.Webserver.private.loggedin){
143 $("#login").show();
144 return;
145 }
146 $("#login").hide();
147};
Note: See TracBrowser for help on using the repository browser.