Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions demo/js/esri-datasets.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import createDatasetsPlugin from '/plugins/beta/datasets/src/index.js'
import { vtsMapStyles27700 } from './mapStyles.js'
import { transformGeocodeRequest, transformVtsRequest3857, setupEsriConfig } from './auth.js'

const datasets = [
{
const datasetFloodZonesCC = {
id: 'flood-zones-cc',
label: 'Flood Zones Climate Change',
groupLabel: 'Datasets',
Expand Down Expand Up @@ -67,8 +66,9 @@ const datasets = [
showInMenu: false,
}
]
},
{
}

const datasetFloodZones = {
id: 'flood-zones',
label: 'Flood Zones',
groupLabel: 'Datasets',
Expand Down Expand Up @@ -100,6 +100,9 @@ const datasets = [
}
]
}

const datasets = [
datasetFloodZonesCC, datasetFloodZones
]

const datasetsPlugin = createDatasetsPlugin({
Expand Down Expand Up @@ -146,4 +149,7 @@ const testGlobalVisibility = () => {

interactiveMap.on('datasets:ready', function () {
// testGlobalVisibility()
setTimeout(() => datasetsPlugin.removeDataset('flood-zones-cc'), 1000)
setTimeout(() => datasetsPlugin.removeDataset('flood-zones'), 3000)
setTimeout(() => datasetsPlugin.addDataset(datasetFloodZones), 5000)
})
1 change: 1 addition & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default {
],
testPathIgnorePatterns: ['<rootDir>/src/test-utils.js'],
coveragePathIgnorePatterns: [
'/__mocks__/',
'<rootDir>/src/index.umd.js',
'<rootDir>/stylelint.config.js',
'<rootDir>/coverage',
Expand Down
100 changes: 67 additions & 33 deletions plugins/beta/datasets/src/adapters/esri/esriLayerAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import GroupLayer from '@arcgis/core/layers/GroupLayer.js'
import { LayerAdapter } from '../layerAdapter.js'
import { datasetRegistry } from '../../registry/datasetRegistry.js'
import { EsriDataset } from './registry/esriDataset.js'
import { logger } from '../../../../../../src/services/logger.js'

export default class EsriLayerAdapter extends LayerAdapter {
constructor (mapProvider, symbolRegistry, patternRegistry) {
Expand Down Expand Up @@ -76,24 +77,44 @@ export default class EsriLayerAdapter extends LayerAdapter {
return vectorTileLayer.when()
}

async removeDataset (...args) {
console.log('TODO: removeDataset', args)
}

async setData (...args) {
console.log('TODO: setData', args)
}

async applyStyle (...args) {
console.log('TODO: applyStyle', args)
async addDataset (datasetId) {
const registryDataset = datasetRegistry.getDataset(datasetId)
if (!registryDataset) {
logger.warn(`addDataset called, but Dataset with id ${datasetId} not found in registry`)
return
}
await this._addLayers(registryDataset)
const { parentId } = registryDataset
const vectorTileLayer = this._vectorTileLayers[parentId || datasetId]
this.applyDatasetOpacity(datasetId)
this._applyStyleLayerPaintProperties(registryDataset, vectorTileLayer)
this.applyDatasetVisibility(datasetId)
}

_applyStyleLayerVisibility (sublayer, vectorTileLayer) {
const { esriStyleLayerId } = sublayer
if (!esriStyleLayerId) {
async removeDataset (datasetId) {
const registryDataset = datasetRegistry.getDataset(datasetId)
if (!registryDataset) {
return
}
vectorTileLayer.setStyleLayerVisibility(esriStyleLayerId, sublayer.visibility)
const { esriGroupId } = registryDataset
const vectorTileLayer = this._vectorTileLayers[datasetId]
// If the dataset is part of a group layer, we need to remove it from the group layer
const groupLayer = esriGroupId ? this._groupLayers[esriGroupId] : null
const vectorTileParent = groupLayer || this._map

if (vectorTileLayer) {
// Remove the vectorTileLayer from the map or group layer
vectorTileParent.remove(vectorTileLayer)
// And remove the vectorTileLayer from the adapter's internal state
delete this._vectorTileLayers[datasetId]
delete this._vectorTileOpacityLayers[datasetId]
}

// If the group layer has no more sublayers, we need to also remove the group layer from the map
if (groupLayer && groupLayer.layers.length === 0) {
this._map.remove(groupLayer)
delete this._groupLayers[esriGroupId]
}
}

_applyRegistryDatasetVisibility (registryDataset) {
Expand Down Expand Up @@ -141,36 +162,49 @@ export default class EsriLayerAdapter extends LayerAdapter {
})
}

async addDataset (...args) {
console.log('TODO: addDataset', args)
_applyStyleLayerVisibility (registryDataset, vectorTileLayer) {
const { esriStyleLayerId } = registryDataset
if (!esriStyleLayerId || !vectorTileLayer) {
return
}
vectorTileLayer.setStyleLayerVisibility(esriStyleLayerId, registryDataset.visibility)
}

async applyFeatureFilter (...args) {
console.log('TODO: applyFeatureFilter', args)
_applyStyleLayerPaintProperties (registryDataset, vectorTileLayer) {
const { esriStyleLayerId, useServerStyle } = registryDataset
if (useServerStyle || !esriStyleLayerId || !vectorTileLayer) {
return
}
const layerPaintProperties = vectorTileLayer.getPaintProperties(esriStyleLayerId)
if (layerPaintProperties) {
registryDataset.applyLayerPaintProperties(layerPaintProperties)
vectorTileLayer.setPaintProperties(esriStyleLayerId, registryDataset.applyLayerPaintProperties(layerPaintProperties))
}
}

async onMapStyleChange () {
datasetRegistry.forEach(registryDataset => {
const { id, isSublayer, esriStyleLayerId, parent } = registryDataset
const { id, isSublayer, parent } = registryDataset
const vectorTileLayer = this._vectorTileLayers[isSublayer ? parent.id : id]
if (vectorTileLayer && esriStyleLayerId) {
// Show hide the style layer based on the dataset's mapStyle visibility
vectorTileLayer.setStyleLayerVisibility(esriStyleLayerId, registryDataset.visibility)
if (registryDataset.useServerStyle) {
// If the dataset is using the server style, we don't need to apply any paint properties
return
}
// Update the paint properties of the style layer based on the dataset's mapStyle style
const layerPaintProperties = vectorTileLayer.getPaintProperties(esriStyleLayerId)
if (layerPaintProperties) {
registryDataset.applyLayerPaintProperties(layerPaintProperties)
vectorTileLayer.setPaintProperties(esriStyleLayerId, registryDataset.applyLayerPaintProperties(layerPaintProperties))
}
}
this._applyStyleLayerVisibility(registryDataset, vectorTileLayer)
this._applyStyleLayerPaintProperties(registryDataset, vectorTileLayer)
})
// TODO - handle dynamic sources
}

// onMapSizeChange is not applicable to the esriLayerAdapter
async onMapSizeChange () {}

// Remaining methods are still todo
async applyFeatureFilter (...args) {
console.log('TODO: applyFeatureFilter', args)
}

async setData (...args) {
console.log('TODO: setData', args)
}

async applyStyle (...args) {
console.log('TODO: applyStyle', args)
}
}
Loading
Loading