Skip to content

Commit

Permalink
Merge pull request #124 from Canadian-Geospatial-Platform/dev-Aug30
Browse files Browse the repository at this point in the history
Dev revert back to Aug30 for Prod as per Bo's request
  • Loading branch information
johnweng001 authored Sep 26, 2023
2 parents 71a6dff + cadd783 commit 68fdab3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 135 deletions.
9 changes: 0 additions & 9 deletions src/common/envglobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ export function envglobals(): globalValues {
SITE_NAME: 'localhost',
JSON_SERVER_URL: 'http://localhost:3000',
APP_GEOLOCATOR_URL: 'https://tkyuwlg5f7.execute-api.ca-central-1.amazonaws.com/live/',
COG_TILESERVICE_URL:'https://fyhjej9kzc.execute-api.ca-central-1.amazonaws.com/cog/tiles/WebMercatorQuad/{z}/{x}/{y}@1x',
COG_META_URL:'https://fyhjej9kzc.execute-api.ca-central-1.amazonaws.com/cog/metadata',
COG_TILEJSON_URL:'https://fyhjej9kzc.execute-api.ca-central-1.amazonaws.com/cog/tilejson.json'
};
case 'app-dev.geo.ca':
return {
Expand All @@ -38,9 +35,6 @@ export function envglobals(): globalValues {
APP_GEOCORE_URL: 'https://geocore-dev.metadata.geo.ca',
SITE_NAME: 'dev.geo.ca',
APP_GEOLOCATOR_URL: 'https://geolocator-dev.api.geo.ca/',
COG_TILESERVICE_URL:'https://fyhjej9kzc.execute-api.ca-central-1.amazonaws.com/cog/tiles/WebMercatorQuad/{z}/{x}/{y}@1x',
COG_META_URL:'https://fyhjej9kzc.execute-api.ca-central-1.amazonaws.com/cog/metadata',
COG_TILEJSON_URL:'https://fyhjej9kzc.execute-api.ca-central-1.amazonaws.com/cog/tilejson.json'
};
case 'app-stage.geo.ca':
return {
Expand Down Expand Up @@ -96,7 +90,4 @@ interface globalValues {
SITE_NAME: string;
JSON_SERVER_URL?: string;
APP_GEOLOCATOR_URL?: string;
COG_TILESERVICE_URL?:string;
COG_TILEJSON_URL?:string;
COG_META_URL?:string;
}
2 changes: 1 addition & 1 deletion src/components/search/geosearch.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

.searchButton {
width: auto;
padding: 4px 15px;
padding: 4px 20px;
margin-bottom: 2em;
}

Expand Down
60 changes: 5 additions & 55 deletions src/components/search/geosearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ const GeoSearch = (
const storestacfilters = useSelector((state) => (state.mappingReducer.stacfilter ? state.mappingReducer.stacfilter : []));
const storespatempfilters = useSelector((state) => state.mappingReducer.spatempfilter);
const dispatch = useDispatch();
const [image, setImage]=useState(null);
const [zoom, setZoom] = useState(null);
const [center, setCenter] = useState(null);
const [boundbox, setBoundbox] = useState(useSelector((state) => state.mappingReducer.boundbox));
Expand All @@ -122,15 +121,8 @@ const GeoSearch = (
const dispatch = useDispatch(); */

const selectResult = (result: SearchResult | undefined) => {
if(image!==null){
map.removeLayer(image);
setImage(null);
}
map.eachLayer((layer: unknown) => {
// console.log(layer);
if(layer.options && layer.options.zIndex && layer.options.zIndex === 9999){
map.removeLayer(layer);
}
const { feature } = layer;
if (
!!feature &&
Expand All @@ -142,16 +134,15 @@ const GeoSearch = (
) {
map.removeLayer(layer);
}
});
});

if (result) {
const coordinates=JSON.parse(result.coordinates);
const data = {
type: 'Feature',
properties: { id: result.id, tag: 'geoViewGeoJSON' },
geometry: {
type: 'Polygon',
coordinates,
coordinates: JSON.parse(result.coordinates),
},
};
const selectedParams: AnalyticParams = {
Expand Down Expand Up @@ -179,56 +170,15 @@ const GeoSearch = (
analyticPost(selectedParams);
// eslint-disable-next-line new-cap
new L.geoJSON(data).addTo(map);

const center=new LatLng((coordinates[0][2][1] + coordinates[0][0][1]) / 2, (coordinates[0][1][0] + coordinates[0][0][0]) / 2);
const bounds = L.latLngBounds([[coordinates[0][2][1], coordinates[0][1][0]],[coordinates[0][0][1],coordinates[0][0][0]]]);
//console.log(center, bounds);
if(result.options){
let imageUrls=JSON.parse(result.options.replaceAll('""','"')).filter(o=>o.url && o.url !==null && o.description && o.description.en && (o.description.en.indexOf("image/tiff")>0 || o.description.en.indexOf("image/png")>0 || o.description.en.indexOf("image/jpeg")>0));
if(imageUrls.length>0 && result.keywords.toLowerCase().indexOf("stac")>=0){
let imgUrls=imageUrls.filter(o=>o.description.en.indexOf("image/tiff")>0);
let url=imageUrls[0].url;
if(imgUrls.length>0){
url=imgUrls[0].url;
}
//const imageBounds = L.latLngBounds([[coordinates[0][2][1], coordinates[0][1][0]],[coordinates[0][0][1],coordinates[0][0][0]]]
//);
//const image=L.imageOverlay(url, imageBounds, {opacity: 1}).addTo(map);
//setImage(image);
axios.get(`${EnvGlobals.COG_TILEJSON_URL}`, {params: {url}}).then((res)=>{
console.log(res);
const centers=res.data.center;
axios.get(`${EnvGlobals.COG_META_URL}`, {params: {url}}).then((res2)=>{
console.log(res2);
const min=res2.data.statistics['1'].min;
const max=res2.data.statistics['1'].max;
const imageBounds = L.latLngBounds([[res2.data.bounds[3], res2.data.bounds[2]],[res2.data.bounds[1], res2.data.bounds[0]]]);
var layer=new L.TileLayer(`${EnvGlobals.COG_TILESERVICE_URL}?url=${url}&resampling_method=nearest&bidx=1&rescale=${min}%2C${max}`, {bounds:imageBounds, zIndex:9999});
map.addLayer(layer);
console.log('added', layer);
map.setView(new LatLng(centers[1], centers[0]), centers[2]);
});
});

}else{
setMapView(center, bounds);
}
} else{
setMapView(center, bounds);
}
}
};

const setMapView=(center, bounds)=>{
map.fitBounds(bounds);
setTimeout(()=>map.setView(center, map.getZoom()>5?map.getZoom()-1:map.getZoom()), 500);
}

const handleSelect = (event: string) => {
// const {selectResult} = this.props;
const cardOpen = selected === event ? !open : true;
const result =
Array.isArray(results) && results.length > 0 && cardOpen ? results.find((r: SearchResult) => r.id === event) : undefined;
Array.isArray(results) && results.length > 0 && cardOpen ? results.find((r: SearchResult) => r.id === event) : undefined;

setSelected(event);
setOpen(cardOpen);
selectResult(result);
Expand Down Expand Up @@ -1501,7 +1451,7 @@ interface SearchResult {
description: string;
published: string;
keywords: string;
options: string;
options: [];
contact: [];
created: string;
spatialRepresentation: string;
Expand Down
74 changes: 6 additions & 68 deletions src/components/search/metadatapage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import { useLocation, useHistory } from 'react-router';
// import {useParams} from 'react-router-dom';
import { useDispatch, useSelector } from "react-redux";
import { useTranslation } from 'react-i18next';
import { MapContainer, TileLayer, GeoJSON, AttributionControl, ImageOverlay } from 'react-leaflet';
import { LatLng, LatLngBounds} from 'leaflet';
import { MapContainer, TileLayer, GeoJSON, AttributionControl } from 'react-leaflet';
import axios from "axios";
import BeatLoader from "react-spinners/BeatLoader";
import {
Expand Down Expand Up @@ -59,10 +58,6 @@ const MetaDataPage = (props) => {

const mapping = useSelector(state => state.mappingReducer.mapping);
const dispatch = useDispatch();
const [tileServiceUrl, setTileServiceUrl]=useState(null);
const [cogCenter, setCogCenter]=useState([]);
const [cogBounds, setCogBounds]=useState([]);
const [cogZoom, setCogZoom]=useState(0);
const [similarRec, setSimilarRec] = useState(true);
const [similarRecords, setSimilarRecords] = useState([]);
const [showSimilarRecords, setShowSimilarRecords] = useState([]);
Expand Down Expand Up @@ -162,44 +157,13 @@ const MetaDataPage = (props) => {
res.title = language === 'en' ? res.title_en : res.title_fr;
res.mappingtitle = { en: res.title_en, fr: res.title_fr };
setResult(res);

setLoading1(false);
//const sims = [{ uuid: 'a4d4b53b-143a-4d10-9ded-45abb164d239', title_en: 'Lost, Stolen and Found Sealed Sources and Radiation Devices', title_fr: 'Ensemble de données sur les sources scellées et les appareils à rayonnement perdus, volés ou trouvés' }, { uuid: '701e5144-5047-4a14-2c0b-03f97ffb7334', title_en: 'Referrals, Investigations and Founded Cases', title_fr: 'Orientations, enquêtes et affaires fondées - Services de délivrance de licences et protection pour les personnes prises en charge' }, { title_en: 'similar3' }, { title_en: 'similar4' }, { title_en: 'similar5' }, { title_en: 'similar6' }, { title_en: 'similar7' }, { title_en: 'similar8' }, { title_en: 'similar9' }, { title_en: 'similar10' }]
if (res.similarity) {
const sims = res.similarity;
setSimilarRecords(sims);
setShowSimilarRecords(sims.slice(0, 5));
}
if(res.options){
const imageUrls=res.options.filter(o=>o.url && o.url!==null && o.description && o.description.en && (o.description.en.indexOf("image/tiff")>=0||o.description.en.indexOf("image/png")>=0||o.description.en.indexOf("image/jpeg")>=0));
const hasImage=imageUrls.length>0 && res.keywords.toLowerCase().indexOf("stac")>=0;
let url;
if(hasImage){
let imgUrls=imageUrls.filter(o=>o.description.en.indexOf("image/tiff")>0);
url=imageUrls[0].url;
if(imgUrls.length>0){
url=imgUrls[0].url;
}
axios.get(`${EnvGlobals.COG_TILEJSON_URL}`, {params: {url}}).then((res)=>{
console.log(res);
const centers=res.data.center;
setCogCenter(new LatLng(centers[1], centers[0]));
setCogZoom(centers[2]);
axios.get(`${EnvGlobals.COG_META_URL}`, {params: {url}}).then((res2)=>{
console.log(res2);
const min=res2.data.statistics['1'].min;
const max=res2.data.statistics['1'].max;
const imageBounds = L.latLngBounds([[res2.data.bounds[3], res2.data.bounds[2]],[res2.data.bounds[1], res2.data.bounds[0]]]);
setCogBounds(imageBounds);
setTileServiceUrl(`${EnvGlobals.COG_TILESERVICE_URL}?url=${url}&resampling_method=nearest&bidx=1&rescale=${min}%2C${max}`);
setLoading1(false);
});
});
}else{
setLoading1(false);
}
}else{
setLoading1(false);
}
})
.catch(error => {
// console.log(error);
Expand Down Expand Up @@ -417,8 +381,7 @@ const MetaDataPage = (props) => {
const desc = option.description[language].split(";");
return { name: option.name[language], type: desc[0], format: desc[1], language: t(`page.${desc[2].toLowerCase().replace(',', '')}`), url: option.url };
});
const imageUrls=formattedOption.filter(o=>o.url && o.url!==null && o.description && o.description.en && (o.description.en.indexOf("image/png")>=0||o.description.en.indexOf("image/jpeg")>=0));
const hasImage=imageUrls.length>0 && result.keywords.toLowerCase().indexOf("stac")>=0;

const tcRange = ['N/A', 'N/A'];
tcRange[0] = result.temporalExtent.begin;
tcRange[1] = result.temporalExtent.end;
Expand All @@ -441,8 +404,7 @@ const MetaDataPage = (props) => {
const mapButtonClass = activeMap ? 'btn btn-search' : 'btn btn-search disabled';
const contact = formattedContact;
const coordinates = JSON.parse(result.coordinates);
const bounds = L.latLngBounds([[coordinates[0][2][1], coordinates[0][1][0]],[coordinates[0][0][1],coordinates[0][0][0]]]
);

const langInd = (language === 'en') ? 0 : 1;
const status = result.status.split(';')[langInd];
const maintenance = result.maintenance.split(';')[langInd];
Expand Down Expand Up @@ -744,7 +706,7 @@ const MetaDataPage = (props) => {
<div className="top-sections">
<section className="sec-search-result search-results-section search-results-map">
<div className="ratio ratio-16x9">
{!hasImage && <MapContainer
<MapContainer
center={[(coordinates[0][2][1] + coordinates[0][0][1]) / 2, (coordinates[0][1][0] + coordinates[0][0][0]) / 2]}
zoom={zoom}
zoomControl={false}
Expand All @@ -758,31 +720,7 @@ const MetaDataPage = (props) => {
"properties": { "id": result.id, "tag": "geoViewGeoJSON" },
"geometry": { "type": "Polygon", "coordinates": coordinates }
}} />

</MapContainer>}
{hasImage && <MapContainer
center={cogCenter}
zoom={cogZoom}
zoomControl={false}
attributionControl={false}
>
<TileLayer url="https://maps-cartes.services.geo.ca/server2_serveur2/rest/services/BaseMaps/CBMT_CBCT_GEOM_3857/MapServer/WMTS/tile/1.0.0/BaseMaps_CBMT_CBCT_GEOM_3857/default/default028mm/{z}/{y}/{x}.jpg" attribution={t("mapctrl.attribution")} />
<AttributionControl position="bottomleft" prefix={false} />
<TileLayer url={tileServiceUrl} bounds={cogBounds} />
<NavBar />
<GeoJSON key={result.id} data={{
"type": "Feature",
"properties": { "id": result.id, "tag": "geoViewGeoJSON" },
"geometry": { "type": "Polygon", "coordinates": coordinates }
}} />
{/*hasImage && <ImageOverlay
url={imageUrls[0].url}
bounds={bounds}
opacity={1}
zIndex={10}
/>
*/}
</MapContainer>}
</MapContainer>
</div>
</section>
<section className="sec-search-result search-results-section search-results-misc-data">
Expand Down
2 changes: 0 additions & 2 deletions src/components/search/sorting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ export default function Sorting(props: SortingProps): JSX.Element {
const onChange = (event) => {
onSorting(event.target.value);
};
/*
useEffect(() => {
console.log(props);
}, []);
*/
return (
<>
{/*
Expand Down

0 comments on commit 68fdab3

Please sign in to comment.