Skip to content

Commit

Permalink
Merge pull request #222 from james-rae/vproj
Browse files Browse the repository at this point in the history
Validate Projections
  • Loading branch information
james-rae authored Jun 12, 2017
2 parents 32aad15 + d1062b6 commit ee3af8d
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 89 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "geoApi",
"version": "0.0.0-protoLR-99",
"version": "0.0.0-protoLR-62",
"description": "",
"main": "src/index.js",
"dependencies": {
Expand Down
9 changes: 9 additions & 0 deletions src/layer/layerRec/layerInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class LayerInterface {
// param: string
setDefinitionQuery () { return undefined; }

// param: spatialReference object
validateProjection () { return undefined; } // returns Boolean

// updates what this interface is pointing to, in terms of layer data source.
// often, the interface starts with a placeholder to avoid errors and return
// defaults. This update happens after a layer has loaded, and new now want
Expand Down Expand Up @@ -96,6 +99,7 @@ class LayerInterface {
this.setOpacity = standardSetOpacity;
this.setQuery = standardSetQuery;
this.zoomToBoundary = standardZoomToBoundary;
this.validateProjection = standardValidateProjection;
}

convertToFeatureLayer (layerRecord) {
Expand Down Expand Up @@ -397,6 +401,11 @@ function dynamicLeafSetDefinitionQuery(query) {
this._source.setDefinitionQuery(query);
}

function standardValidateProjection(spatialReference) {
/* jshint validthis: true */
return this._source.validateProjection(spatialReference);
}

module.exports = () => ({
LayerInterface
});
16 changes: 16 additions & 0 deletions src/layer/layerRec/layerRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,22 @@ class LayerRecord extends root.Root {
return this._rootProxy;
}

/**
* Determines if layer's spatial ref matches the given spatial ref.
* Mainly used to determine if a tile wont display on a map.
* Highly recommend only calling this after a layer's load event has happened.
* @param {Object} spatialReference spatial reference to compare against.
* @return {Boolean} true if layer has same sr as input. false otherwise.
*/
validateProjection (spatialReference) {
if (spatialReference && this._layer && this._layer.spatialReference) {
return this._apiRef.proj.isSpatialRefEqual(spatialReference, this._layer.spatialReference);
} else {
console.warn('validateProjection called -- essential info wasnt available');
return false;
}
}

/**
* Create a layer record with the appropriate geoApi layer type. Layer config
* should be fully merged with all layer options defined (i.e. this constructor
Expand Down
81 changes: 81 additions & 0 deletions test/lr/TileLRBasic1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import geoapi from '../../src/index';

// https://github.com/fgpv-vpgf/geoApi/wiki/Locally-Testing-GeoAPI
// to run, temporarily update package.json
// "main": "test/lr/TileLRBasic1.js"

geoapi('http://js.arcgis.com/3.14/', window).then(function (api) {
console.log('TEST PAGE - Basic Testing on Tile Layer Record');


var config1 = {
id: 'dog',
name: 'Tile Test',
url: 'http://geoappext.nrcan.gc.ca/arcgis/rest/services/BaseMaps/Graticule/MapServer',

metadataUrl: 'http://www.github.com',
layerType: 'esriTile',
controls: ['visibility', 'opacity', 'boundingBox'],
state: {
opacity: 1,
visibility: true,
boundingBox: false,
query: false
}
};

var lods = [
{ "level": 15, "resolution": 13.229193125052918, "scale": 50000 },
{ "level": 16, "resolution": 7.9375158750317505, "scale": 30000 },
{ "level": 17, "resolution": 4.6302175937685215, "scale": 17500 } ];

var sameSR = {
wkid: 3978
};
var diffSR = {
wkid: 102100
};

var layerRec = api.layer.createTileRecord(config1);
console.log('layer PROOF ', layerRec);
var proxy = layerRec.getProxy();
console.log('proxy PROOF ', proxy);

// hack to wait for layer to load

var to = setInterval(() => {
if (layerRec.state === 'rv-loaded') {
clearInterval(to);
afterLoadTests();
}
}, 1000);

function afterLoadTests() {
console.log('enhanced loaded')

console.log('visible scale set - sb 0,0', layerRec.getVisibleScales());

console.log('queryable, should be false', proxy.query);

console.log('proj check good, should be true', proxy.validateProjection(sameSR));
console.log('proj check bad, should be false', proxy.validateProjection(diffSR));

/*
layerRec.isOffScale(20000).then(offscale => {
console.log('offscale test - sb false, flase', offscale);
});
// note using hack of layerRec._layer for zoom scales, as that thing is private
console.log('find zoom scale test - sb level 17', layerRec.findZoomScale(lods, layerRec._layer, false));
console.log('visible - sb true', layerRec.visible);
proxy.symbology.then(sym => {
console.log('symbology - sb 1 element', sym);
});
*/

}

});
88 changes: 0 additions & 88 deletions test/lr/testTLayer.html

This file was deleted.

0 comments on commit ee3af8d

Please sign in to comment.