@cowegis/client 1.0.1 → 1.0.3

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.
@@ -13,7 +13,7 @@ class MapElement extends HTMLElement {
13
13
  this.attachShadow({mode: 'open'});
14
14
  this.shadowRoot.innerHTML = template;
15
15
  this._leaflet = L;
16
- this._container = this.shadowRoot.querySelector('.cowegis-map-container');;
16
+ this._container = this.shadowRoot.querySelector('.cowegis-map-container');
17
17
  this._map = null;
18
18
  this._layers = {};
19
19
  this._controls = {};
@@ -21,6 +21,7 @@ class MapElement extends HTMLElement {
21
21
  this._listeners = {};
22
22
  this._config = {};
23
23
  this._assets = new AssetsLoader(this);
24
+ this._connected = false;
24
25
  }
25
26
 
26
27
  get container() {
@@ -41,9 +42,11 @@ class MapElement extends HTMLElement {
41
42
  this._listeners = {};
42
43
  this._config = this._prepareConfig(config);
43
44
 
44
- mapFactory.create(this).then(function () {
45
- this.dispatchEvent(new CustomEvent('cowegis:ready', {bubbles: true, detail: {element: this}}));
46
- }.bind(this));
45
+ if (this._connected) {
46
+ this._createMap();
47
+ } else {
48
+ this.addEventListener('cowegis:connected', this._createMap.bind(this));
49
+ }
47
50
  }
48
51
 
49
52
  get leaflet() {
@@ -89,6 +92,7 @@ class MapElement extends HTMLElement {
89
92
 
90
93
  config.then(function (config) {
91
94
  this.config = config;
95
+ this._setConnected();
92
96
  }.bind(this));
93
97
 
94
98
  return;
@@ -109,6 +113,8 @@ class MapElement extends HTMLElement {
109
113
  configLoaded = true;
110
114
  }.bind(this));
111
115
 
116
+ this._setConnected();
117
+
112
118
  if (configLoaded) {
113
119
  return;
114
120
  }
@@ -163,6 +169,17 @@ class MapElement extends HTMLElement {
163
169
 
164
170
  return config;
165
171
  }
172
+
173
+ _createMap() {
174
+ mapFactory.create(this).then(function () {
175
+ this.dispatchEvent(new CustomEvent('cowegis:ready', {bubbles: true, detail: {element: this}}));
176
+ }.bind(this));
177
+ }
178
+
179
+ _setConnected() {
180
+ this._connected = true;
181
+ this.dispatchEvent(new CustomEvent('cowegis:connected', {bubbles: true, detail: {element: this}}));
182
+ }
166
183
  }
167
184
 
168
185
  export default MapElement;
@@ -40,7 +40,7 @@ class MapFactory {
40
40
 
41
41
  this.registerListeners(config, element);
42
42
 
43
- if (config.view) {
43
+ if (config.view && config.view.center) {
44
44
  element.map.setView(config.view.center, config.view.zoom, config.view.zoomOptions);
45
45
  }
46
46
 
@@ -1,6 +1,7 @@
1
1
  import osmtogeojson from 'osmtogeojson';
2
2
 
3
3
  import leaflet from '../leaflet';
4
+ import {mapFactory} from "../factory";
4
5
 
5
6
  /**
6
7
  * Get the bounds as overpass bbox string.
@@ -30,7 +31,7 @@ export default leaflet.FeatureGroup.extend({
30
31
  *
31
32
  * @param options
32
33
  */
33
- initialize: function (options) {
34
+ initialize: function (options, element) {
34
35
  if (!options.pointToLayer) {
35
36
  options.pointToLayer = this.pointToLayer;
36
37
  }
@@ -39,10 +40,11 @@ export default leaflet.FeatureGroup.extend({
39
40
  }
40
41
 
41
42
  leaflet.Util.setOptions(this, options);
42
- this.options.dynamicLoad = !!this.options.query.match(/BBOX/g);
43
+ this.options.dynamicLoad = !this.options.adjustBounds && !!this.options.query.match(/BBOX/g);
43
44
 
44
45
  this._layer = leaflet.geoJson();
45
46
  this._layers = {};
47
+ this._element = element;
46
48
 
47
49
  this.addLayer(this._layer);
48
50
  },
@@ -58,7 +60,7 @@ export default leaflet.FeatureGroup.extend({
58
60
 
59
61
  var bounds = toOverpassBBoxString(this._map.getBounds());
60
62
  var query = this.options.query.replace(/(BBOX)/g, bounds);
61
- var url = this.options.endpoint + 'interpreter?data=[out:json];' + query;
63
+ var url = this.options.endpoint + 'interpreter?data=' + encodeURIComponent('[out:json];' + query);
62
64
 
63
65
  this._map.fire('dataloading', {layer: this});
64
66
 
@@ -74,11 +76,9 @@ export default leaflet.FeatureGroup.extend({
74
76
  this.removeLayer(this._layer);
75
77
  this._layer = layer;
76
78
 
77
- if (this.options.boundsMode === 'extend' && layer.getBounds().isValid()) {
79
+ if (this.options.adjustBounds && layer.getBounds().isValid()) {
78
80
  var bounds = this._map.getBounds();
79
- bounds = bounds.extend(layer.getBounds());
80
-
81
- this._map.fitBounds(bounds, this._map.getBoundsOptions());
81
+ this._map.fitBounds(bounds.extend(layer.getBounds()));
82
82
  }
83
83
 
84
84
  this._map.fire('dataload', {layer: this});
@@ -88,8 +88,9 @@ export default leaflet.FeatureGroup.extend({
88
88
  * @param map
89
89
  */
90
90
  onAdd: function (map) {
91
- // TODO: Make it configurable
92
- map.on('moveend', this.refreshData, this);
91
+ if (this.options.dynamicLoad) {
92
+ map.on('moveend', this.refreshData, this);
93
+ }
93
94
 
94
95
  this.refreshData();
95
96
  },
@@ -103,20 +104,18 @@ export default leaflet.FeatureGroup.extend({
103
104
  marker.setRadius(feature.properties.radius);
104
105
  }
105
106
 
106
- // TODO: Icon handling
107
107
  if (feature.properties.icon) {
108
- icon = this._map.getIcon(feature.properties.icon);
109
-
110
- } else if (feature.properties.tags
111
- && feature.properties.tags.amenity
112
- && this.options.amenityIcons[feature.properties.tags.amenity]
113
- ) {
114
- //icon = L.contao.getIcon(this.options.amenityIcons[feature.properties.tags.amenity]);
108
+ icon = feature.properties.icon;
109
+ } else if (feature.properties.amenity) {
110
+ icon = this.options.amenityIcons[feature.properties.amenity] || undefined;
115
111
  }
116
112
 
117
- // TODO: Icon handling
118
- if (icon) {
119
- marker.setIcon(icon);
113
+ if (icon && this._element.config.map.presets.icons[icon]) {
114
+ mapFactory.createIcon(
115
+ this._element.config.map.presets.icons[icon],
116
+ feature.properties,
117
+ this._element
118
+ ).then(icon => marker.setIcon(icon));
120
119
  }
121
120
  }
122
121
 
@@ -1,5 +1,5 @@
1
1
  import OverpassLayer from './OverpassLayer';
2
2
 
3
3
  export default async function (config, element) {
4
- return new OverpassLayer(config.options);
4
+ return new OverpassLayer(config.options, element);
5
5
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@cowegis/client",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Cowegis web client",
5
5
  "main": "js/client.js",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "git+https://github.com/cowegis/cowegis-js-client.git"
8
+ "url": "git+https://github.com/cowegis/client.git"
9
9
  },
10
10
  "keywords": [
11
11
  "Cowegis",
@@ -16,9 +16,9 @@
16
16
  "author": "netzmacht David Molineus",
17
17
  "license": "LGPL-3.0-or-later",
18
18
  "bugs": {
19
- "url": "https://github.com/cowegis/cowegis-js-client/issues"
19
+ "url": "https://github.com/cowegis/client/issues"
20
20
  },
21
- "homepage": "https://github.com/cowegis/cowegis-js-client#readme",
21
+ "homepage": "https://github.com/cowegis/client#readme",
22
22
  "dependencies": {
23
23
  "@fortawesome/fontawesome-svg-core": "^6.1",
24
24
  "@fortawesome/free-brands-svg-icons": "^6.1",