PageSourceSearch

https://indiacinehub.gov.in/modules/contrib/geofield_map/js/geojson.js?v=1.x

js indiacinehub.gov.in collected 2026-10-02 17:36:59 UTC 7,657 bytes, 225 lines download raw bytes

1/**
2 * @file
3 * Javascript for the Geojson Google Maps.
4 *
5 * @source: https://github.com/JasonSanford/GeoJSON-to-Google-Maps
6 */
7
8(function ($, Drupal) {
9
10  'use strict';
11
12  Drupal.googleGeoJson = function (geojson, options) {
13
14    let _geometryToGoogleMaps = function (geojsonGeometry, opts, geojsonProperties) {
15
16      let googleObj;
17      let bounds;
18      let paths = [];
19      let path = [];
20      let i;
21      let j;
22      let k;
23      let coord;
24      let ll;
25
26      switch (geojsonGeometry.type) {
27        case 'Point':
28          opts.position = new google.maps.LatLng(geojsonGeometry.coordinates[1], geojsonGeometry.coordinates[0]);
29          bounds = new google.maps.LatLngBounds();
30          bounds.extend(opts.position);
31          googleObj = new google.maps.Marker(opts);
32          googleObj.set('bounds', bounds);
33          if (geojsonProperties) {
34            googleObj.set('geojsonProperties', geojsonProperties);
35          }
36          break;
37
38        case 'MultiPoint':
39          googleObj = [];
40          bounds = new google.maps.LatLngBounds();
41          for (i = 0; i < geojsonGeometry.coordinates.length; i++) {
42            opts.position = new google.maps.LatLng(geojsonGeometry.coordinates[i][1], geojsonGeometry.coordinates[i][0]);
43            bounds.extend(opts.position);
44            googleObj.push(new google.maps.Marker(opts));
45          }
46          if (geojsonProperties) {
47            for (k = 0; k < googleObj.length; k++) {
48              googleObj[k].set('geojsonProperties', geojsonProperties);
49            }
50          }
51          for (k = 0; k < googleObj.length; k++) {
52            googleObj[k].set('bounds', bounds);
53          }
54          break;
55
56        case 'LineString':
57          bounds = new google.maps.LatLngBounds();
58          path = [];
59          for (i = 0; i < geojsonGeometry.coordinates.length; i++) {
60            coord = geojsonGeometry.coordinates[i];
61            ll = new google.maps.LatLng(coord[1], coord[0]);
62            bounds.extend(ll);
63            path.push(ll);
64          }
65          opts.path = path;
66          googleObj = new google.maps.Polyline(opts);
67          googleObj.set('bounds', bounds);
68          if (geojsonProperties) {
69            googleObj.set('geojsonProperties', geojsonProperties);
70          }
71          break;
72
73        case 'MultiLineString':
74          googleObj = [];
75          bounds = new google.maps.LatLngBounds();
76          for (i = 0; i < geojsonGeometry.coordinates.length; i++) {
77            path = [];
78            for (j = 0; j < geojsonGeometry.coordinates[i].length; j++) {
79              coord = geojsonGeometry.coordinates[i][j];
80              ll = new google.maps.LatLng(coord[1], coord[0]);
81              bounds.extend(ll);
82              path.push(ll);
83            }
84            opts.path = path;
85            googleObj.push(new google.maps.Polyline(opts));
86          }
87          if (geojsonProperties) {
88            for (k = 0; k < googleObj.length; k++) {
89              googleObj[k].set('geojsonProperties', geojsonProperties);
90            }
91          }
92          for (k = 0; k < googleObj.length; k++) {
93            googleObj[k].set('bounds', bounds);
94          }
95          break;
96
97        case 'Polygon':
98          paths = [];
99          bounds = new google.maps.LatLngBounds();
100          for (i = 0; i < geojsonGeometry.coordinates.length; i++) {
101            path = [];
102            for (j = 0; j < geojsonGeometry.coordinates[i].length; j++) {
103              ll = new google.maps.LatLng(geojsonGeometry.coordinates[i][j][1], geojsonGeometry.coordinates[i][j][0]);
104              bounds.extend(ll);
105              path.push(ll);
106            }
107            paths.push(path);
108          }
109          opts.paths = paths;
110          googleObj = new google.maps.Polygon(opts);
111          googleObj.set('bounds', bounds);
112          if (geojsonProperties) {
113            googleObj.set('geojsonProperties', geojsonProperties);
114          }
115          break;
116
117        case 'MultiPolygon':
118          googleObj = [];
119          bounds = new google.maps.LatLngBounds();
120          for (i = 0; i < geojsonGeometry.coordinates.length; i++) {
121            paths = [];
122            for (j = 0; j < geojsonGeometry.coordinates[i].length; j++) {
123              path = [];
124              for (k = 0; k < geojsonGeometry.coordinates[i][j].length; k++) {
125                ll = new google.maps.LatLng(geojsonGeometry.coordinates[i][j][k][1], geojsonGeometry.coordinates[i][j][k][0]);
126                bounds.extend(ll);
127                path.push(ll);
128              }
129              paths.push(path);
130            }
131            opts.paths = paths;
132            googleObj.push(new google.maps.Polygon(opts));
133          }
134          if (geojsonProperties) {
135            for (k = 0; k < googleObj.length; k++) {
136              googleObj[k].set('geojsonProperties', geojsonProperties);
137            }
138          }
139          for (k = 0; k < googleObj.length; k++) {
140            googleObj[k].set('bounds', bounds);
141          }
142          break;
143
144        case 'GeometryCollection':
145          googleObj = [];
146          if (!geojsonGeometry.geometries) {
147            googleObj = _error('Invalid GeoJSON object: GeometryCollection object missing \'geometries\' member.');
148          }
149          else {
150            for (i = 0; i < geojsonGeometry.geometries.length; i++) {
151              googleObj.push(_geometryToGoogleMaps(geojsonGeometry.geometries[i], opts, geojsonProperties || null));
152            }
153          }
154          break;
155
156        default:
157          googleObj = _error('Invalid GeoJSON object: Geometry object must be one of \'Point\', \'LineString\', \'Polygon\' or \'MultiPolygon\'.');
158      }
159
160      return googleObj;
161
162    };
163
164    let _error = function (message) {
165
166      return {
167        type: 'Error',
168        message: message
169      };
170
171    };
172
173    let obj;
174
175    let opts = options || {};
176
177    switch (geojson.type) {
178      case 'FeatureCollection':
179        if (!geojson.features) {
180          obj = _error('Invalid GeoJSON object: FeatureCollection object missing \'features\' member.');
181        }
182        else {
183          obj = [];
184          for (let y = 0; y < geojson.features.length; y++) {
185            obj.push(_geometryToGoogleMaps(geojson.features[y].geometry, opts, geojson.features[y].properties));
186          }
187        }
188        break;
189
190      case 'GeometryCollection':
191        if (!geojson.geometries) {
192          obj = _error('Invalid GeoJSON object: GeometryCollection object missing \'geometries\' member.');
193        }
194        else {
195          obj = [];
196          for (let z = 0; z < geojson.geometries.length; z++) {
197            obj.push(_geometryToGoogleMaps(geojson.geometries[z], opts, geojson.geometries[z].properties));
198          }
199        }
200        break;
201
202      case 'Feature':
203        if (!(geojson.properties && geojson.geometry)) {
204          obj = _error('Invalid GeoJSON object: Feature object missing \'properties\' or \'geometry\' member.');
205        }
206        else {
207          obj = _geometryToGoogleMaps(geojson.geometry, opts, geojson.properties);
208        }
209        break;
210
211      case 'Point': case 'MultiPoint': case 'LineString': case 'MultiLineString': case 'Polygon': case 'MultiPolygon':
212        obj = geojson.coordinates
213          ? obj = _geometryToGoogleMaps(geojson, opts, geojson.properties)
214          : _error('Invalid GeoJSON object: Geometry object missing \'coordinates\' member.');
215        break;
216
217      default:
218        obj = _error('Invalid GeoJSON object: GeoJSON object must be one of \'Point\', \'LineString\', \'Polygon\', \'MultiPolygon\', \'Feature\', \'FeatureCollection\' or \'GeometryCollection\'.');
219
220    }
221
222    return obj;
223  };
224
225})(jQuery, Drupal);

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.