IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Commit 8972509a authored by jedjas12's avatar jedjas12
Browse files

Set max bounds

parent 500f6e92
/* eslint-disable no-console */
import { LightningElement } from 'lwc'; import { LightningElement } from 'lwc';
import utils from 'c/utils'; import utils from 'c/utils';
...@@ -47,6 +48,11 @@ export default class GeoQuery extends LightningElement { ...@@ -47,6 +48,11 @@ export default class GeoQuery extends LightningElement {
[-30.06909396443886, 26.102030238912395], [-30.06909396443886, 26.102030238912395],
[-7.231698708367139, 74.47760116029443]]); [-7.231698708367139, 74.47760116029443]]);
// Locks the map region to one earth.
map.setMaxBounds([[-90,-180],[90,180]]);
// Implement map "on click" handler // Implement map "on click" handler
// If we could keep a reference to the map via a class variable (this.map = event.detail) this would be a lot cleaner // If we could keep a reference to the map via a class variable (this.map = event.detail) this would be a lot cleaner
// to bad this map doesn't wish to cooperate at the time being. // to bad this map doesn't wish to cooperate at the time being.
...@@ -78,33 +84,14 @@ export default class GeoQuery extends LightningElement { ...@@ -78,33 +84,14 @@ export default class GeoQuery extends LightningElement {
// If you zoom out far enough the world map will start to repeat accross the screan and leaflet // If you zoom out far enough the world map will start to repeat accross the screan and leaflet
// will return longitudes like 190 degrees for what would technicall be -170 // will return longitudes like 190 degrees for what would technicall be -170
let mlat = (((coord.lat + 90) % 180) - 90);
if(coord.lat >= 0){ //Works for positive let mlon = (((coord.lng + 180) % 360) - 180); //TODO
this.mlat = (((coord.lat + 180) % 360) - 180); //TODO
}
else if(coord.lat < 0){
let absmlat = Math.abs(coord.lng);
console.log(`YOLO: ${absmlat}`);
this.mlat = (((absmlat + 180) % 360) - 180);
this.mlat*=-1;
}
// let mlat = (((coord.lat + 90) % 180) - 90);
if(coord.lng >= 0){ //Works for positive
this.mlon = (((coord.lng + 180) % 360) - 180); //TODO
}
else if(coord.lng < 0){
let absmlon = Math.abs(coord.lng);
this.mlon = (((absmlon + 180) % 360) - 180);
this.mlon*=-1;
}
// Remember where the user actually clicked so we can put the markers in the correct spot // Remember where the user actually clicked so we can put the markers in the correct spot
let latOff = Math.trunc(coord.lat / 90); let latOff = Math.trunc(coord.lat / 90);
let lonOff = Math.trunc(coord.lng / 180); let lonOff = Math.trunc(coord.lng / 180);
console.log(`Translates to lat: ${this.mlat} lat offset: ${latOff} lon: ${this.mlon} lon offset: ${lonOff}`); console.log(`Translates to lat: ${mlat} lat offset: ${latOff} lon: ${mlon} lon offset: ${lonOff}`);
// radius in meters // radius in meters
let rad = 100000; let rad = 100000;
...@@ -121,8 +108,8 @@ export default class GeoQuery extends LightningElement { ...@@ -121,8 +108,8 @@ export default class GeoQuery extends LightningElement {
// where the user clicked... this should go in a controller module and is only // where the user clicked... this should go in a controller module and is only
// here because I was hacking this together for a demo // here because I was hacking this together for a demo
const distanceURL = new URL(DISTANCE_URL); const distanceURL = new URL(DISTANCE_URL);
distanceURL.searchParams.append('latitude', `${this.mlat}`); distanceURL.searchParams.append('latitude', `${mlat}`);
distanceURL.searchParams.append('longitude', `${this.mlon}`); distanceURL.searchParams.append('longitude', `${mlon}`);
distanceURL.searchParams.append('radiusMeters', `${rad}`); distanceURL.searchParams.append('radiusMeters', `${rad}`);
console.log('Getting: ' + distanceURL.href); console.log('Getting: ' + distanceURL.href);
......
...@@ -33,6 +33,7 @@ export default class Map extends LightningElement { ...@@ -33,6 +33,7 @@ export default class Map extends LightningElement {
const mapRoot = this.template.querySelector('.map-root'); const mapRoot = this.template.querySelector('.map-root');
this.map = L.map(mapRoot); this.map = L.map(mapRoot);
this.map.fitWorld(); this.map.fitWorld();
} }
/** /**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment