Skip to content

Commit

Permalink
feat(attrib-loader): attribute loader from file
Browse files Browse the repository at this point in the history
  • Loading branch information
james-rae committed Apr 16, 2015
1 parent 9259e5c commit 3116c5e
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 67 deletions.
34 changes: 1 addition & 33 deletions src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -695,20 +695,7 @@
}
],
"wms": [
{
"id": "geomet_wind",
"displayName": "@@config.layers.wms.geomet_wind.displayName",
"format": "image/jpeg",
"layerName": "GDPS.ETA_UU",
"imageUrl": "assets/images/wms.png",
"url": "http://geo.weather.gc.ca/geomet/",
"legendMimeType": "image/jpeg",
"featureInfo": {
"mimeType": "text/plain",
"parser": "windParse"
},
"settings": { "opacity": { "default": 0.4 } }
},

{
"id": "geomet_temp",
"displayName": "@@config.layers.wms.geomet_temp.displayName",
Expand All @@ -722,25 +709,6 @@
"parser": "tempParse"
},
"settings": { "opacity": { "default": 0.3 } }
},
{
"id": "geomet_rain",
"displayName": "@@config.layers.wms.geomet_rain.displayName",
"format": "image/jpeg",
"layerName": "RADAR_RRAI",
"imageUrl": "assets/images/wms.png",
"url": "http://geo.weather.gc.ca/geomet/",
"legendMimeType": "image/jpeg",
"settings": { "opacity": { "default": 0.8 } }
},
{
"id": "railroad",
"displayName": "@@config.layers.wms.wms6.displayName",
"format": "png",
"layerName": "railway.track",
"imageUrl": "assets/images/wms.png",
"url": "http://maps.geogratis.gc.ca/wms/railway_en",
"legendMimeType": "image/jpeg"
}
]

Expand Down
87 changes: 72 additions & 15 deletions src/js/RAMP/Modules/attributeLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,34 @@ define([
EventManager, GlobalStorage) {
"use strict";

/**
* Will generate object id indexes and parent pointers on a layer data object.
* Assumes data object already has features and object id field defined
*
* @method enhanceData
* @private
* @param {Object} layerData layer data object
*/
function enhanceData(layerData) {
//make parent pointers and a fun index on object id
layerData.features.forEach(function (elem, idx) {
//map object id to index of object in feature array
//use toString, as objectid is integer and will act funny using array notation.
layerData.index[elem.attributes[layerData.idField].toString()] = idx;

//pointer back to parent
elem.parent = layerData;
});
}

/**
* Will download the attribute data for a layer.
*
* @method loadAttributeData
* @private
* @param {String} layerId id of the layer
* @param {String} layerUrl the URL of the layer
* @param {String} layerType type of the layer. should be a value from GlobalStorage.layerType
* @param {String} layerType type of the layer. should be a value from GlobalStorage.layerType
*/
function loadAttributeData(layerId, layerUrl, layerType) {
switch (layerType) {
Expand All @@ -64,7 +84,7 @@ define([
function (result) {
//change to standard format and store.
//TODO change if we decide on a non-esri standard format
var attribData = {
var layerData = {
layerId: layerId,
features: result.features,
index: {}
Expand All @@ -75,24 +95,16 @@ define([
//find object id field
result.fields.every(function (elem) {
if (elem.type === 'esriFieldTypeOID') {
attribData.idField = elem.name;
layerData.idField = elem.name;
return false; //break the loop
}
return true; //keep looping
});

//make parent pointers and a fun index on object id
attribData.features.forEach(function (elem, idx) {
//map object id to index of object in feature array
//use toString, as objectid is integer and will act funny using array notation.
attribData.index[elem.attributes[attribData.idField].toString()] = idx;

//pointer back to parent
elem.parent = attribData;
});
enhanceData(layerData);

//store attribData
RAMP.data[layerId] = attribData;
RAMP.data[layerId] = layerData;
//new data. tell grid to reload
topic.publish(EventManager.Datagrid.APPLY_EXTENT_FILTER);
console.log('END ATTRIB LOAD: ' + layerId);
Expand All @@ -107,10 +119,55 @@ define([
console.log("Layer type not supported by attribute loader: " + layerType);
}

//TODO do we need to return any sort of promise to indicate when the loading has finished?
//TODO do we need to return any sort of promise to indicate when the loading has finished?
}

/**
* Will extract the attribute data from a file based layer.
*
* @method extractAttributeData
* @private
* @param {Object} layer the layer object
*/
function extractAttributeData(layer) {
switch (layer.ramp.type) {
case GlobalStorage.layerType.feature:

//change to standard format and store.
//TODO change if we decide on a non-esri standard format
var layerData = {
layerId: layer.id,
features: [],
index: {},
idField: layer.objectIdField
};

//TODO consider having the following stuff in a different function, that can be called when file based stuff is loaded.

//find object id field
layerData.features = layer.graphics.map(function (elem) {
return { attributes: elem.attributes };
});

enhanceData(layerData);

//store attribData
RAMP.data[layer.id] = layerData;
//new data. tell grid to reload
topic.publish(EventManager.Datagrid.APPLY_EXTENT_FILTER);
console.log('END ATTRIB LOAD: ' + layer.id);

break;

default:
console.log("Layer type not supported by attribute extractor: " + layer.ramp.type);
}

//TODO do we need to return any sort of promise to indicate when the loading has finished?
}

return {
loadAttributeData: loadAttributeData
loadAttributeData: loadAttributeData,
extractAttributeData: extractAttributeData
};
});
34 changes: 17 additions & 17 deletions src/js/RAMP/Modules/dataLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
* API.
*
* ####Imports RAMP Modules:
* {{#crossLink "LayerLoader"}}{{/crossLink}}
* {{#crossLink "GlobalStorage"}}{{/crossLink}}
* {{#crossLink "Map"}}{{/crossLink}}
* {{#crossLink "LayerLoader"}}{{/crossLink}}
* {{#crossLink "GlobalStorage"}}{{/crossLink}}
* {{#crossLink "Map"}}{{/crossLink}}
* {{#crossLink "Util"}}{{/crossLink}}
*
*
* @class DataLoader
* @static
* @uses dojo/Deferred
* @uses dojo/Deferred
* @uses dojo/query
* @uses dojo/_base/array
* @uses esri/request
Expand Down Expand Up @@ -105,7 +105,7 @@ define([
// jshint bitwise:true
}

return buf.slice(0,j);
return buf.slice(0, j);
}

if (args.type === 'binary') {
Expand Down Expand Up @@ -352,7 +352,7 @@ define([
};

dg.gridColumns.push(makeField('iconCol', '', '50px', 'Icon', 'graphic_icon', { orderable: false }));
dg.gridColumns.push(makeField('detailsCol', '', '60px', 'Details', 'details_button',{ orderable: false }));
dg.gridColumns.push(makeField('detailsCol', '', '60px', 'Details', 'details_button', { orderable: false }));

if (fields && fields.length) {
fields.forEach(function (field, idx) {
Expand Down Expand Up @@ -444,7 +444,7 @@ define([

/**
* Scan a geojson fragment and if plugins are available attempt to load new projection information
*
*
*/
function scanCrs(geoJson) {
if (!geoJson.crs || geoJson.crs.type !== 'name') { return; }
Expand Down Expand Up @@ -545,15 +545,15 @@ define([
function enhanceFileFeatureLayer(featureLayer, opts) {
//make a minimal config object for this layer
var newConfig = {
id: featureLayer.id,
displayName: opts.datasetName,
nameField: opts.nameField,
symbology: {
type: "simple",
imageUrl: opts.icon
},
datagrid: createDatagridConfig(opts.fields)
id: featureLayer.id,
displayName: opts.datasetName,
nameField: opts.nameField,
symbology: {
type: "simple",
imageUrl: opts.icon
},
datagrid: createDatagridConfig(opts.fields)
},
defaultRenderers = GlobalStorage.DefaultRenderers;

//backfill the rest of the config object with default values
Expand Down Expand Up @@ -692,4 +692,4 @@ define([
createDatagridConfig: createDatagridConfig,
createSymbologyConfig: createSymbologyConfig
};
});
});
10 changes: 8 additions & 2 deletions src/js/RAMP/Modules/layerLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,13 @@ define([
case GlobalStorage.layerType.feature:

//initiate the feature data download
AttributeLoader.loadAttributeData(layer.id, layer.url, layer.ramp.type);
if (layer.url) {
//service based. get feature data from the service
AttributeLoader.loadAttributeData(layer.id, layer.url, layer.ramp.type);
} else {
//file based. scrape data from the layer
AttributeLoader.extractAttributeData(layer);
}

//TODO consider the case where a layer was loaded by the user, and we want to disable things like maptips?

Expand Down Expand Up @@ -432,7 +438,7 @@ define([
},

/**
* Reacts when a layer has updated successfully. This means the layer has pulled its data and displayed it.
* Rettcts when a layer has updated successfully. This means the layer has pulled its data and displayed it.
*
* @method onLayerUpdateEnd
* @param {Object} evt
Expand Down

0 comments on commit 3116c5e

Please sign in to comment.