Skip to content
Snippets Groups Projects
Commit 21e1a8fa authored by Glenn Vorhes's avatar Glenn Vorhes
Browse files

update read options for geojson layer, its layer transform explicit

parent fd935cd5
No related branches found
No related tags found
No related merge requests found
......@@ -72,7 +72,8 @@ var LayerBaseVectorGeoJson = (function (_super) {
* @param {object} featureCollection - as geojson object
*/
LayerBaseVectorGeoJson.prototype.addFeatures = function (featureCollection) {
this.source.addFeatures(this._geoJsonFormat.readFeatures(featureCollection));
this.source.addFeatures(this._geoJsonFormat.readFeatures(featureCollection, { dataProjection: this._transform.dataProjection,
featureProjection: this._transform.featureProjection }));
};
/**
* trigger load features
......
{"version":3,"file":"LayerBaseVectorGeoJson.js","sourceRoot":"","sources":["../../src/layers/LayerBaseVectorGeoJson.ts"],"names":[],"mappings":"AAAA;;GAEG;;;;;;;;;;;;;AAEH,qDAA0E;AAC1E,2CAAsC;AACtC,8BAAiC;AACjC,0BAA6B;AAE7B,+CAAiD;AACjD,wDAAkD;AAElD,IAAI,EAAE,GAAG,iBAAO,CAAC,QAAQ,CAAC,CAAC;AAa3B;;;GAGG;AACH;IAA4C,0CAAe;IAIvD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,gCAAY,GAAY,EAAE,OAA2C;QAA3C,wBAAA,EAAA,YAA2C;QAArE,iBAaC;QAZG,GAAG,GAAG,OAAO,GAAG,IAAI,QAAQ,GAAG,GAAG,GAAG,EAAE,CAAC;QACxC,QAAA,kBAAM,GAAG,EAAE,OAAO,CAAC,SAAC;QAEpB,KAAI,CAAC,cAAc,GAAG,IAAI,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAE9C,KAAI,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC;QAC1C,KAAI,CAAC,UAAU,CAAC,cAAc,GAAG,KAAI,CAAC,UAAU,CAAC,cAAc,IAAI,IAAI,CAAC,QAAQ,CAAC;QACjF,KAAI,CAAC,UAAU,CAAC,iBAAiB,GAAG,KAAI,C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A6FnC,EAAE,CAAC,sBAAsB,GAAG,sBAAsB,CAAC;AACnD,kBAAe,sBAAsB,CAAC","sourcesContent":["/**\r\n * Created by gavorhes on 11/2/2015.\r\n */\r\n\r\nimport {LayerBaseVector, LayerBaseVectorOptions} from './LayerBaseVector';\r\nimport provide from '../util/provide';\r\nimport ol = require('custom-ol');\r\nimport $ = require('jquery');\r\nimport {MapMoveCls} from \"../olHelpers/mapMoveCls\";\r\nimport * as proj from '../olHelpers/projections';\r\nimport {proj3857} from \"../olHelpers/projections\";\r\n\r\nlet nm = provide('layers');\r\n\r\nexport interface crsTransform {\r\n dataProjection?: ol.proj.Projection;\r\n featureProjection?: ol.proj.Projection;\r\n}\r\n\r\n\r\nexport interface LayerBaseVectorGeoJsonOptions extends LayerBaseVectorOptions {\r\n transform?: crsTransform;\r\n mapMoveObj?: MapMoveCls;\r\n}\r\n\r\n/**\r\n * The Vector GeoJson Layer\r\n * @augments LayerBaseVector\r\n */\r\nexport class LayerBaseVectorGeoJson extends LayerBaseVector {\r\n _geoJsonFormat: ol.format.GeoJSON;\r\n _transform: crsTransform;\r\n\r\n /**\r\n * @param {string|null} url - resource url, set to '' to make blank layer\r\n * @param {object} options - config\r\n * @param {string} [options.id] - layer id\r\n * @param {string} [options.name=Unnamed Layer] - layer name\r\n * @param {number} [options.opacity=1] - opacity\r\n * @param {boolean} [options.visible=true] - default visible\r\n * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28\r\n * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28\r\n * @param {object} [options.params={}] the get parameters to include to retrieve the layer\r\n * @param {number} [options.zIndex=0] the z index for the layer\r\n * @param {function} [options.loadCallback] function to call on load, context this is the layer object\r\n * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed\r\n * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility\r\n * @param {boolean} [options.legendContent] additional content to add to the legend\r\n *\r\n * @param {boolean} [options.autoLoad=false] if the layer should auto load if not visible\r\n * @param {object} [options.style=undefined] the layer style, use openlayers default style if not defined\r\n * @param {boolean} [options.onDemand=false] if the layer should be loaded by extent on map move\r\n * @param {number} [options.onDemandDelay=300] delay before the map move callback should be called\r\n *\r\n * @param {object} [options.transform={}] SR transform, set as false for no transform\r\n * @param {string} options.transform.dataProjection=EPSG:4326 the data CRS\r\n * @param {string} options.transform.featureProjection=EPSG:3857 the feature/map CRS\r\n * @param {mapMoveMakeGetParams} [options.mapMoveMakeGetParams=function(lyr, extent, zoomLevel){}] function to create additional map move params\r\n * @param {MapMoveCls} [options.mapMoveObj=mapMove] alternate map move object for use with multi map pages\r\n */\r\n constructor(url?: string, options: LayerBaseVectorGeoJsonOptions = {}) {\r\n url = typeof url == 'string' ? url : '';\r\n super(url, options);\r\n\r\n this._geoJsonFormat = new ol.format.GeoJSON();\r\n\r\n this._transform = options.transform || {};\r\n this._transform.dataProjection = this._transform.dataProjection || proj.proj4326;\r\n this._transform.featureProjection = this._transform.featureProjection || proj3857;\r\n\r\n if (this.autoLoad || this.visible) {\r\n this._load();\r\n }\r\n }\r\n\r\n /**\r\n * add feature collection\r\n * @param {object} featureCollection - as geojson object\r\n */\r\n addFeatures(featureCollection: any) {\r\n\r\n this.source.addFeatures(this._geoJsonFormat.readFeatures(featureCollection));\r\n }\r\n\r\n\r\n /**\r\n * trigger load features\r\n * @protected\r\n * @returns {boolean} if already loaded\r\n */\r\n _load() {\r\n\r\n if (super._load()) {\r\n return true;\r\n }\r\n\r\n $.get(this._url,\r\n this._params,\r\n (d) => {\r\n this.addFeatures(d);\r\n this.loadCallback(this);\r\n }, 'json').fail(\r\n function () {\r\n this._loaded = false;\r\n }\r\n );\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * callback function on map move\r\n * @param {object} d the json response\r\n * @override\r\n */\r\n mapMoveCallback(d) {\r\n super.mapMoveCallback(d);\r\n this._source.addFeatures(this._geoJsonFormat.readFeatures(d,\r\n {featureProjection: this._transform.featureProjection, dataProjection: this._transform.dataProjection}));\r\n }\r\n}\r\n\r\nnm.LayerBaseVectorGeoJson = LayerBaseVectorGeoJson;\r\nexport default LayerBaseVectorGeoJson;\r\n"]}
\ No newline at end of file
{"version":3,"file":"LayerBaseVectorGeoJson.js","sourceRoot":"","sources":["../../src/layers/LayerBaseVectorGeoJson.ts"],"names":[],"mappings":"AAAA;;GAEG;;;;;;;;;;;;;AAEH,qDAA0E;AAC1E,2CAAsC;AACtC,8BAAiC;AACjC,0BAA6B;AAE7B,+CAAiD;AACjD,wDAAkD;AAElD,IAAI,EAAE,GAAG,iBAAO,CAAC,QAAQ,CAAC,CAAC;AAa3B;;;GAGG;AACH;IAA4C,0CAAe;IAIvD;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,gCAAY,GAAY,EAAE,OAA2C;QAA3C,wBAAA,EAAA,YAA2C;QAArE,iBAaC;QAZG,GAAG,GAAG,OAAO,GAAG,IAAI,QAAQ,GAAG,GAAG,GAAG,EAAE,CAAC;QACxC,QAAA,kBAAM,GAAG,EAAE,OAAO,CAAC,SAAC;QAEpB,KAAI,CAAC,cAAc,GAAG,IAAI,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QAE9C,KAAI,CAAC,UAAU,GAAG,OAAO,CAAC,SAAS,IAAI,EAAE,CAAC;QAC1C,KAAI,CAAC,UAAU,CAAC,cAAc,GAAG,KAAI,CAAC,UAAU,CAAC,cAAc,IAAI,IAAI,CAAC,QAAQ,CAAC;QACjF,KAAI,CAAC,UAAU,CAAC,iBAAiB,GAAG,KAAI,CAAC,UAAU,CAAC,iBAAiB,IAAI,sBAAQ,CAAC;QAElF,EAAE,CAAC,CAAC,KAAI,CAAC,QAAQ,IAAI,KAAI,CAAC,OAAO,CAAC,CAAC,CAAC;YAChC,KAAI,CAAC,KAAK,EAAE,CAAC;QACjB,CAAC;;IACL,CAAC;IAED;;;OAGG;IACH,4CAAW,GAAX,UAAY,iBAAsB;QAC9B,IAAI,CAAC,MAAM,CAAC,WAAW,CACn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erBaseVector';\r\nimport provide from '../util/provide';\r\nimport ol = require('custom-ol');\r\nimport $ = require('jquery');\r\nimport {MapMoveCls} from \"../olHelpers/mapMoveCls\";\r\nimport * as proj from '../olHelpers/projections';\r\nimport {proj3857} from \"../olHelpers/projections\";\r\n\r\nlet nm = provide('layers');\r\n\r\nexport interface crsTransform {\r\n dataProjection?: ol.proj.Projection;\r\n featureProjection?: ol.proj.Projection;\r\n}\r\n\r\n\r\nexport interface LayerBaseVectorGeoJsonOptions extends LayerBaseVectorOptions {\r\n transform?: crsTransform;\r\n mapMoveObj?: MapMoveCls;\r\n}\r\n\r\n/**\r\n * The Vector GeoJson Layer\r\n * @augments LayerBaseVector\r\n */\r\nexport class LayerBaseVectorGeoJson extends LayerBaseVector {\r\n _geoJsonFormat: ol.format.GeoJSON;\r\n _transform: crsTransform;\r\n\r\n /**\r\n * @param {string|null} url - resource url, set to '' to make blank layer\r\n * @param {object} options - config\r\n * @param {string} [options.id] - layer id\r\n * @param {string} [options.name=Unnamed Layer] - layer name\r\n * @param {number} [options.opacity=1] - opacity\r\n * @param {boolean} [options.visible=true] - default visible\r\n * @param {number} [options.minZoom=undefined] - min zoom level, 0 - 28\r\n * @param {number} [options.maxZoom=undefined] - max zoom level, 0 - 28\r\n * @param {object} [options.params={}] the get parameters to include to retrieve the layer\r\n * @param {number} [options.zIndex=0] the z index for the layer\r\n * @param {function} [options.loadCallback] function to call on load, context this is the layer object\r\n * @param {boolean} [options.legendCollapse=false] if the legend item should be initially collapsed\r\n * @param {boolean} [options.legendCheckbox=true] if the legend item should have a checkbox for visibility\r\n * @param {boolean} [options.legendContent] additional content to add to the legend\r\n *\r\n * @param {boolean} [options.autoLoad=false] if the layer should auto load if not visible\r\n * @param {object} [options.style=undefined] the layer style, use openlayers default style if not defined\r\n * @param {boolean} [options.onDemand=false] if the layer should be loaded by extent on map move\r\n * @param {number} [options.onDemandDelay=300] delay before the map move callback should be called\r\n *\r\n * @param {object} [options.transform={}] SR transform, set as false for no transform\r\n * @param {string} options.transform.dataProjection=EPSG:4326 the data CRS\r\n * @param {string} options.transform.featureProjection=EPSG:3857 the feature/map CRS\r\n * @param {mapMoveMakeGetParams} [options.mapMoveMakeGetParams=function(lyr, extent, zoomLevel){}] function to create additional map move params\r\n * @param {MapMoveCls} [options.mapMoveObj=mapMove] alternate map move object for use with multi map pages\r\n */\r\n constructor(url?: string, options: LayerBaseVectorGeoJsonOptions = {}) {\r\n url = typeof url == 'string' ? url : '';\r\n super(url, options);\r\n\r\n this._geoJsonFormat = new ol.format.GeoJSON();\r\n\r\n this._transform = options.transform || {};\r\n this._transform.dataProjection = this._transform.dataProjection || proj.proj4326;\r\n this._transform.featureProjection = this._transform.featureProjection || proj3857;\r\n\r\n if (this.autoLoad || this.visible) {\r\n this._load();\r\n }\r\n }\r\n\r\n /**\r\n * add feature collection\r\n * @param {object} featureCollection - as geojson object\r\n */\r\n addFeatures(featureCollection: any) {\r\n this.source.addFeatures(\r\n this._geoJsonFormat.readFeatures(featureCollection,\r\n {dataProjection: this._transform.dataProjection,\r\n featureProjection: this._transform.featureProjection}\r\n )\r\n );\r\n }\r\n\r\n\r\n /**\r\n * trigger load features\r\n * @protected\r\n * @returns {boolean} if already loaded\r\n */\r\n _load() {\r\n\r\n if (super._load()) {\r\n return true;\r\n }\r\n\r\n $.get(this._url,\r\n this._params,\r\n (d) => {\r\n this.addFeatures(d);\r\n this.loadCallback(this);\r\n }, 'json').fail(\r\n function () {\r\n this._loaded = false;\r\n }\r\n );\r\n\r\n return false;\r\n }\r\n\r\n /**\r\n * callback function on map move\r\n * @param {object} d the json response\r\n * @override\r\n */\r\n mapMoveCallback(d) {\r\n super.mapMoveCallback(d);\r\n this._source.addFeatures(this._geoJsonFormat.readFeatures(d,\r\n {featureProjection: this._transform.featureProjection, dataProjection: this._transform.dataProjection}));\r\n }\r\n}\r\n\r\nnm.LayerBaseVectorGeoJson = LayerBaseVectorGeoJson;\r\nexport default LayerBaseVectorGeoJson;\r\n"]}
\ No newline at end of file
......@@ -18,6 +18,7 @@ var mapPopup_1 = require("../olHelpers/mapPopup");
var provide_1 = require("../util/provide");
var ol = require("custom-ol");
var $ = require("jquery");
var projections_1 = require("../olHelpers/projections");
var nm = provide_1.default('layers');
function checkStyleNumber(itsIcon, itsLineStyle, itsIconConfig, itsLineConfig) {
"use strict";
......@@ -260,6 +261,7 @@ var LayerItsInventory = (function (_super) {
if (typeof options.itsType !== 'string') {
throw 'its type must be defined';
}
options.transform = { dataProjection: projections_1.proj4326, featureProjection: projections_1.proj3857 };
var addToLegend = '';
// define a style with the helper function if it is not explicitly defined
if (typeof options.style == 'undefined') {
......
This diff is collapsed.
......@@ -78,8 +78,12 @@ export class LayerBaseVectorGeoJson extends LayerBaseVector {
* @param {object} featureCollection - as geojson object
*/
addFeatures(featureCollection: any) {
this.source.addFeatures(this._geoJsonFormat.readFeatures(featureCollection));
this.source.addFeatures(
this._geoJsonFormat.readFeatures(featureCollection,
{dataProjection: this._transform.dataProjection,
featureProjection: this._transform.featureProjection}
)
);
}
......
......@@ -7,6 +7,7 @@ import mapPopup from '../olHelpers/mapPopup';
import provide from '../util/provide';
import ol = require('custom-ol');
import $ = require('jquery');
import {proj4326, proj3857} from '../olHelpers/projections'
let nm = provide('layers');
......@@ -275,6 +276,8 @@ class LayerItsInventory extends LayerBaseVectorGeoJson {
throw 'its type must be defined';
}
options.transform = {dataProjection: proj4326, featureProjection: proj3857};
let addToLegend = '';
// define a style with the helper function if it is not explicitly defined
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment