PageSourceSearch

https://www.guides-belleville.com/ete/wp-content/plugins/osm/js/osm-plugin-lib.js?ver=7.1.2

js guides-belleville.com collected 2026-09-30 03:35:40 UTC 16,309 bytes, 497 lines download raw bytes

1/*
2  OSM OpenLayers for OSM wordpress plugin
3  plugin: http://wp-osm-plugin.hyumika.com
4  blog:   http://www.hyumika.com
5*/
6
7// Display Disc / Circles
8function osm_getFeatureDiscCenter(a_tileLayer, a_discLayer, a_lon, a_lat, a_radius, a_centeropac, a_centercol, a_strw, a_strcol, a_stropac, a_fillcol, a_fillopac) 
9{
10    var lonLat = new OpenLayers.LonLat(a_lon, a_lat).transform(a_tileLayer.displayProjection, a_tileLayer.projection);
11
12    var discStyle    = { strokeColor: a_strcol,
13                         strokeOpacity: a_stropac,
14                         strokeWidth: a_strw,
15                         fillColor: a_fillcol,
16                         fillOpacity: a_fillopac
17                       };
18    var centerStyle  = { strokeColor: a_centercol,
19                         strokeOpacity: a_centeropac,
20                         strokeWidth: a_strw,
21                         fillColor: a_centercol,
22                         fillOpacity: a_centeropac
23                       };
24
25    var radius = a_radius / Math.cos(a_lat*(Math.PI/180));
26
27    var disc = OpenLayers.Geometry.Polygon.createRegularPolygon(
28                                             new OpenLayers.Geometry.Point(lonLat.lon, lonLat.lat),
29                                             radius,
30                                             200); // nombre de faces
31                 
32    var center = OpenLayers.Geometry.Polygon.createRegularPolygon(
33                                             new OpenLayers.Geometry.Point(lonLat.lon, lonLat.lat),
34                                             1,   // taille dans lunite de la carte
35                                             5);  // nombre de faces
36                 
37
38    var featureDisc   = new OpenLayers.Feature.Vector(disc,null,discStyle);
39    var featureCenter = new OpenLayers.Feature.Vector(center,null,centerStyle);
40    a_discLayer.addFeatures([featureDisc,featureCenter]);
41}
42
43// Draw line
44function osm_setLinePoints(a_tileLayer, a_lineLayer, a_strw, a_strcol, a_stropac, a_Points)
45{
46  var Points = new Array();
47
48  for (var i = 0; i < a_Points.length; i++) {
49   // var lonLat = new OpenLayers.LonLat(a_Points[i]["lon"], a_Points[i]["lat"]).transform(new OpenLayers.Projection("EPSG:4326"), a_tileLayer.getProjectionObject());
50   var lonLat = new OpenLayers.LonLat(a_Points[i]["lon"], a_Points[i]["lat"]).transform(a_tileLayer.displayProjection, a_tileLayer.projection);
51    Points[i] = new OpenLayers.Geometry.Point(lonLat.lon, lonLat.lat);
52  }
53  var line = new OpenLayers.Geometry.LineString(Points);
54  var style = { 
55    strokeColor: a_strcol, 
56    strokeOpacity: a_stropac, 
57    strokeWidth: a_strw 
58   };
59
60  var lineFeature = new OpenLayers.Feature.Vector(line, null, style);
61  a_lineLayer.addFeatures([lineFeature]);
62}
63
64
65// Clickhandler / Shorcode generator
66
67function osm_getIconSize(a_IconName){
68  Icon = new Object();
69  if (a_IconName.match('mic_')) {
70    Icon["height"] = "37";
71    Icon["width"] = "32";
72    Icon["offset_height"] = "-37";
73    Icon["offset_width"] = "-16";
74  }
75  else if (a_IconName.match('wpttemp')){
76    Icon["height"] = "24";
77    Icon["width"] = "24";
78    Icon["offset_height"] = "-24";
79    Icon["offset_width"] = "-0";
80  }
81  else if ((a_IconName == "camping.png") || (a_IconName == "friends.png") || (a_IconName == "guest_house.png") || (a_IconName == "home.png") || (a_IconName == "toilets.png")  || (a_IconName == "hotel.png")){
82    Icon["height"] = "32";
83    Icon["width"] = "32";
84    Icon["offset_height"] = "-16";
85    Icon["offset_width"] = "-16";
86  }
87  else if ((a_IconName == "hostel.png") || (a_IconName == "restaurant.png")){
88    Icon["height"] = "24";
89    Icon["width"] = "24";
90    Icon["offset_height"] = "-12";
91    Icon["offset_width"] = "-12";
92  }
93  else if (a_IconName == "marker_blue.png"){
94    Icon["height"] = "24";
95    Icon["width"] = "24";
96    Icon["offset_height"] = "-24";
97    Icon["offset_width"] = "0";
98  }
99  else if (a_IconName == "airport.png"){
100    Icon["height"] = "32";
101    Icon["width"] = "31";
102    Icon["offset_height"] = "-16";
103    Icon["offset_width"] = "-16";
104  }
105  else if (a_IconName == "bus.png"){
106    Icon["height"] = "32";
107    Icon["width"] = "26";
108    Icon["offset_height"] = "-16";
109    Icon["offset_width"] = "-13";
110  }
111  else if (a_IconName == "geocache.png"){
112    Icon["height"] = "25";
113    Icon["width"] = "25";
114    Icon["offset_height"] = "-12";
115    Icon["offset_width"] = "-12";
116  }
117  else if (a_IconName == "motorbike.png"){
118    Icon["height"] = "23";
119    Icon["width"] = "32";
120    Icon["offset_height"] = "-12";
121    Icon["offset_width"] = "-16";
122  }
123  else if (a_IconName == "services.png"){
124    Icon["height"] = "28";
125    Icon["width"] = "32";
126    Icon["offset_height"] = "-14";
127    Icon["offset_width"] = "-16";
128  }
129  else if (a_IconName == "styria_linux.png"){
130    Icon["height"] = "50";
131    Icon["width"] = "36";
132    Icon["offset_height"] = "-25";
133    Icon["offset_width"] = "-18";
134  }
135  else if (a_IconName == "marker_posts.png"){
136    Icon["height"] = "2";
137    Icon["width"] = "2";
138    Icon["offset_height"] = "-1";
139    Icon["offset_width"] = "-1";
140  }
141  else {
142    Icon["height"] = "32";
143    Icon["width"] = "32";
144    Icon["offset_height"] = "-16";
145    Icon["offset_width"] = "-16";
146  }
147  return Icon;
148}
149
150// Clickhandler / Shorcode generator
151
152function osm_getRadioValue(a_Form){
153  if (a_Form == "Markerform"){
154    for (var i=0; i < document.Markerform.Art.length; i++){
155      if (document.Markerform.Art[i].checked){
156        var rad_val = document.Markerform.Art[i].value;
157        return rad_val;
158      }
159    }
160    return "undefined";
161  }
162  else if (a_Form == "GPXcolourform"){
163    for (var i=0; i < document.GPXcolourform.Gpx_colour.length; i++){
164      if (document.GPXcolourform.Gpx_colour[i].checked){
165        var rad_val = document.GPXcolourform.Gpx_colour[i].value;
166        return rad_val;
167      }
168    }
169    return "undefined";
170  }
171  else if (a_Form == "Bordercolourform"){
172    for (var i=0; i < document.Bordercolourform.Border_colour.length; i++){
173      if (document.Bordercolourform.Border_colour[i].checked){
174        var rad_val = document.Bordercolourform.Border_colour[i].value;
175        return rad_val;
176      }
177    }
178    return "undefined";
179  }
180  else if (a_Form == "Naviform"){
181    for (var i=0; i < document.Naviform.Navi_Link.length; i++){
182      if (document.Naviform.Navi_Link[i].checked){
183        var rad_val = document.Naviform.Navi_Link[i].value;
184        return rad_val;
185      }
186    }
187    return "undefined";
188  }
189  else if (a_Form == "ControlStyleform"){
190    for (var i=0; i < document.ControlStyleform.Cntrl_style.length; i++){
191      if (document.ControlStyleform.Cntrl_style[i].checked){
192        var rad_val = document.ControlStyleform.Cntrl_style[i].value;
193        return rad_val;
194      }
195    }
196    return "undefined";
197  }
198  return "not implemented";
199}
200
201function osm_saveGeotag() {
202  if ((osm_ajax_object.lat == '') || (osm_ajax_object.lon == '')) {
203    alert('Place geotag in the map before save');
204  } else {
205    var data = {
206      action: 'act_saveGeotag',
207      lat: osm_ajax_object.lat,
208      lon: osm_ajax_object.lon,
209      icon: osm_ajax_object.icon,
210      post_id: osm_ajax_object.post_id,
211      geotag_nonce: osm_ajax_object.geotag_nonce
212    };
213
214    jQuery.post(osm_ajax_object.ajax_url, data, function(response) {
215      var div = document.getElementById("Geotag_Div");
216
217      if (response.success) {
218        div.innerHTML = '<span style="color:green;">' + response.data + '</span>';
219      } else {
220        div.innerHTML = '<span style="color:red;">Error: ' + response.data + '</span>';
221      }
222    });
223  }
224}
225
226
227function osm_savePostMarker() {
228  if ((osm_ajax_object.MarkerLat === '') || (osm_ajax_object.MarkerLon === '')) {
229    alert('Place marker in the map before save');
230    return;
231  }
232
233  var data = {
234    action: 'act_saveMarker',
235    MarkerId: osm_ajax_object.MarkerId,
236    MarkerLat: osm_ajax_object.MarkerLat,
237    MarkerLon: osm_ajax_object.MarkerLon,
238    MarkerIcon: osm_ajax_object.MarkerIcon,
239    MarkerText: osm_ajax_object.MarkerText,
240    MarkerName: osm_ajax_object.MarkerName,
241    post_id: osm_ajax_object.post_id,
242    marker_nonce: osm_ajax_object.marker_nonce,
243  };
244
245  jQuery.post(osm_ajax_object.ajax_url, data, function(response) {
246    var div = document.getElementById("Marker_Div");
247
248    if (!response || typeof response.success === 'undefined') {
249      div.innerHTML = '<span style="color:red;">Unexpected server response.</span>';
250      return;
251    }
252
253    if (response.success) {
254      div.innerHTML = '<span style="color:green;">' + response.data + '</span>';
255    } else {
256      div.innerHTML = '<span style="color:red;">Error: ' + response.data + '</span>';
257    }
258  }, 'json'); // <-- explizit als JSON erwarten
259}
260
261
262
263function getTileURL(bounds) {
264  var res = this.map.getResolution();
265  var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
266  var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
267  var z = this.map.getZoom();
268  var limit = Math.pow(2, z);
269  if (y < 0 || y >= limit) {
270    return null;
271  } 
272  else {
273    x = ((x % limit) + limit) % limit;
274    url = this.url;
275    path= z + "/" + x + "/" + y + "." + this.type;
276    if (url instanceof Array) {
277      url = this.selectUrl(path, url);
278    }
279    return url+path;
280  }
281}
282
283// http://trac.openlayers.org/changeset/9023
284function osm_getTileURL(bounds) {
285    var res = this.map.getResolution();
286    var x = Math.round((bounds.left - this.maxExtent.left) / (res * this.tileSize.w));
287    var y = Math.round((this.maxExtent.top - bounds.top) / (res * this.tileSize.h));
288    var z = this.map.getZoom();
289    var limit = Math.pow(2, z);
290
291    if (y < 0 || y >= limit) {
292        return OpenLayers.Util.getImagesLocation() + "404.png";
293    } else {
294        x = ((x % limit) + limit) % limit;
295        return this.url + z + "/" + x + "/" + y + "." + this.type;
296    }
297}
298
299
300function AddMarker(a_tileLayer, a_marker_distance)
301{
302    var ll;
303    var feature;
304    var marker;
305
306    var popup_maxwidth = 999;
307    var popup_maxheight = 250;
308
309    // Combine marker with a distance lower then 12 pixels
310    var PopUpArray = CombineNearMarker(a_marker_distance, a_tileLayer);
311
312    // Create marker
313    for (var i = 0; i < PopUpArray.length; i++)
314    {
315        // Convert coordinates
316        ll = new OpenLayers.LonLat(PopUpArray[i].Lon, PopUpArray[i].Lat).transform(a_tileLayer.displayProjection, a_tileLayer.projection);
317
318        // Create pop-up
319        feature = new OpenLayers.Feature(markers, ll, data);
320        feature.closeBox = true;
321        feature.popupClass = OpenLayers.Class(OpenLayers.Popup.FramedCloud,
322        {
323            "autoSize": true,
324            /*
325             * For "panMapIfOutOfView" and "keepInMap" see:
326             * http://permalink.gmane.org/gmane.comp.gis.openlayers.user/25702
327             */ 
328            "panMapIfOutOfView": false,
329            "keepInMap": false,
330            "contentDisplayClass": "olPopupContent",
331            maxSize: new OpenLayers.Size(popup_maxwidth, popup_maxheight)
332        });
333        //feature.data.overflow = "hidden";
334
335        // Create pop-up text
336        var TextArray = PopUpArray[i].Text;
337        var Text = 0;
338        for (var j = 0; j < TextArray.length; j++)
339        {
340        	if(j == 0)
341        	    Text = TextArray[j];
342        	else
343        		Text += "<br>" + TextArray[j];
344        }
345
346        feature.data.popupContentHTML = Text;
347
348        a_tileLayer.addPopup(feature.createPopup(feature.closeBox));
349        feature.popup.toggle();
350
351        // Create marker
352        if (PopUpArray[i].Count > 1) // If we have a combined marker than take an onther icon
353        {
354            marker = new OpenLayers.Marker(ll, data2.icon.clone());
355        }
356        else
357        {
358            marker = new OpenLayers.Marker(ll, data.icon.clone());
359        }
360
361        marker.feature = feature;
362        marker.events.register("mousedown", feature, markerClick);
363        markers.addMarker(marker);
364    }
365}
366
367function CombineNearMarker(PixelDiff, a_tileLayer)
368{
369    var px1 = a_tileLayer.getLonLatFromPixel(new OpenLayers.Pixel(0, 0));
370    var px2 = a_tileLayer.getLonLatFromPixel(new OpenLayers.Pixel(PixelDiff, 0));
371    var PixelLonLatDiff = Math.abs(px1.lon - px2.lon);
372
373    var PopUpArray = new Array();
374    var isNowPopUp = 0;
375
376    // Read all markers
377    for (var i = 0; i < MarkerArray.length; i++)
378    {
379        isNowPopUp = 0;
380
381        // Get the position of marker1 coordinates in pixel
382        var ll = new OpenLayers.LonLat(MarkerArray[i].Lon, MarkerArray[i].Lat).transform(a_tileLayer.displayProjection, a_tileLayer.projection);
383        var pixel = a_tileLayer.getPixelFromLonLat(ll);
384        var LonTemp1 = ll.lon;
385        var LatTemp1 = ll.lat;
386
387        // Use only the visible markers
388        if (pixel.x >= 0 && pixel.x <= a_tileLayer.size.w && pixel.y >= 0 && pixel.y <= a_tileLayer.size.h)
389        {
390            // Check if marker near to this marker exist
391            for (var j = 0; j < PopUpArray.length; j++)
392            {
393                // Get the position of marker2 coordinates in pixel
394                var ll = new OpenLayers.LonLat(PopUpArray[j].Lon, PopUpArray[j].Lat).transform(a_tileLayer.displayProjection, a_tileLayer.projection);
395                var LonTemp2 = ll.lon;
396                var LatTemp2 = ll.lat;
397
398                // Calculate difference of these two marker in pixel
399                var LonDiff = Math.abs(LonTemp1 - LonTemp2);
400                var LatDiff = Math.abs(LatTemp1 - LatTemp2);
401
402                // Check the distance
403                if (LonDiff <= PixelLonLatDiff && LatDiff <= PixelLonLatDiff)
404                {
405                    var Count = PopUpArray[j].Count;
406                    // Add this link to the existing marker
407                    PopUpArray[j].Text[Count] = MarkerArray[i].Text;
408                    // Calculate the mean position of these combined markers
409                    PopUpArray[j].Lat = (PopUpArray[j].Lat + MarkerArray[i].Lat) / 2;
410                    PopUpArray[j].Lon = (PopUpArray[j].Lon + MarkerArray[i].Lon) / 2;
411                    Count++;
412                    PopUpArray[j].Count = Count;
413                    isNowPopUp = 1;
414                }
415            }
416
417            // Add a new marker to the list
418            if (isNowPopUp == 0)
419            {
420                PopUpArray.push(
421                {
422                    Text: new Array(MarkerArray[i].Text),
423                    Lon: MarkerArray[i].Lon,
424                    Lat: MarkerArray[i].Lat,
425                    Count: 1
426                });
427            }
428        }
429    }
430
431    return PopUpArray;
432}
433
434document.addEventListener('DOMContentLoaded', function () {
435  // EventListener für Marker speichern und Shortcode generieren
436  const markerBtn = document.getElementById('osm-save-marker-btn');
437  if (markerBtn) {
438    markerBtn.addEventListener('click', function () {
439      osm_savePostMarker();
440      osm_generateAddMarkerSC();
441    });
442  }
443
444  // EventListener für Geotag speichern
445  const geotagBtn = document.getElementById('osm-save-geotag-btn');
446  if (geotagBtn) {
447    geotagBtn.addEventListener('click', function () {
448      osm_saveGeotag();
449    });
450  }
451  
452  // EventListener für generate File ShortCode
453  const FileSCBtn = document.getElementById('osm-gen-file-sc-btn');
454  if (FileSCBtn) {
455    FileSCBtn.addEventListener('click', function () {
456      osm_generateFileSC();
457    });
458  }
459  
460  // EventListener für generate tagged post ShortCode
461  const GenTPSCBtn = document.getElementById('osm-gen-tagged-post-sc-btn');
462  if (GenTPSCBtn) {
463    GenTPSCBtn.addEventListener('click', function () {
464      osm_generateTaggedPostsSC();
465    });
466  }
467  
468  const clusterRadio = document.getElementById('tagged_marker_cluster');
469  if (clusterRadio) {
470    clusterRadio.addEventListener('change', function () {
471      if (this.checked) {
472        osm_showTaggedSCmap();
473      }
474    });
475  }
476  
477  
478  const radios = document.querySelectorAll('input[name="tagged_marker_style"]');
479  radios.forEach(function (radio) {
480    radio.addEventListener('change', function () {
481      console.log("Marker Style gewählt:", this.value);
482      osm_showTaggedSCmap(); 
483    });
484  });
485  
486  const selectionBox = document.getElementById('show_selection_box');
487  if (selectionBox) {
488    selectionBox.addEventListener('change', function () {
489      osm_showFileSCmap();
490    });
491  }
492  
493});
494
495
496
497

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.