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.
- cone/maps/__init__.py +64 -0
- cone/maps/browser/__init__.py +4 -0
- cone/maps/browser/map.py +139 -0
- cone/maps/browser/static/cone.maps.js +109 -0
- cone/maps/browser/static/cone.maps.min.js +1 -0
- cone/maps/browser/static/leaflet/images/layers-2x.png +0 -0
- cone/maps/browser/static/leaflet/images/layers.png +0 -0
- cone/maps/browser/static/leaflet/images/marker-icon-2x.png +0 -0
- cone/maps/browser/static/leaflet/images/marker-icon.png +0 -0
- cone/maps/browser/static/leaflet/images/marker-shadow.png +0 -0
- cone/maps/browser/static/leaflet/leaflet-src.js +14062 -0
- cone/maps/browser/static/leaflet/leaflet-src.js.map +1 -0
- cone/maps/browser/static/leaflet/leaflet.css +640 -0
- cone/maps/browser/static/leaflet/leaflet.js +6 -0
- cone/maps/browser/static/leaflet/leaflet.js.map +1 -0
- cone/maps/browser/static/leaflet-activearea/leaflet.activearea.js +458 -0
- cone/maps/browser/static/leaflet-geosearch/geosearch.css +240 -0
- cone/maps/browser/static/leaflet-geosearch/geosearch.umd.js +2 -0
- cone/maps/browser/static/leaflet-geosearch/geosearch.umd.js.map +1 -0
- cone/maps/browser/static/leaflet-markercluster/MarkerCluster.Default.css +60 -0
- cone/maps/browser/static/leaflet-markercluster/MarkerCluster.css +14 -0
- cone/maps/browser/static/leaflet-markercluster/leaflet.markercluster-src.js +2718 -0
- cone/maps/browser/static/leaflet-markercluster/leaflet.markercluster-src.js.map +1 -0
- cone/maps/browser/static/leaflet-markercluster/leaflet.markercluster.js +2 -0
- cone/maps/browser/static/leaflet-markercluster/leaflet.markercluster.js.map +1 -0
- cone/maps/browser/static/leaflet-nogap/L.TileLayer.NoGap.js +243 -0
- cone/maps/browser/static/leaflet-proj4/proj4leaflet.js +272 -0
- cone/maps/browser/static/proj4js/proj4-src.js +7174 -0
- cone/maps/browser/static/proj4js/proj4.js +1 -0
- cone/maps/locale/cone.maps.pot +0 -0
- cone/maps/tests.py +54 -0
- cone.maps-0.2-py3.9-nspkg.pth +1 -0
- cone_maps-0.2.dist-info/METADATA +179 -0
- cone_maps-0.2.dist-info/RECORD +39 -0
- cone_maps-0.2.dist-info/WHEEL +5 -0
- cone_maps-0.2.dist-info/licenses/LICENSE.rst +26 -0
- cone_maps-0.2.dist-info/licenses/LICENSE_LEAFLET.rst +23 -0
- cone_maps-0.2.dist-info/namespace_packages.txt +1 -0
- cone_maps-0.2.dist-info/top_level.txt +1 -0
cone/maps/__init__.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from cone.app import cfg
|
|
2
|
+
from cone.app import main_hook
|
|
3
|
+
from cone.maps.browser import static_resources
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger('cone.maps')
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@main_hook
|
|
11
|
+
def initialize_maps(config, global_config, settings):
|
|
12
|
+
# application startup initialization
|
|
13
|
+
|
|
14
|
+
# ignore yafowil leaflet dependencies if cone.maps is installed
|
|
15
|
+
cfg.yafowil.js_skip.add('yafowil.widget.location.dependencies')
|
|
16
|
+
cfg.yafowil.css_skip.add('yafowil.widget.location.dependencies')
|
|
17
|
+
|
|
18
|
+
# resources
|
|
19
|
+
if settings.get('cone.maps.public', 'false') == 'true':
|
|
20
|
+
css_res = cfg.css.public
|
|
21
|
+
js_res = cfg.js.public
|
|
22
|
+
else:
|
|
23
|
+
css_res = cfg.css.protected
|
|
24
|
+
js_res = cfg.js.protected
|
|
25
|
+
|
|
26
|
+
# leaflet core
|
|
27
|
+
css_res.append('maps-static/leaflet/leaflet.css')
|
|
28
|
+
js_res.append('maps-static/leaflet/leaflet.js')
|
|
29
|
+
|
|
30
|
+
# Leaflet.TileLayer.NoGap
|
|
31
|
+
if settings.get('cone.maps.nogap', 'false') == 'true':
|
|
32
|
+
js_res.append('maps-static/leaflet-nogap/L.TileLayer.NoGap.js')
|
|
33
|
+
|
|
34
|
+
# leaflet-geosearch
|
|
35
|
+
if settings.get('cone.maps.geosearch', 'false') == 'true':
|
|
36
|
+
css_res.append('maps-static/leaflet-geosearch/geosearch.css')
|
|
37
|
+
js_res.append('maps-static/leaflet-geosearch/geosearch.umd.js')
|
|
38
|
+
|
|
39
|
+
# Leaflet.markercluster
|
|
40
|
+
if settings.get('cone.maps.markercluster', 'false') == 'true':
|
|
41
|
+
css_res.append('maps-static/leaflet-markercluster/MarkerCluster.css')
|
|
42
|
+
css_res.append('maps-static/leaflet-markercluster/MarkerCluster.Default.css')
|
|
43
|
+
js_res.append('maps-static/leaflet-markercluster/leaflet.markercluster.js')
|
|
44
|
+
|
|
45
|
+
# Leaflet-active-area
|
|
46
|
+
if settings.get('cone.maps.activearea', 'false') == 'true':
|
|
47
|
+
js_res.append('maps-static/leaflet-activearea/leaflet.activearea.js')
|
|
48
|
+
|
|
49
|
+
# proj4js and Proj4Leaflet
|
|
50
|
+
if settings.get('cone.maps.proj4', 'false') == 'true':
|
|
51
|
+
js_res.append('maps-static/proj4js/proj4.js')
|
|
52
|
+
js_res.append('maps-static/leaflet-proj4/proj4leaflet.js')
|
|
53
|
+
|
|
54
|
+
# cone maps
|
|
55
|
+
js_res.append('maps-static/cone.maps.js')
|
|
56
|
+
|
|
57
|
+
# add translation
|
|
58
|
+
config.add_translation_dirs('cone.maps:locale/')
|
|
59
|
+
|
|
60
|
+
# static resources
|
|
61
|
+
config.add_view(static_resources, name='maps-static')
|
|
62
|
+
|
|
63
|
+
# scan browser package
|
|
64
|
+
config.scan('cone.maps.browser')
|
cone/maps/browser/map.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
from cone.tile import Tile
|
|
2
|
+
import json
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class MapTile(Tile):
|
|
6
|
+
"""Tile rendering a leaflet map.
|
|
7
|
+
|
|
8
|
+
Reference: https://leafletjs.com/reference.html
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
map_factory = 'cone_maps.Map'
|
|
12
|
+
"""Factory used for map creation in Javascript.
|
|
13
|
+
|
|
14
|
+
The definded factory must accept the map related DOM element as argument
|
|
15
|
+
and is responsible to initialize the leaflet map.
|
|
16
|
+
|
|
17
|
+
It points to a class or function and does property lookup on window with
|
|
18
|
+
'.' as delimiter, e.g:
|
|
19
|
+
|
|
20
|
+
'cone_maps.Map'
|
|
21
|
+
|
|
22
|
+
corresponds to:
|
|
23
|
+
|
|
24
|
+
cone_maps: {
|
|
25
|
+
Map: {}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
If JS map factory needs to be customized, this is usually done by subclassing
|
|
29
|
+
'cone_maps.Map':
|
|
30
|
+
|
|
31
|
+
my_namespace = {};
|
|
32
|
+
|
|
33
|
+
my_namespace.Map = class extends cone_maps.Map {
|
|
34
|
+
constructor(elem) {
|
|
35
|
+
elem.height(800);
|
|
36
|
+
super(elem);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
map_id = 'map'
|
|
42
|
+
"""HTML id of the map.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
map_css = 'cone-map'
|
|
46
|
+
"""CSS class of the map element.
|
|
47
|
+
|
|
48
|
+
The default JS map implementation searches for
|
|
49
|
+
for all `div` elements with `cone-map` CSS class set and initializes map
|
|
50
|
+
instances for them.
|
|
51
|
+
|
|
52
|
+
If it's desired to completly customize map instancing on client side, this
|
|
53
|
+
property must be changed.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
map_options = {}
|
|
57
|
+
"""Map options passed to the leaflet map constructor.
|
|
58
|
+
|
|
59
|
+
See: https://leafletjs.com/reference.html#map-l-map
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
map_control_options = {}
|
|
63
|
+
"""Layers control options passed to the leaflet layers control constructor.
|
|
64
|
+
|
|
65
|
+
See: https://leafletjs.com/reference.html#control-layers
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
map_layers = [{
|
|
69
|
+
# general layer options
|
|
70
|
+
'factory': 'tile_layer', # layer factory
|
|
71
|
+
'category': 'base', # base|overlay
|
|
72
|
+
'display': True, # initial display
|
|
73
|
+
'title': 'OpenStreetMap', # layer title
|
|
74
|
+
# factory specific layer options
|
|
75
|
+
'urlTemplate': '//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
|
76
|
+
'options': {
|
|
77
|
+
'attribution': 'OSM map data © <a href="http://openstreetmap.org">OSM</a>',
|
|
78
|
+
'minZoom': 2,
|
|
79
|
+
'maxZoom': 18
|
|
80
|
+
}
|
|
81
|
+
}]
|
|
82
|
+
"""List of map layer definitions.
|
|
83
|
+
|
|
84
|
+
See: https://leafletjs.com/reference.html
|
|
85
|
+
"""
|
|
86
|
+
|
|
87
|
+
map_center = [47.2688805, 11.3929127]
|
|
88
|
+
"""The default (initial) center of the map as lat/lng.
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
map_zoom = 8
|
|
92
|
+
"""The default (initial) zoom level of the map
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
map_markers = []
|
|
96
|
+
"""List of map markers to display.
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
map_markers_source = None
|
|
100
|
+
"""JSON endpoint to fetch markers from.
|
|
101
|
+
"""
|
|
102
|
+
|
|
103
|
+
map_marker_groups = []
|
|
104
|
+
"""List of map marker groups to display.
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
map_marker_groups_source = None
|
|
108
|
+
"""JSON endpoint to fetch marker groups from.
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
def render(self):
|
|
112
|
+
return (
|
|
113
|
+
u'<div class="{css}"'
|
|
114
|
+
u' id="{id}"'
|
|
115
|
+
u' data-map-factory="{factory}"'
|
|
116
|
+
u' data-map-options=\'{options}\''
|
|
117
|
+
u' data-map-control-options=\'{control_options}\''
|
|
118
|
+
u' data-map-layers=\'{layers}\''
|
|
119
|
+
u' data-map-center=\'{center}\''
|
|
120
|
+
u' data-map-zoom="{zoom}"'
|
|
121
|
+
u' data-map-markers=\'{markers}\''
|
|
122
|
+
u' data-map-markers-source="{markers_source}"'
|
|
123
|
+
u' data-map-groups=\'{marker_groups}\''
|
|
124
|
+
u' data-map-groups-source="{marker_groups_source}" >'
|
|
125
|
+
u'</div>'
|
|
126
|
+
).format(
|
|
127
|
+
css=self.map_css,
|
|
128
|
+
id=self.map_id,
|
|
129
|
+
factory=self.map_factory,
|
|
130
|
+
options=json.dumps(self.map_options),
|
|
131
|
+
control_options=json.dumps(self.map_control_options),
|
|
132
|
+
layers=json.dumps(self.map_layers),
|
|
133
|
+
center=json.dumps(self.map_center),
|
|
134
|
+
zoom=self.map_zoom,
|
|
135
|
+
markers=self.map_markers,
|
|
136
|
+
markers_source=self.map_markers_source,
|
|
137
|
+
marker_groups=self.map_marker_groups,
|
|
138
|
+
marker_groups_source=self.map_marker_groups_source,
|
|
139
|
+
)
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
(function (exports, $) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
function lookup_factory(name) {
|
|
5
|
+
let ob = window;
|
|
6
|
+
for (let part of name.split('.')) {
|
|
7
|
+
ob = ob[part];
|
|
8
|
+
if (ob === undefined) {
|
|
9
|
+
throw "Cannot locate map factory: " + name;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return ob;
|
|
13
|
+
}
|
|
14
|
+
let layer_factories = {};
|
|
15
|
+
layer_factories.tile_layer = function(inst, cfg) {
|
|
16
|
+
inst.layer_created(new L.TileLayer(cfg.urlTemplate, cfg.options), cfg);
|
|
17
|
+
};
|
|
18
|
+
layer_factories.geo_json = function(inst, cfg) {
|
|
19
|
+
$.getJSON(cfg.dataUrl, function(data) {
|
|
20
|
+
inst.layer_created(new L.GeoJSON(data, cfg.options), cfg);
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
class Map {
|
|
24
|
+
static initialize(context) {
|
|
25
|
+
$('div.cone-map', context).each(function() {
|
|
26
|
+
let elem = $(this);
|
|
27
|
+
let factory = lookup_factory(elem.data('map-factory'));
|
|
28
|
+
new factory(elem);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
constructor(elem) {
|
|
32
|
+
this.elem = elem;
|
|
33
|
+
this.id = elem.attr('id');
|
|
34
|
+
this.layers = elem.data('map-layers');
|
|
35
|
+
this.default_center = elem.data('map-center');
|
|
36
|
+
this.default_zoom = elem.data('map-zoom');
|
|
37
|
+
this.map_options = elem.data('map-options');
|
|
38
|
+
this.control_options = elem.data('map-control-options');
|
|
39
|
+
this.markers = elem.data('data-map-markers');
|
|
40
|
+
this.markers_source = elem.data('data-map-markers-source');
|
|
41
|
+
this.marker_groups = elem.data('data-map-groups');
|
|
42
|
+
this.marker_groups_source = elem.data('data-map-groups-source');
|
|
43
|
+
this.create();
|
|
44
|
+
elem.data('map-instance', this);
|
|
45
|
+
}
|
|
46
|
+
create() {
|
|
47
|
+
this.create_map();
|
|
48
|
+
this.create_controls();
|
|
49
|
+
this.create_layers();
|
|
50
|
+
}
|
|
51
|
+
create_map() {
|
|
52
|
+
this.map = new L.Map(this.id, this.map_options);
|
|
53
|
+
this.map.setView(this.default_center, this.default_zoom);
|
|
54
|
+
}
|
|
55
|
+
create_controls() {
|
|
56
|
+
let base_maps = [],
|
|
57
|
+
overlay_maps = [];
|
|
58
|
+
this.map_layers = new L.control.Layers(
|
|
59
|
+
base_maps,
|
|
60
|
+
overlay_maps,
|
|
61
|
+
this.control_options
|
|
62
|
+
);
|
|
63
|
+
this.map_layers.addTo(this.map);
|
|
64
|
+
}
|
|
65
|
+
create_layers() {
|
|
66
|
+
for (let l of this.layers) {
|
|
67
|
+
layer_factories[l.factory](this, l);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
layer_created(layer, cfg) {
|
|
71
|
+
cfg.layer = layer;
|
|
72
|
+
if (cfg.display === undefined || cfg.display) {
|
|
73
|
+
this.add_layer(layer);
|
|
74
|
+
}
|
|
75
|
+
if (cfg.category === 'base') {
|
|
76
|
+
this.map_layers.addBaseLayer(layer, cfg.title);
|
|
77
|
+
} else if (cfg.category === 'overlay') {
|
|
78
|
+
this.map_layers.addOverlay(layer, cfg.title);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
add_layer(layer) {
|
|
82
|
+
this.map.addLayer(layer);
|
|
83
|
+
}
|
|
84
|
+
remove_layer(layer) {
|
|
85
|
+
this.map.removeLayer(layer);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
$(function() {
|
|
90
|
+
if (window.ts !== undefined) {
|
|
91
|
+
ts.ajax.register(Map.initialize, true);
|
|
92
|
+
} else {
|
|
93
|
+
bdajax.register(Map.initialize, true);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
exports.Map = Map;
|
|
98
|
+
exports.layer_factories = layer_factories;
|
|
99
|
+
exports.lookup_factory = lookup_factory;
|
|
100
|
+
|
|
101
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
window.cone_maps = exports;
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
return exports;
|
|
108
|
+
|
|
109
|
+
})({}, jQuery);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(a,t){"use strict";function e(a){let t=window;for(let e of a.split("."))if(t=t[e],void 0===t)throw"Cannot locate map factory: "+a;return t}let r={tile_layer:function(a,t){a.layer_created(new L.TileLayer(t.urlTemplate,t.options),t)},geo_json:function(a,e){t.getJSON(e.dataUrl,(function(t){a.layer_created(new L.GeoJSON(t,e.options),e)}))}};class i{static initialize(a){t("div.cone-map",a).each((function(){let a=t(this);new(e(a.data("map-factory")))(a)}))}constructor(a){this.elem=a,this.id=a.attr("id"),this.layers=a.data("map-layers"),this.default_center=a.data("map-center"),this.default_zoom=a.data("map-zoom"),this.map_options=a.data("map-options"),this.control_options=a.data("map-control-options"),this.markers=a.data("data-map-markers"),this.markers_source=a.data("data-map-markers-source"),this.marker_groups=a.data("data-map-groups"),this.marker_groups_source=a.data("data-map-groups-source"),this.create(),a.data("map-instance",this)}create(){this.create_map(),this.create_controls(),this.create_layers()}create_map(){this.map=new L.Map(this.id,this.map_options),this.map.setView(this.default_center,this.default_zoom)}create_controls(){this.map_layers=new L.control.Layers([],[],this.control_options),this.map_layers.addTo(this.map)}create_layers(){for(let a of this.layers)r[a.factory](this,a)}layer_created(a,t){t.layer=a,(void 0===t.display||t.display)&&this.add_layer(a),"base"===t.category?this.map_layers.addBaseLayer(a,t.title):"overlay"===t.category&&this.map_layers.addOverlay(a,t.title)}add_layer(a){this.map.addLayer(a)}remove_layer(a){this.map.removeLayer(a)}}t((function(){void 0!==window.ts?ts.ajax.register(i.initialize,!0):bdajax.register(i.initialize,!0)})),a.Map=i,a.layer_factories=r,a.lookup_factory=e,Object.defineProperty(a,"__esModule",{value:!0}),window.cone_maps=a}({},jQuery);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|