| 1234 | } |
| 1235 | |
| 1236 | defineCustomProjection(jsonTemplate) { |
| 1237 | let t = JSON.parse(jsonTemplate); |
| 1238 | if ( |
| 1239 | t === undefined || |
| 1240 | !t.proj4string || |
| 1241 | !t.projection || |
| 1242 | !t.resolutions || |
| 1243 | !t.origin || |
| 1244 | !t.bounds |
| 1245 | ) |
| 1246 | throw new Error('Incomplete TCRS Definition'); |
| 1247 | if (t.projection.indexOf(':') >= 0) |
| 1248 | throw new Error('":" is not permitted in projection name'); |
| 1249 | if (M[t.projection.toUpperCase()]) return t.projection.toUpperCase(); |
| 1250 | let tileSize = [256, 512, 1024, 2048, 4096].includes(t.tilesize) |
| 1251 | ? t.tilesize |
| 1252 | : M.TILE_SIZE; |
| 1253 | |
| 1254 | M[t.projection] = new Proj.CRS(t.projection, t.proj4string, { |
| 1255 | origin: t.origin, |
| 1256 | resolutions: t.resolutions, |
| 1257 | bounds: bounds(t.bounds), |
| 1258 | crs: { |
| 1259 | tcrs: { |
| 1260 | horizontal: { |
| 1261 | name: 'x', |
| 1262 | min: 0, |
| 1263 | max: (zoom) => |
| 1264 | Math.round( |
| 1265 | M[t.projection].options.bounds.getSize().x / |
| 1266 | M[t.projection].options.resolutions[zoom] |
| 1267 | ) |
| 1268 | }, |
| 1269 | vertical: { |
| 1270 | name: 'y', |
| 1271 | min: 0, |
| 1272 | max: (zoom) => |
| 1273 | Math.round( |
| 1274 | M[t.projection].options.bounds.getSize().y / |
| 1275 | M[t.projection].options.resolutions[zoom] |
| 1276 | ) |
| 1277 | }, |
| 1278 | bounds: (zoom) => |
| 1279 | bounds( |
| 1280 | [ |
| 1281 | M[t.projection].options.crs.tcrs.horizontal.min, |
| 1282 | M[t.projection].options.crs.tcrs.vertical.min |
| 1283 | ], |
| 1284 | [ |
| 1285 | M[t.projection].options.crs.tcrs.horizontal.max(zoom), |
| 1286 | M[t.projection].options.crs.tcrs.vertical.max(zoom) |
| 1287 | ] |
| 1288 | ) |
| 1289 | }, |
| 1290 | pcrs: { |
| 1291 | horizontal: { |
| 1292 | name: 'easting', |
| 1293 | get min() { |