layer.applyEdits([selectedFeature], null, null, (res) => { if (res.length) { const idvalue = res[0].objectId; const layerid = getLayerId(layer); const layerName = layer.id; const service = layer.url.slice(0, layer.url.lastIndexOf('/')); const labels = settings.labels[lang]; const query = { title: labels.title, subtitle: labels.subtitle, logoUrl: settings.logoUrl, logoLinkUrl: settings.logoLinkUrl, activeSlopeClass: activeSlopeClass, webmap: settings.webmap, idvalue: idvalue, service: service, layerid: layerid, layerName: layerName, tcd: canopyDensity, lang: lang }; if (appid) { query.appid = appid; } const path = toQuerystring(query); window.open(`report.html?${path}`); } else { console.error('Unable to save feature at this time'); } }, (err) => { console.error(err); });
share = () => { const {map, language, settings} = this.context; const {activeLayers, activeTab, canopyDensity, gladStartDate, gladEndDate, formaStartDate, formaEndDate, terraIStartDate, terraIEndDate, lossToSelectIndex, lossFromSelectIndex, imazonStartMonth, imazonEndMonth, imazonStartYear, imazonEndYear, viirsStartDate, viirsEndDate, modisStartDate, modisEndDate } = this.props; const visibleLayers = []; activeLayers.forEach(activeLayer => { if (activeLayer !== layerKeys.USER_FEATURES) { visibleLayers.push(activeLayer); } }); modalActions.showShareModal(toQuerystring(prepareStateForShare({ map: map, language: language, settings: settings, basemap: basemapUtils.getBasemap(), activeLayers: visibleLayers, activeTab: activeTab, gladStartDate: this.formatDate(gladStartDate), gladEndDate: this.formatDate(gladEndDate), formaStartDate: this.formatDate(formaStartDate), formaEndDate: this.formatDate(formaEndDate), terraIStartDate: this.formatDate(terraIStartDate), terraIEndDate: this.formatDate(terraIEndDate), lossToSelectIndex: lossToSelectIndex, lossFromSelectIndex: lossFromSelectIndex, imazonStartMonth: imazonStartMonth, imazonEndMonth: imazonEndMonth, imazonStartYear: imazonStartYear, imazonEndYear: imazonEndYear, viirsStartDate: this.formatDate(viirsStartDate), viirsEndDate: this.formatDate(viirsEndDate), modisStartDate: this.formatDate(modisStartDate), modisEndDate: this.formatDate(modisEndDate), canopyDensity: canopyDensity }))); };
generateReport: (options) => { /** webmap or appid * Other Params possibly needed ** basemap - basemap to use, default is topo ** visibleLayers - visible layers of dynamic layer selected feature belongs too, default is all */ const { selectedFeature, settings, lang, canopyDensity, appid, activeSlopeClass } = options; const USER_FEATURES_CONFIG = utils.getObject(resources.layers.en, 'id', layerKeys.USER_FEATURES); //- Is this a custom feature or a feature from the webmap const layer = selectedFeature._layer; //- NOTE: LAYER ID FOR REPORT //- Depending on how they created the layer in AGOL, there may be different ways to parse these values const getLayerId = function getLayerId () { return layer.source ? layer.source.mapLayerId : layer.layerId; }; if (layer.id === USER_FEATURES_CONFIG.id) { layer.applyEdits([selectedFeature], null, null, (res) => { if (res.length) { const idvalue = res[0].objectId; const layerid = getLayerId(layer); const layerName = layer.id; const service = layer.url.slice(0, layer.url.lastIndexOf('/')); const labels = settings.labels[lang]; const query = { title: labels.title, subtitle: labels.subtitle, logoUrl: settings.logoUrl, logoLinkUrl: settings.logoLinkUrl, activeSlopeClass: activeSlopeClass, webmap: settings.webmap, idvalue: idvalue, service: service, layerid: layerid, layerName: layerName, tcd: canopyDensity, lang: lang }; if (appid) { query.appid = appid; } const path = toQuerystring(query); window.open(`report.html?${path}`); } else { console.error('Unable to save feature at this time'); } }, (err) => { console.error(err); }); } else if (layer.url) { //- from service const objectIdField = layer.objectIdField; const idvalue = selectedFeature.attributes[objectIdField]; const layerid = getLayerId(layer); const layerName = layer.id; //- NOTE: SERVICE URL FOR REPORT //- This may need more testing, the report needs only the service url, see the following: //- http://gis..../MapServer and not http://gis..../MapServer/8 //- http://gis..../MapServer and not http://gis..../MapServer/dynamicServer //- These can also vary by how they are created in AGOL const service = layer.url.slice(0, layer.url.lastIndexOf('/')); const labels = settings.labels[lang]; const path = toQuerystring({ title: labels.title, subtitle: labels.subtitle, logoUrl: settings.logoUrl, logoLinkUrl: settings.logoLinkUrl, activeSlopeClass: activeSlopeClass, webmap: settings.webmap, idvalue: idvalue, service: service, layerid: layerid, layerName: layerName, tcd: canopyDensity, lang: lang }); window.open(`report.html?${path}`); } }