PageSourceSearch

https://cloud.dstar.su/maps/RepeaterLayer.js

js dstar.su collected 2026-10-04 02:22:47 UTC 3,837 bytes, 123 lines download raw bytes

1// RepeaterLayer.js
2// Copyright 2012 Artem Prilutskiy
3
4var EssenceFormat = OpenLayers.Class(OpenLayers.Format.JSON,
5  {
6    read: function(data, filter)
7    {
8      var features = [];
9      var projection1 = new OpenLayers.Projection('EPSG:4326');
10      var projection2 = new OpenLayers.Projection('EPSG:900913');
11      for (var name in data)
12      {
13        var node = data[name];
14        var indent = '';
15        for (var index = 0; index < 4; index ++)
16        {
17          var letter = String.fromCharCode(index + 65);
18          if (node[letter] != undefined)
19          {
20            var module = node[letter];
21            var latitude = module['latitude'];
22            var longitude = module['longitude'];
23            if (latitude != undefined)
24            {
25              var color = 'red';
26              if (!node['state'])
27                color = 'black';
28
29              var point = new OpenLayers.Geometry.Point(longitude, latitude).transform(projection1, projection2);
30              features.push(new OpenLayers.Feature.Vector(point, { name: name, description: '', color: color }));
31
32              var color = 'orange';
33              if (module['frequency'] > 400)
34                color = 'gold';
35              if (module['frequency'] > 1200)
36                color = 'white';
37              if (!node['state'])
38                color = 'gray';
39
40              var radius = module['range'] * 1609.344 + 25;
41              var description = indent + letter + ': ' + module['frequency'] +
42                ' (' + String.fromCharCode(0x00b1) + module['shift'] + ') MHz';
43
44              var circle = OpenLayers.Geometry.Polygon.createRegularPolygon(point, radius, 30, 0);
45              features.push(new OpenLayers.Feature.Vector(circle, { name: '', description: description, color: color }));
46              indent = indent + String.fromCharCode(0x00a0) + '\n';
47            }
48          }
49        }
50      }
51      return features;
52    }
53  }
54);
55
56function createRepeaterLayer(name, filters)
57{
58  var style = new OpenLayers.Style(
59    {
60      label: '${label}',
61      strokeColor: '${color}',
62      strokeOpacity: 0.8,
63      strokeWidth: 1,
64      fillColor: '${color}',
65      fillOpacity: 0.4,
66      pointRadius: 6,
67      pointerEvents: 'visiblePainted',
68      fontColor: 'black',
69      fontSize: '${size}',
70      fontFamily: 'Arial, Tahoma, Veranda, Hevelica',
71      fontWeight: 'bold',
72      labelOutlineColor: 'snow',
73      labelOutlineWidth: 2
74    },
75    {
76      context:
77      {
78        label: function (feature)
79          { 
80            if (feature.cluster)
81            {
82              var count = 0;
83              for (var index = 0; index < feature.cluster.length; index ++)
84                if (feature.cluster[index].geometry instanceof OpenLayers.Geometry.Point)
85                  count ++;
86              return count + ' nodes';
87            }
88            return feature.attributes['name'] + '\n' + feature.attributes['description'];
89          },
90        color: function (feature)
91          {
92            return (feature.cluster) ? 'blue' : feature.attributes['color'];
93          },
94        'size' : function (feature)
95          {
96            return (feature.cluster) ? '18px' : '11px';
97          }
98      }
99    }
100  );
101
102  return new OpenLayers.Layer.Vector(
103    name,
104    {
105      projection: new OpenLayers.Projection('EPSG:900913'),
106      strategies:
107      [
108        new OpenLayers.Strategy.BBOX({ resFactor: 1 }),
109        new OpenLayers.Strategy.Cluster({ distance: 40, threshold: 8 })
110      ],
111      protocol: new OpenLayers.Protocol.Script(
112        {
113          url: 'https://tracker.dstar.su/api/essence.php',
114          params: filters,
115          callbackKey: 'callback',
116          srsInBBOX: true,
117          format: new EssenceFormat()
118        }
119      ),
120      styleMap: new OpenLayers.StyleMap({ default: style })
121    }
122  );
123};

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.