OSDP Integration

Main

Demonstration of Open Science Data Portal Integration

OSDP Integration

Changes to map div:

Code
document.getElementById('Map1').remove();
Code
if (!document.getElementById('Map1')) {
  const newDiv = document.createElement('div');
  const id = document.createAttribute('id');
  id.value = 'Map1';
  newDiv.setAttributeNode(id);
  const dataLang = document.createAttribute('data-lang');
  dataLang.value = lang;
  newDiv.setAttributeNode(dataLang);
  document.getElementById('mapSection').appendChild(newDiv);
}
          

Currently: fr

Note: Will not effect the map until reloaded.

Code
lang = lang === 'fr' ? 'en' : 'fr';
const mapDiv = document.getElementById('Map1');
if (mapDiv) {
  mapDiv.setAttribute('data-lang', lang);
            }
          


Add Layers:


Code
if (document.getElementById('Map1')) {
  const layerUuids = document.getElementById('layerUuids').value;
  const uuidList = layerUuids.split('\n').join(',').split(',');
  addLayers(uuidList);
}

function addLayers(layers) {
  layers.forEach((layer) => {
    cgpv.api.maps.Map1.layer.addGeoviewLayerByGeoCoreUUID(layer);
  });
}
            

Code
cgpv.api.maps.Map1.layer.addGeoviewLayerByGeoCoreUUID(uuid, customListOfLayerEntries);


Current Stored Config:

Code
return new Promise (resolve => {
  removeMap('Map1')
    .then(() => {
      cgpv.api.createMapFromConfig('Map1', JSON.stringify(mapConfig), 800)
      .then(() => {
          resolve();
        });
    });
  });

  function removeMap(map) {
    return new Promise(resolve => {
      if (cgpv.api.maps[map]) {
        cgpv.api.maps[map].remove(false)
          .then(() => {
            resolve();
          });
      } else {
        resolve();
      }
    });
  }
          
Modes
true - All names are kept as they appear on the map
false - All geocore names are set to undefined, to be reapplied by the service
hybrid - Geocore layer names are kept, style to be reapplied by the service
          
Code
mapConfig = cgpv.api.maps.Map1.createMapConfigFromMapState(overrideGeocoreServiceNames);

Change the layer names in the config:

The examples provided below are for the default three layers in the add layers box above. To see this work, click the "Add Layers" button with the default layers, click "Update With Map State" once the layers are loaded, and then click "Change Names". The names in the config will be updated.

To try it yourself, add any layer to the map, update the config, and then copy the layer name you would like to change. Put it in square brackets in the box below, followed by a comma, and then the name you would like to replace it with - [name to change, new name]. Note that the order of the names in the pair, and the order of the pairs do not matter, [Radioactivité de l'air, Radioactivity] and [Radioactivity, Radioactivité de l'air] will function the same - any provided layer name will be replaced with its pair, so the same call can be used to switch a name and switch it back.


Code
const pairs = [["Radioactivité de l'air", 'Radioactivity'], ['Périmètre de localisation des stations', 'Perimeter'], ['Carte commémorative du Canada', 'Commemorative Map']];
cgpv.api.maps.Map1.replaceMapConfigLayerNames(pairs, mapConfig);
        
Code
const pairs = [["Radioactivité de l'air", 'Radioactivity'], ['Périmètre de localisation des stations', 'Perimeter'], ['Carte commémorative du Canada', 'Commemorative Map']];
cgpv.api.maps.Map1.replaceMapConfigLayerNames(pairs, mapConfig, true);