PageSourceSearch

https://www.bes.au/wp-content/plugins/osm/js/OSeaM/harbours.js?ver=6.9.9

js bes.au collected 2026-10-04 16:09:46 UTC 6,720 bytes, 196 lines download raw bytes

1/******************************************************************************
2 Copyright 2008 - 2011 Xavier Le Bourdon, Christoph Böhme, Mitja Kleider
3
4 This file originates from the Openstreetbugs project and was modified
5 by Matthias Hoffmann and Olaf Hannemann for the OpenSeaMap project.
6
7 This file is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 This file is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this file.  If not, see <http://www.gnu.org/licenses/>.
19 ******************************************************************************/
20
21/******************************************************************************
22 This file implements the client-side of the harbour display.
23 Version 0.1.5  03.10.2011
24 ******************************************************************************/
25
26// List of downloaded harbours:
27var harbours = new Array();
28
29var selectControlHarbour;
30
31// Current state of the user interface. This is used
32// to keep track which popups are displayed.
33var harbour_state = 0;
34var harbour_current_feature = null;
35var popuptime=0;
36
37
38// AJAX functions--------------------------------------------------------------------------------------------
39
40// Request harbours from the server.
41function make_harbour_request(params) {
42    var url = "";
43    for (var name in params) {
44        url += (url.indexOf("?") > -1) ? "&" : "?";
45        url += encodeURIComponent(name) + "=" + encodeURIComponent(params[name]);
46    }
47    // Example: http://dev.openseamap.org/website/map/api/getHarbours.php?b=43.16098&t=43.46375&l=16.23863&r=17.39219&ucid=0&maxSize=5&zoom=11
48    var skgUrl="http://dev.openseamap.org/website/map/api/getHarbours.php"+url;
49
50    var script = document.createElement("script");
51    script.src = skgUrl;
52    script.type = "text/javascript";
53    document.body.appendChild(script);
54}
55
56// This function is called from the scripts that are returned on make_harbour_request calls.
57function putHarbourMarker(id, lon, lat, names, link, type) {
58
59    if (!harbour_exist(id,type)) {
60        var name = names.split("-");
61        if(type==-1) {
62            type = determineHarbourType(name[0]);
63        }
64        var popupText = "<b>" + name[0] +"</b>&nbsp;&nbsp;&nbsp;&nbsp;<br/>";
65        if (typeof name[1] != "undefined") {
66            popupText += name[1];
67        }
68        if (typeof name[2] != "undefined") {
69            popupText += "<br/><i>" + name[2] + "</i>";
70        }
71        if (link != '') {
72            popupText += "<br/><br/><a href='" + link + "' target='blank'>" + linkTextSkipperGuide + "</a>";
73        }
74        popupText += "<br/><a href='http://openportguide.org/cgi-bin/weather/weather.pl/weather.png?var=meteogram&nx=614&ny=750&lat=" + lat + "&lon=" + lon + "&lang=" + language + "&unit=metric&label=" + convert2Locode(name[0]) + "' target='blank'>" + linkTextWeatherHarbour + "</a>";
75        create_harbour_marker(lon2x(lon), lat2y(lat), popupText, type);
76
77        var harbour = {id: id, name: names, lat: lat, lon: lon, type: type, feature: null};
78        harbours.push(harbour);
79    }
80}
81
82
83// Harbour management----------------------------------------------------------------------------------------
84
85// Downloads new harbours from the server.
86function refreshHarbours() {
87
88    if (refreshHarbours.call_count == undefined) {
89        refreshHarbours.call_count = 0;
90    } else {
91        ++refreshHarbours.call_count;
92    }
93    bounds = map.getExtent().toArray();
94    var b = y2lat(bounds[1]).toFixed(5);
95    var t = y2lat(bounds[3]).toFixed(5);
96    var l = x2lon(bounds[0]).toFixed(5);
97    var r = x2lon(bounds[2]).toFixed(5);
98
99    var params = { "b": b, "t": t, "l": l, "r": r, "ucid": refreshHarbours.call_count, "maxSize":getHarbourVisibility(zoom), "zoom":zoom};
100    make_harbour_request(params);
101}
102
103// Check if a harbour has been downloaded already.
104function harbour_exist(id,type) {
105    for (var i in harbours) {
106        if (harbours[i].id == id && (harbours[i].type == type
107            || type==-1 && (harbours[i].type==5
108                ||harbours[i].type==6 ))) {
109            return true;
110        }
111    }
112
113    return false;
114}
115
116function isWPI(type) {
117    /**********************************
118    1 = L
119    2 = M
120    3 = S
121    4 = V (Very small)
122    5 = Marina (representative skipperguide)
123    6 = Anchorage (representative skipperguide)
124    7 = other descr. skipperguide
125    ***********************************/
126    if(type<=4) {
127        return true;
128    }
129    return false;
130}
131
132function determineHarbourType(myName){
133    for (var i in harbours) {
134        var otherName = harbours[i].name.split("-");
135        if(myName==otherName[0]) {
136            return 6;
137        }
138    }
139    return 5;
140}
141
142function getHarbourVisibility(zoom){
143    var maxType=1;
144    if(zoom>=7) {
145        maxType=2;
146    }
147    if(zoom>=8) {
148        maxType=3;
149    }
150    if(zoom>=9) {
151        maxType=4;
152    }
153    if(zoom>=10) {
154        maxType=6;
155    }
156
157 return maxType;
158}
159
160// Return a harbour description from the list of downloaded harbours.
161function get_harbour(id,type) {
162    for (var i in harbours) {
163        if (harbours[i].id == id && harbours[i].type == type) {
164            return harbours[i];
165        }
166    }
167
168    return '';
169}
170
171function create_harbour_marker(x, y, popupText, type) {
172    var layer_poi_icon_style = OpenLayers.Util.extend({});
173    var harbour_marker = new OpenLayers.Geometry.Point(x, y);
174    var maxType = getHarbourVisibility(zoom);
175
176    if(type <= maxType){
177        if (isWPI(type)) {
178            layer_poi_icon_style.externalGraphic = './resources/places/harbour_32.png';
179        } else {
180            if (type == 6) {
181                layer_poi_icon_style.externalGraphic = './resources/places/anchorage_32.png';
182            } else {
183                layer_poi_icon_style.externalGraphic = './resources/places/marina_32.png';
184            }
185        }
186        layer_poi_icon_style.graphicWidth = 24;
187        layer_poi_icon_style.graphicHeight = 24;
188
189        if(zoom>=5 ||refreshHarbours.call_count>0) {
190            var pointFeature = new OpenLayers.Feature.Vector(harbour_marker, null, layer_poi_icon_style);
191            pointFeature.popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud);
192            pointFeature.data.popupContentHTML = popupText;
193            layer_pois.addFeatures([pointFeature]);
194        }
195    }
196}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.