cone.maps 0.2__py3-none-any.whl

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.
Files changed (39) hide show
  1. cone/maps/__init__.py +64 -0
  2. cone/maps/browser/__init__.py +4 -0
  3. cone/maps/browser/map.py +139 -0
  4. cone/maps/browser/static/cone.maps.js +109 -0
  5. cone/maps/browser/static/cone.maps.min.js +1 -0
  6. cone/maps/browser/static/leaflet/images/layers-2x.png +0 -0
  7. cone/maps/browser/static/leaflet/images/layers.png +0 -0
  8. cone/maps/browser/static/leaflet/images/marker-icon-2x.png +0 -0
  9. cone/maps/browser/static/leaflet/images/marker-icon.png +0 -0
  10. cone/maps/browser/static/leaflet/images/marker-shadow.png +0 -0
  11. cone/maps/browser/static/leaflet/leaflet-src.js +14062 -0
  12. cone/maps/browser/static/leaflet/leaflet-src.js.map +1 -0
  13. cone/maps/browser/static/leaflet/leaflet.css +640 -0
  14. cone/maps/browser/static/leaflet/leaflet.js +6 -0
  15. cone/maps/browser/static/leaflet/leaflet.js.map +1 -0
  16. cone/maps/browser/static/leaflet-activearea/leaflet.activearea.js +458 -0
  17. cone/maps/browser/static/leaflet-geosearch/geosearch.css +240 -0
  18. cone/maps/browser/static/leaflet-geosearch/geosearch.umd.js +2 -0
  19. cone/maps/browser/static/leaflet-geosearch/geosearch.umd.js.map +1 -0
  20. cone/maps/browser/static/leaflet-markercluster/MarkerCluster.Default.css +60 -0
  21. cone/maps/browser/static/leaflet-markercluster/MarkerCluster.css +14 -0
  22. cone/maps/browser/static/leaflet-markercluster/leaflet.markercluster-src.js +2718 -0
  23. cone/maps/browser/static/leaflet-markercluster/leaflet.markercluster-src.js.map +1 -0
  24. cone/maps/browser/static/leaflet-markercluster/leaflet.markercluster.js +2 -0
  25. cone/maps/browser/static/leaflet-markercluster/leaflet.markercluster.js.map +1 -0
  26. cone/maps/browser/static/leaflet-nogap/L.TileLayer.NoGap.js +243 -0
  27. cone/maps/browser/static/leaflet-proj4/proj4leaflet.js +272 -0
  28. cone/maps/browser/static/proj4js/proj4-src.js +7174 -0
  29. cone/maps/browser/static/proj4js/proj4.js +1 -0
  30. cone/maps/locale/cone.maps.pot +0 -0
  31. cone/maps/tests.py +54 -0
  32. cone.maps-0.2-py3.9-nspkg.pth +1 -0
  33. cone_maps-0.2.dist-info/METADATA +179 -0
  34. cone_maps-0.2.dist-info/RECORD +39 -0
  35. cone_maps-0.2.dist-info/WHEEL +5 -0
  36. cone_maps-0.2.dist-info/licenses/LICENSE.rst +26 -0
  37. cone_maps-0.2.dist-info/licenses/LICENSE_LEAFLET.rst +23 -0
  38. cone_maps-0.2.dist-info/namespace_packages.txt +1 -0
  39. cone_maps-0.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,243 @@
1
+ // @class TileLayer
2
+
3
+ L.TileLayer.mergeOptions({
4
+ // @option keepBuffer
5
+ // The amount of tiles outside the visible map area to be kept in the stitched
6
+ // `TileLayer`.
7
+
8
+ // @option dumpToCanvas: Boolean = true
9
+ // Whether to dump loaded tiles to a `<canvas>` to prevent some rendering
10
+ // artifacts. (Disabled by default in IE)
11
+ dumpToCanvas: L.Browser.canvas && !L.Browser.ie,
12
+ });
13
+
14
+ L.TileLayer.include({
15
+ _onUpdateLevel: function(z, zoom) {
16
+ if (this.options.dumpToCanvas) {
17
+ this._levels[z].canvas.style.zIndex =
18
+ this.options.maxZoom - Math.abs(zoom - z);
19
+ }
20
+ },
21
+
22
+ _onRemoveLevel: function(z) {
23
+ if (this.options.dumpToCanvas) {
24
+ L.DomUtil.remove(this._levels[z].canvas);
25
+ }
26
+ },
27
+
28
+ _onCreateLevel: function(level) {
29
+ if (this.options.dumpToCanvas) {
30
+ level.canvas = L.DomUtil.create(
31
+ "canvas",
32
+ "leaflet-tile-container leaflet-zoom-animated",
33
+ this._container
34
+ );
35
+ level.ctx = level.canvas.getContext("2d");
36
+ this._resetCanvasSize(level);
37
+ }
38
+ },
39
+
40
+ _removeTile: function(key) {
41
+ if (this.options.dumpToCanvas) {
42
+ var tile = this._tiles[key];
43
+ var level = this._levels[tile.coords.z];
44
+ var tileSize = this.getTileSize();
45
+
46
+ if (level) {
47
+ // Where in the canvas should this tile go?
48
+ var offset = L.point(tile.coords.x, tile.coords.y)
49
+ .subtract(level.canvasRange.min)
50
+ .scaleBy(this.getTileSize());
51
+
52
+ level.ctx.clearRect(offset.x, offset.y, tileSize.x, tileSize.y);
53
+ }
54
+ }
55
+
56
+ L.GridLayer.prototype._removeTile.call(this, key);
57
+ },
58
+
59
+ _resetCanvasSize: function(level) {
60
+ var buff = this.options.keepBuffer,
61
+ pixelBounds = this._getTiledPixelBounds(this._map.getCenter()),
62
+ tileRange = this._pxBoundsToTileRange(pixelBounds),
63
+ tileSize = this.getTileSize();
64
+
65
+ tileRange.min = tileRange.min.subtract([buff, buff]); // This adds the no-prune buffer
66
+ tileRange.max = tileRange.max.add([buff + 1, buff + 1]);
67
+
68
+ var pixelRange = L.bounds(
69
+ tileRange.min.scaleBy(tileSize),
70
+ tileRange.max.add([1, 1]).scaleBy(tileSize) // This prevents an off-by-one when checking if tiles are inside
71
+ ),
72
+ mustRepositionCanvas = false,
73
+ neededSize = pixelRange.max.subtract(pixelRange.min);
74
+
75
+ // Resize the canvas, if needed, and only to make it bigger.
76
+ if (
77
+ neededSize.x > level.canvas.width ||
78
+ neededSize.y > level.canvas.height
79
+ ) {
80
+ // Resizing canvases erases the currently drawn content, I'm afraid.
81
+ // To keep it, dump the pixels to another canvas, then display it on
82
+ // top. This could be done with getImageData/putImageData, but that
83
+ // would break for tainted canvases (in non-CORS tilesets)
84
+ var oldSize = { x: level.canvas.width, y: level.canvas.height };
85
+ // console.info('Resizing canvas from ', oldSize, 'to ', neededSize);
86
+
87
+ var tmpCanvas = L.DomUtil.create("canvas");
88
+ tmpCanvas.style.width = (tmpCanvas.width = oldSize.x) + "px";
89
+ tmpCanvas.style.height = (tmpCanvas.height = oldSize.y) + "px";
90
+ tmpCanvas.getContext("2d").drawImage(level.canvas, 0, 0);
91
+ // var data = level.ctx.getImageData(0, 0, oldSize.x, oldSize.y);
92
+
93
+ level.canvas.style.width = (level.canvas.width = neededSize.x) + "px";
94
+ level.canvas.style.height = (level.canvas.height = neededSize.y) + "px";
95
+ level.ctx.drawImage(tmpCanvas, 0, 0);
96
+ // level.ctx.putImageData(data, 0, 0, 0, 0, oldSize.x, oldSize.y);
97
+ }
98
+
99
+ // Translate the canvas contents if it's moved around
100
+ if (level.canvasRange) {
101
+ var offset = level.canvasRange.min
102
+ .subtract(tileRange.min)
103
+ .scaleBy(this.getTileSize());
104
+
105
+ // console.info('Offsetting by ', offset);
106
+
107
+ if (!L.Browser.safari) {
108
+ // By default, canvases copy things "on top of" existing pixels, but we want
109
+ // this to *replace* the existing pixels when doing a drawImage() call.
110
+ // This will also clear the sides, so no clearRect() calls are needed to make room
111
+ // for the new tiles.
112
+ level.ctx.globalCompositeOperation = "copy";
113
+ level.ctx.drawImage(level.canvas, offset.x, offset.y);
114
+ level.ctx.globalCompositeOperation = "source-over";
115
+ } else {
116
+ // Safari clears the canvas when copying from itself :-(
117
+ if (!this._tmpCanvas) {
118
+ var t = (this._tmpCanvas = L.DomUtil.create("canvas"));
119
+ t.width = level.canvas.width;
120
+ t.height = level.canvas.height;
121
+ this._tmpContext = t.getContext("2d");
122
+ }
123
+ this._tmpContext.clearRect(
124
+ 0,
125
+ 0,
126
+ level.canvas.width,
127
+ level.canvas.height
128
+ );
129
+ this._tmpContext.drawImage(level.canvas, 0, 0);
130
+ level.ctx.clearRect(0, 0, level.canvas.width, level.canvas.height);
131
+ level.ctx.drawImage(this._tmpCanvas, offset.x, offset.y);
132
+ }
133
+
134
+ mustRepositionCanvas = true; // Wait until new props are set
135
+ }
136
+
137
+ level.canvasRange = tileRange;
138
+ level.canvasPxRange = pixelRange;
139
+ level.canvasOrigin = pixelRange.min;
140
+
141
+ // console.log('Canvas tile range: ', level, tileRange.min, tileRange.max );
142
+ // console.log('Canvas pixel range: ', pixelRange.min, pixelRange.max );
143
+ // console.log('Level origin: ', level.origin );
144
+
145
+ if (mustRepositionCanvas) {
146
+ this._setCanvasZoomTransform(
147
+ level,
148
+ this._map.getCenter(),
149
+ this._map.getZoom()
150
+ );
151
+ }
152
+ },
153
+
154
+ /// set transform/position of canvas, in addition to the transform/position of the individual tile container
155
+ _setZoomTransform: function(level, center, zoom) {
156
+ L.GridLayer.prototype._setZoomTransform.call(this, level, center, zoom);
157
+ if (this.options.dumpToCanvas) {
158
+ this._setCanvasZoomTransform(level, center, zoom);
159
+ }
160
+ },
161
+
162
+ // This will get called twice:
163
+ // * From _setZoomTransform
164
+ // * When the canvas has shifted due to a new tile being loaded
165
+ _setCanvasZoomTransform: function(level, center, zoom) {
166
+ // console.log('_setCanvasZoomTransform', level, center, zoom);
167
+ if (!level.canvasOrigin) {
168
+ return;
169
+ }
170
+ var scale = this._map.getZoomScale(zoom, level.zoom),
171
+ translate = level.canvasOrigin
172
+ .multiplyBy(scale)
173
+ .subtract(this._map._getNewPixelOrigin(center, zoom))
174
+ .round();
175
+
176
+ if (L.Browser.any3d) {
177
+ L.DomUtil.setTransform(level.canvas, translate, scale);
178
+ } else {
179
+ L.DomUtil.setPosition(level.canvas, translate);
180
+ }
181
+ },
182
+
183
+ _onOpaqueTile: function(tile) {
184
+ if (!this.options.dumpToCanvas) {
185
+ return;
186
+ }
187
+
188
+ // Guard against an NS_ERROR_NOT_AVAILABLE (or similar) exception
189
+ // when a non-image-tile has been loaded (e.g. a WMS error).
190
+ // Checking for tile.el.complete is not enough, as it has been
191
+ // already marked as loaded and ready somehow.
192
+ try {
193
+ this.dumpPixels(tile.coords, tile.el);
194
+ } catch (ex) {
195
+ return this.fire("tileerror", {
196
+ error: "Could not copy tile pixels: " + ex,
197
+ tile: tile,
198
+ coods: tile.coords,
199
+ });
200
+ }
201
+
202
+ // If dumping the pixels was successful, then hide the tile.
203
+ // Do not remove the tile itself, as it is needed to check if the whole
204
+ // level (and its canvas) should be removed (via level.el.children.length)
205
+ tile.el.style.display = "none";
206
+ },
207
+
208
+ // @section Extension methods
209
+ // @uninheritable
210
+
211
+ // @method dumpPixels(coords: Object, imageSource: CanvasImageSource): this
212
+ // Dumps pixels from the given `CanvasImageSource` into the layer, into
213
+ // the space for the tile represented by the `coords` tile coordinates (an object
214
+ // like `{x: Number, y: Number, z: Number}`; the image source must have the
215
+ // same size as the `tileSize` option for the layer. Has no effect if `dumpToCanvas`
216
+ // is `false`.
217
+ dumpPixels: function(coords, imageSource) {
218
+ var level = this._levels[coords.z],
219
+ tileSize = this.getTileSize();
220
+
221
+ if (!level.canvasRange || !this.options.dumpToCanvas) {
222
+ return;
223
+ }
224
+
225
+ // Check if the tile is inside the currently visible map bounds
226
+ // There is a possible race condition when tiles are loaded after they
227
+ // have been panned outside of the map.
228
+ if (!level.canvasRange.contains(coords)) {
229
+ this._resetCanvasSize(level);
230
+ }
231
+
232
+ // Where in the canvas should this tile go?
233
+ var offset = L.point(coords.x, coords.y)
234
+ .subtract(level.canvasRange.min)
235
+ .scaleBy(this.getTileSize());
236
+
237
+ level.ctx.drawImage(imageSource, offset.x, offset.y, tileSize.x, tileSize.y);
238
+
239
+ // TODO: Clear the pixels of other levels' canvases where they overlap
240
+ // this newly dumped tile.
241
+ return this;
242
+ },
243
+ });
@@ -0,0 +1,272 @@
1
+ (function (factory) {
2
+ var L, proj4;
3
+ if (typeof define === 'function' && define.amd) {
4
+ // AMD
5
+ define(['leaflet', 'proj4'], factory);
6
+ } else if (typeof module === 'object' && typeof module.exports === "object") {
7
+ // Node/CommonJS
8
+ L = require('leaflet');
9
+ proj4 = require('proj4');
10
+ module.exports = factory(L, proj4);
11
+ } else {
12
+ // Browser globals
13
+ if (typeof window.L === 'undefined' || typeof window.proj4 === 'undefined')
14
+ throw 'Leaflet and proj4 must be loaded first';
15
+ factory(window.L, window.proj4);
16
+ }
17
+ }(function (L, proj4) {
18
+ if (proj4.__esModule && proj4.default) {
19
+ // If proj4 was bundled as an ES6 module, unwrap it to get
20
+ // to the actual main proj4 object.
21
+ // See discussion in https://github.com/kartena/Proj4Leaflet/pull/147
22
+ proj4 = proj4.default;
23
+ }
24
+
25
+ L.Proj = {};
26
+
27
+ L.Proj._isProj4Obj = function(a) {
28
+ return (typeof a.inverse !== 'undefined' &&
29
+ typeof a.forward !== 'undefined');
30
+ };
31
+
32
+ L.Proj.Projection = L.Class.extend({
33
+ initialize: function(code, def, bounds) {
34
+ var isP4 = L.Proj._isProj4Obj(code);
35
+ this._proj = isP4 ? code : this._projFromCodeDef(code, def);
36
+ this.bounds = isP4 ? def : bounds;
37
+ },
38
+
39
+ project: function (latlng) {
40
+ var point = this._proj.forward([latlng.lng, latlng.lat]);
41
+ return new L.Point(point[0], point[1]);
42
+ },
43
+
44
+ unproject: function (point, unbounded) {
45
+ var point2 = this._proj.inverse([point.x, point.y]);
46
+ return new L.LatLng(point2[1], point2[0], unbounded);
47
+ },
48
+
49
+ _projFromCodeDef: function(code, def) {
50
+ if (def) {
51
+ proj4.defs(code, def);
52
+ } else if (proj4.defs[code] === undefined) {
53
+ var urn = code.split(':');
54
+ if (urn.length > 3) {
55
+ code = urn[urn.length - 3] + ':' + urn[urn.length - 1];
56
+ }
57
+ if (proj4.defs[code] === undefined) {
58
+ throw 'No projection definition for code ' + code;
59
+ }
60
+ }
61
+
62
+ return proj4(code);
63
+ }
64
+ });
65
+
66
+ L.Proj.CRS = L.Class.extend({
67
+ includes: L.CRS,
68
+
69
+ options: {
70
+ transformation: new L.Transformation(1, 0, -1, 0)
71
+ },
72
+
73
+ initialize: function(a, b, c) {
74
+ var code,
75
+ proj,
76
+ def,
77
+ options;
78
+
79
+ if (L.Proj._isProj4Obj(a)) {
80
+ proj = a;
81
+ code = proj.srsCode;
82
+ options = b || {};
83
+
84
+ this.projection = new L.Proj.Projection(proj, options.bounds);
85
+ } else {
86
+ code = a;
87
+ def = b;
88
+ options = c || {};
89
+ this.projection = new L.Proj.Projection(code, def, options.bounds);
90
+ }
91
+
92
+ L.Util.setOptions(this, options);
93
+ this.code = code;
94
+ this.transformation = this.options.transformation;
95
+
96
+ if (this.options.origin) {
97
+ this.transformation =
98
+ new L.Transformation(1, -this.options.origin[0],
99
+ -1, this.options.origin[1]);
100
+ }
101
+
102
+ if (this.options.scales) {
103
+ this._scales = this.options.scales;
104
+ } else if (this.options.resolutions) {
105
+ this._scales = [];
106
+ for (var i = this.options.resolutions.length - 1; i >= 0; i--) {
107
+ if (this.options.resolutions[i]) {
108
+ this._scales[i] = 1 / this.options.resolutions[i];
109
+ }
110
+ }
111
+ }
112
+
113
+ this.infinite = !this.options.bounds;
114
+
115
+ },
116
+
117
+ scale: function(zoom) {
118
+ var iZoom = Math.floor(zoom),
119
+ baseScale,
120
+ nextScale,
121
+ scaleDiff,
122
+ zDiff;
123
+ if (zoom === iZoom) {
124
+ return this._scales[zoom];
125
+ } else {
126
+ // Non-integer zoom, interpolate
127
+ baseScale = this._scales[iZoom];
128
+ nextScale = this._scales[iZoom + 1];
129
+ scaleDiff = nextScale - baseScale;
130
+ zDiff = (zoom - iZoom);
131
+ return baseScale + scaleDiff * zDiff;
132
+ }
133
+ },
134
+
135
+ zoom: function(scale) {
136
+ // Find closest number in this._scales, down
137
+ var downScale = this._closestElement(this._scales, scale),
138
+ downZoom = this._scales.indexOf(downScale),
139
+ nextScale,
140
+ nextZoom,
141
+ scaleDiff;
142
+ // Check if scale is downScale => return array index
143
+ if (scale === downScale) {
144
+ return downZoom;
145
+ }
146
+ if (downScale === undefined) {
147
+ return -Infinity;
148
+ }
149
+ // Interpolate
150
+ nextZoom = downZoom + 1;
151
+ nextScale = this._scales[nextZoom];
152
+ if (nextScale === undefined) {
153
+ return Infinity;
154
+ }
155
+ scaleDiff = nextScale - downScale;
156
+ return (scale - downScale) / scaleDiff + downZoom;
157
+ },
158
+
159
+ distance: L.CRS.Earth.distance,
160
+
161
+ R: L.CRS.Earth.R,
162
+
163
+ /* Get the closest lowest element in an array */
164
+ _closestElement: function(array, element) {
165
+ var low;
166
+ for (var i = array.length; i--;) {
167
+ if (array[i] <= element && (low === undefined || low < array[i])) {
168
+ low = array[i];
169
+ }
170
+ }
171
+ return low;
172
+ }
173
+ });
174
+
175
+ L.Proj.GeoJSON = L.GeoJSON.extend({
176
+ initialize: function(geojson, options) {
177
+ this._callLevel = 0;
178
+ L.GeoJSON.prototype.initialize.call(this, geojson, options);
179
+ },
180
+
181
+ addData: function(geojson) {
182
+ var crs;
183
+
184
+ if (geojson) {
185
+ if (geojson.crs && geojson.crs.type === 'name') {
186
+ crs = new L.Proj.CRS(geojson.crs.properties.name);
187
+ } else if (geojson.crs && geojson.crs.type) {
188
+ crs = new L.Proj.CRS(geojson.crs.type + ':' + geojson.crs.properties.code);
189
+ }
190
+
191
+ if (crs !== undefined) {
192
+ this.options.coordsToLatLng = function(coords) {
193
+ var point = L.point(coords[0], coords[1]);
194
+ return crs.projection.unproject(point);
195
+ };
196
+ }
197
+ }
198
+
199
+ // Base class' addData might call us recursively, but
200
+ // CRS shouldn't be cleared in that case, since CRS applies
201
+ // to the whole GeoJSON, inluding sub-features.
202
+ this._callLevel++;
203
+ try {
204
+ L.GeoJSON.prototype.addData.call(this, geojson);
205
+ } finally {
206
+ this._callLevel--;
207
+ if (this._callLevel === 0) {
208
+ delete this.options.coordsToLatLng;
209
+ }
210
+ }
211
+ }
212
+ });
213
+
214
+ L.Proj.geoJson = function(geojson, options) {
215
+ return new L.Proj.GeoJSON(geojson, options);
216
+ };
217
+
218
+ L.Proj.ImageOverlay = L.ImageOverlay.extend({
219
+ initialize: function (url, bounds, options) {
220
+ L.ImageOverlay.prototype.initialize.call(this, url, null, options);
221
+ this._projectedBounds = bounds;
222
+ },
223
+
224
+ // Danger ahead: Overriding internal methods in Leaflet.
225
+ // Decided to do this rather than making a copy of L.ImageOverlay
226
+ // and doing very tiny modifications to it.
227
+ // Future will tell if this was wise or not.
228
+ _animateZoom: function (event) {
229
+ var scale = this._map.getZoomScale(event.zoom);
230
+ var northWest = L.point(this._projectedBounds.min.x, this._projectedBounds.max.y);
231
+ var offset = this._projectedToNewLayerPoint(northWest, event.zoom, event.center);
232
+
233
+ L.DomUtil.setTransform(this._image, offset, scale);
234
+ },
235
+
236
+ _reset: function () {
237
+ var zoom = this._map.getZoom();
238
+ var pixelOrigin = this._map.getPixelOrigin();
239
+ var bounds = L.bounds(
240
+ this._transform(this._projectedBounds.min, zoom)._subtract(pixelOrigin),
241
+ this._transform(this._projectedBounds.max, zoom)._subtract(pixelOrigin)
242
+ );
243
+ var size = bounds.getSize();
244
+
245
+ L.DomUtil.setPosition(this._image, bounds.min);
246
+ this._image.style.width = size.x + 'px';
247
+ this._image.style.height = size.y + 'px';
248
+ },
249
+
250
+ _projectedToNewLayerPoint: function (point, zoom, center) {
251
+ var viewHalf = this._map.getSize()._divideBy(2);
252
+ var newTopLeft = this._map.project(center, zoom)._subtract(viewHalf)._round();
253
+ var topLeft = newTopLeft.add(this._map._getMapPanePos());
254
+
255
+ return this._transform(point, zoom)._subtract(topLeft);
256
+ },
257
+
258
+ _transform: function (point, zoom) {
259
+ var crs = this._map.options.crs;
260
+ var transformation = crs.transformation;
261
+ var scale = crs.scale(zoom);
262
+
263
+ return transformation.transform(point, scale);
264
+ }
265
+ });
266
+
267
+ L.Proj.imageOverlay = function (url, bounds, options) {
268
+ return new L.Proj.ImageOverlay(url, bounds, options);
269
+ };
270
+
271
+ return L.Proj;
272
+ }));