Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(landing): limit nztm to its extent #878

Merged
merged 1 commit into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions packages/landing/src/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import TileSource from 'ol/source/Tile';
import BaseEvent from 'ol/events/Event';
import { ImageTile } from 'ol';
import { gaEvent, GaEvent } from './config';
import { Extent } from 'ol/extent';

/** Projection to use for the URL bar */
const UrlProjection = Epsg.Wgs84.toEpsgString();

/** Default center point if none provided */
const DefaultCenter: Record<number, MapLocation> = {
[Epsg.Google.code]: { lat: -41.88999621, lon: 174.04924373, zoom: 6 },
[Epsg.Nztm2000.code]: { lat: -41.277848, lon: 174.6763921, zoom: 2 },
[Epsg.Nztm2000.code]: { lat: -41.277848, lon: 174.6763921, zoom: 3 },
};

export interface TileLoadEvent extends BaseEvent {
Expand Down Expand Up @@ -81,10 +82,18 @@ export class Basemaps {

const loc = proj.transform([location.lon, location.lat], UrlProjection, `EPSG:${projection}`);
let resolutions: undefined | number[] = undefined;
let extent: undefined | Extent = undefined;
if (projection == Epsg.Nztm2000) {
resolutions = NztmOl.resolutions;
extent = NztmOl.extent;
}
const view = new View({ projection: projection.toEpsgString(), center: loc, zoom: location.zoom, resolutions });
const view = new View({
projection: projection.toEpsgString(),
center: loc,
zoom: location.zoom,
resolutions,
extent,
});

const source = this.getSource();
source.addEventListener('tileloadstart', this.trackTileLoad);
Expand Down
10 changes: 10 additions & 0 deletions packages/landing/src/nztm2000.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Nztm2000Tms } from '@basemaps/geo/build/tms/nztm2000';
import { Extent } from 'ol/extent';
import { register } from 'ol/proj/proj4';
import WMTSTileGrid from 'ol/tilegrid/WMTS.js';
import Proj from 'proj4';
Expand All @@ -14,9 +15,18 @@ const origin = [topLeft[1], topLeft[0]]; // NZTM is defined as y,x not x,y
const resolutions = Nztm2000Tms.zooms.map((c, i) => Nztm2000Tms.pixelScale(i));
const matrixIds = Nztm2000Tms.zooms.map((c) => c.identifier);

const { lowerCorner, upperCorner } = Nztm2000Tms.def.boundingBox;
const extent: Extent = [
lowerCorner[Nztm2000Tms.indexX],
lowerCorner[Nztm2000Tms.indexY],
upperCorner[Nztm2000Tms.indexX],
upperCorner[Nztm2000Tms.indexY],
];

export const NztmOl = {
resolutions,
origin,
matrixIds,
extent,
TileGrid: new WMTSTileGrid({ origin, resolutions, matrixIds }),
};