Skip to content

Commit

Permalink
WIP on map-link:
Browse files Browse the repository at this point in the history
* delete map-link._templateVars.boundsFallbackPCRS, unused, problematic
* change implementation of map-link.getBounds() to use getFallbackBounds
when necessary, which gets those bounds from the CRS.  map-link.getBounds()
is called during connectedCallback, so usually the CRS is defined by then.
* make map-extent.units getter fall back to M.FALLBACK_PROJECTION if no units
attribute is present
  • Loading branch information
prushfor authored and prushfor committed Nov 23, 2023
1 parent b4a80da commit 94ed3e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
3 changes: 1 addition & 2 deletions src/map-extent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ export class MapExtent extends HTMLElement {
return ['checked', 'label', 'opacity', 'hidden'];
}
get units() {
// this should fallback to something??
return this.getAttribute('units');
return this.getAttribute('units') || M.FALLBACK_PROJECTION;
}

get checked() {
Expand Down
25 changes: 9 additions & 16 deletions src/map-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,7 @@ export class MapLink extends HTMLElement {
inputsReady: Promise.allSettled(inputsReady),
zoom: linkedZoomInput,
zoomBounds: this._getZoomBounds(linkedZoomInput),
boundsFallbackPCRS: this.getFallbackBounds(
this.parentElement.units || M.FALLBACK_PROJECTION
),
// TODO: make map-extent.units fall back automatically
projection: this.parentElement.units || M.FALLBACK_PROJECTION,
projection: this.parentElement.units,
tms: this.tms,
step: step
};
Expand All @@ -493,12 +489,12 @@ export class MapLink extends HTMLElement {
getBounds() {
let template = this._templateVars;
let inputs = template.values,
projection = template.projection || M.FALLBACK_PROJECTION,
projection = this.parentElement.units,
value = 0,
boundsUnit = M.FALLBACK_CS;
let bounds = M[template.projection].options.crs.tilematrix.bounds(0),
let bounds = M[projection].options.crs.tilematrix.bounds(0),
defaultMinZoom = 0,
defaultMaxZoom = M[template.projection].options.resolutions.length - 1,
defaultMaxZoom = M[projection].options.resolutions.length - 1,
nativeMinZoom = defaultMinZoom,
nativeMaxZoom = defaultMaxZoom;
let locInputs = false,
Expand Down Expand Up @@ -554,12 +550,12 @@ export class MapLink extends HTMLElement {
if (numberOfAxes >= 2) {
locInputs = true;
}
if (!locInputs && template.boundsFallbackPCRS) {
bounds = template.boundsFallbackPCRS;
if (!locInputs) {
bounds = this.getFallbackBounds(projection);
} else if (locInputs) {
bounds = M.boundsToPCRSBounds(bounds, value, projection, boundsUnit);
} else {
bounds = M[template.projection].options.crs.pcrs.bounds;
bounds = M[projection].options.crs.pcrs.bounds;
}
return bounds;
}
Expand Down Expand Up @@ -621,11 +617,8 @@ export class MapLink extends HTMLElement {
cs
);
} else {
// TODO review. Should this.parentElement.units automatically fall back
// i.e. to OSMTILE if not specified? Probably, but it does not currently.
let fallbackProjection =
M[this.parentElement.units || M.FALLBACK_PROJECTION];
bounds = fallbackProjection.options.crs.pcrs.bounds;
let crs = M[this.parentElement.units];
bounds = crs.options.crs.pcrs.bounds;
}
return bounds;
}
Expand Down

0 comments on commit 94ed3e2

Please sign in to comment.