@masterportal/masterportalapi 2.8.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -16,6 +16,20 @@
16
16
 
17
17
  ---
18
18
 
19
+ ## 2.9.0 - 2022-10-25
20
+ ### Added
21
+
22
+ ### Changed
23
+ - Exports in src/rawLayerList and src/crs.js changed to module.exports to provide the possibility to stub the functions with sinon in masterportal.
24
+
25
+ ### Deprecated
26
+
27
+ ### Removed
28
+
29
+ ### Fixed
30
+
31
+ ---
32
+
19
33
  ## 2.8.0 - 2022-10-04
20
34
  ### Added
21
35
  - Issue #814: Adding optional error callbacks and availability detection to layers.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@masterportal/masterportalapi",
3
3
  "author": "Implementierungspartnerschaft Masterportal <info@masterportal.org> (https://www.masterportal.org)",
4
- "version": "2.8.0",
4
+ "version": "2.9.0",
5
5
  "license": "MIT",
6
6
  "description": "Basic functions of the Masterportal as api",
7
7
  "repository": {
@@ -58,9 +58,5 @@
58
58
  },
59
59
  "bugs": {
60
60
  "url": "https://bitbucket.org/geowerkstatt-hamburg/masterportalapi/issues"
61
- },
62
- "keywords": [
63
- "geo",
64
- "map"
65
- ]
61
+ }
66
62
  }
package/src/crs.js CHANGED
@@ -22,7 +22,7 @@ function addAliasForWFSFromGeoserver (epsgCode) {
22
22
  * @param {string} name - projection name as written in [0] position of namedProjections
23
23
  * @returns {(object|undefined)} proj4 projection object or undefined
24
24
  */
25
- export function getProjection (name) {
25
+ function getProjection (name) {
26
26
  return proj4.defs(name);
27
27
  }
28
28
 
@@ -33,7 +33,7 @@ export function getProjection (name) {
33
33
  ]] - projection name, projection definition string
34
34
  * @returns {undefined}
35
35
  */
36
- export function registerProjections (namedProjections = defaults.namedProjections) {
36
+ function registerProjections (namedProjections = defaults.namedProjections) {
37
37
  proj4.defs(namedProjections);
38
38
  register(proj4);
39
39
  namedProjections.forEach(projection => {
@@ -48,7 +48,7 @@ export function registerProjections (namedProjections = defaults.namedProjection
48
48
  * Returns all known projections.
49
49
  * @returns {object[]} array of projection objects with their name added
50
50
  */
51
- export function getProjections () {
51
+ function getProjections () {
52
52
  const projections = Object
53
53
  .keys(proj4.defs)
54
54
  .map(name => Object.assign(proj4.defs(name), {name}));
@@ -64,7 +64,7 @@ export function getProjections () {
64
64
  * @param {ol.Map} map - map to get projection of
65
65
  * @returns {string} active projection name of map
66
66
  */
67
- export function getMapProjection (map) {
67
+ function getMapProjection (map) {
68
68
  return map.getView().getProjection().getCode();
69
69
  }
70
70
 
@@ -87,7 +87,7 @@ function getProj4Projection (projection) {
87
87
  * @param {number[]} point - point to project
88
88
  * @returns {number[]|undefined} transformed point
89
89
  */
90
- export function transform (sourceProjection, targetProjection, point) {
90
+ function transform (sourceProjection, targetProjection, point) {
91
91
  const source = getProj4Projection(sourceProjection),
92
92
  target = getProj4Projection(targetProjection);
93
93
 
@@ -106,7 +106,7 @@ export function transform (sourceProjection, targetProjection, point) {
106
106
  * @param {number[]} point - point to project
107
107
  * @returns {number[]|undefined} new point or undefined
108
108
  */
109
- export function transformToMapProjection (map, sourceProjection, point) {
109
+ function transformToMapProjection (map, sourceProjection, point) {
110
110
  return transform(sourceProjection, getMapProjection(map), point);
111
111
  }
112
112
 
@@ -117,6 +117,16 @@ export function transformToMapProjection (map, sourceProjection, point) {
117
117
  * @param {number[]} point - point to project
118
118
  * @returns {(number[]|undefined)} new point or undefined
119
119
  */
120
- export function transformFromMapProjection (map, targetProjection, point) {
120
+ function transformFromMapProjection (map, targetProjection, point) {
121
121
  return transform(getMapProjection(map), targetProjection, point);
122
122
  }
123
+
124
+ module.exports = {
125
+ transformFromMapProjection,
126
+ transformToMapProjection,
127
+ transform,
128
+ getMapProjection,
129
+ getProjections,
130
+ registerProjections,
131
+ getProjection
132
+ };
package/src/layer/wms.js CHANGED
@@ -5,7 +5,7 @@ import TileGrid from "ol/tilegrid/TileGrid";
5
5
  import ImageWMS from "ol/source/ImageWMS.js";
6
6
  import {get as getProjection} from "ol/proj";
7
7
 
8
- import {getLayerWhere} from "../rawLayerList";
8
+ import {rawLayerList} from "../index.js";
9
9
 
10
10
  const OLCS_DEFAULT_OLCS_PROJECTION_CRS = "EPSG:3857";
11
11
 
@@ -176,7 +176,7 @@ export function updateSource (layer) {
176
176
  * @returns {(string|undefined)} the gfiURL, or undefined if it could not be constructed
177
177
  */
178
178
  export function getGfiURL (layer, map, coordinate) {
179
- const rawLayer = getLayerWhere({Id: layer.get("id")}),
179
+ const rawLayer = rawLayerList.getLayerWhere({Id: layer.get("id")}),
180
180
  resolution = map.getView().getResolution(),
181
181
  projection = map.getView().getProjection(),
182
182
  params = Object.assign({
@@ -11,7 +11,7 @@ import * as vectorBase from "../../layer/vectorBase";
11
11
  import * as vectortile from "../../layer/vectorTile";
12
12
  import * as oaf from "../../layer/oaf";
13
13
  import {createMapView} from "../../maps/mapView";
14
- import {initializeLayerList, getLayerWhere} from "../../rawLayerList";
14
+ import {rawLayerList} from "../../index.js";
15
15
  import {registerProjections} from "../../crs";
16
16
  import {setGazetteerUrl} from "../../searchAddress";
17
17
 
@@ -97,7 +97,7 @@ function addLayer (layerOrId, params = {visibility: true, transparency: 0, error
97
97
 
98
98
  // if parameter is id, create and add layer with masterportalAPI mechanisms
99
99
  if (typeof layerOrId === "string") {
100
- const rawLayer = getLayerWhere({id: layerOrId});
100
+ const rawLayer = rawLayerList.getLayerWhere({id: layerOrId});
101
101
 
102
102
  if (!rawLayer) {
103
103
  console.error("Layer with id '" + layerOrId + "' not found. No layer added to map.");
@@ -160,7 +160,7 @@ export function createMap (config = defaults, {mapParams, callback, errorCallbac
160
160
  map.set("id", `map2D_${mapIdCounter++}`);
161
161
 
162
162
  // extend callback to load configured initial layers
163
- initializeLayerList(config.layerConf, (param, error) => {
163
+ rawLayerList.initializeLayerList(config.layerConf, (param, error) => {
164
164
  getInitialLayers(config)
165
165
  .forEach(layer => {
166
166
  map.addLayer(layer.id, {errorCallback});
@@ -14,7 +14,7 @@ let layerList = [];
14
14
  * @param {function} [callback] - called with services after loaded; called with false and error on error
15
15
  * @returns {undefined} nothing, add callback to receive layerList
16
16
  */
17
- export function initializeLayerList (layerConf = defaults.layerConf, callback) {
17
+ function initializeLayerList (layerConf = defaults.layerConf, callback) {
18
18
  if (Array.isArray(layerConf)) {
19
19
  // case: parameter was services.json contents
20
20
  layerList = layerConf;
@@ -55,14 +55,14 @@ export function initializeLayerList (layerConf = defaults.layerConf, callback) {
55
55
  * @param {object} searchAttributes - key/value-pairs to be searched for, e.g. { typ: "WMS" } to get the first WMS
56
56
  * @returns {?object} first layer matching the searchAttributes or null if none was found
57
57
  */
58
- export function getLayerWhere (searchAttributes) {
58
+ function getLayerWhere (searchAttributes) {
59
59
  const keys = Object.keys(searchAttributes);
60
60
 
61
61
  return layerList.find(entry => keys.every(key => entry[key] === searchAttributes[key])) || null;
62
62
  }
63
63
 
64
64
  /** @returns {object[]} complete layerList as initialized */
65
- export function getLayerList () {
65
+ function getLayerList () {
66
66
  return layerList;
67
67
  }
68
68
 
@@ -72,7 +72,7 @@ export function getLayerList () {
72
72
  * @param {string} [featureAttribute] - if given, only one entry of map is returned
73
73
  * @returns {?(object|string)} - map of originalName->displayName or name of featureAttribute if specified; if layer or featureAttribute not found, null
74
74
  */
75
- export function getDisplayNamesOfFeatureAttributes (layerId, featureAttribute) {
75
+ function getDisplayNamesOfFeatureAttributes (layerId, featureAttribute) {
76
76
  const attributes = getLayerWhere({id: layerId});
77
77
 
78
78
  if (attributes && typeof featureAttribute === "string") {
@@ -86,3 +86,11 @@ export function getDisplayNamesOfFeatureAttributes (layerId, featureAttribute) {
86
86
 
87
87
  return null;
88
88
  }
89
+
90
+
91
+ module.exports = {
92
+ getLayerWhere,
93
+ getDisplayNamesOfFeatureAttributes,
94
+ initializeLayerList,
95
+ getLayerList
96
+ };