leaflet marker theming
This commit is contained in:
parent
1f1a0711c6
commit
2f82dd981d
8 changed files with 67 additions and 21 deletions
|
@ -436,6 +436,7 @@ def create_editor_form(editor_model):
|
||||||
'color_css_header_text', 'color_css_header_text_hover',
|
'color_css_header_text', 'color_css_header_text_hover',
|
||||||
'color_css_shadow', 'color_css_overlay_background', 'color_css_grid',
|
'color_css_shadow', 'color_css_overlay_background', 'color_css_grid',
|
||||||
'color_css_modal_backdrop', 'color_css_route_dots_shadow', 'extra_css',
|
'color_css_modal_backdrop', 'color_css_route_dots_shadow', 'extra_css',
|
||||||
|
'icon_path', 'leaflet_marker_config',
|
||||||
'color_background', 'color_wall_fill', 'color_wall_border', 'color_door_fill',
|
'color_background', 'color_wall_fill', 'color_wall_border', 'color_door_fill',
|
||||||
'color_ground_fill', 'color_obstacles_default_fill', 'color_obstacles_default_border',
|
'color_ground_fill', 'color_obstacles_default_fill', 'color_obstacles_default_border',
|
||||||
]
|
]
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 5.0.8 on 2024-09-17 17:30
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('mapdata', '0109_accesspermissionssogrant_accesspermission_sso_grant'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='theme',
|
||||||
|
name='icon_path',
|
||||||
|
field=models.CharField(blank=True, default='', max_length=255, verbose_name='Root path for icon images'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='theme',
|
||||||
|
name='leaflet_marker_config',
|
||||||
|
field=models.TextField(blank=True, default='', verbose_name='Leaflet marker config override'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -45,6 +45,9 @@ class Theme(TitledMixin, models.Model):
|
||||||
verbose_name=_('CSS route dots shadow color'))
|
verbose_name=_('CSS route dots shadow color'))
|
||||||
extra_css = models.TextField(default='', blank=True, verbose_name=_('Extra CSS'))
|
extra_css = models.TextField(default='', blank=True, verbose_name=_('Extra CSS'))
|
||||||
|
|
||||||
|
icon_path = models.CharField(default='', blank=True, max_length=255, verbose_name=_('Root path for icon images'))
|
||||||
|
leaflet_marker_config = models.TextField(default='', blank=True, verbose_name=_('Leaflet marker config override'))
|
||||||
|
|
||||||
color_background = models.CharField(max_length=32, blank=True, verbose_name=_('background color'))
|
color_background = models.CharField(max_length=32, blank=True, verbose_name=_('background color'))
|
||||||
color_wall_fill = models.CharField(max_length=32, blank=True, verbose_name=_('wall fill color'))
|
color_wall_fill = models.CharField(max_length=32, blank=True, verbose_name=_('wall fill color'))
|
||||||
color_wall_border = models.CharField(max_length=32, blank=True, verbose_name=_('wall border color'))
|
color_wall_border = models.CharField(max_length=32, blank=True, verbose_name=_('wall border color'))
|
||||||
|
|
|
@ -1346,7 +1346,7 @@ c3nav = {
|
||||||
_modal_link_click: function (e) {
|
_modal_link_click: function (e) {
|
||||||
var location = $(this).attr('href');
|
var location = $(this).attr('href');
|
||||||
if ($(this).is('[target]') || c3nav._href_modal_open_tab(location)) {
|
if ($(this).is('[target]') || c3nav._href_modal_open_tab(location)) {
|
||||||
if(!$(this).is('[target]')) $(this).attr('target', '_blank');
|
if (!$(this).is('[target]')) $(this).attr('target', '_blank');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -1436,9 +1436,7 @@ c3nav = {
|
||||||
|
|
||||||
// set up icons
|
// set up icons
|
||||||
L.Icon.Default.imagePath = '/static/leaflet/images/';
|
L.Icon.Default.imagePath = '/static/leaflet/images/';
|
||||||
c3nav._add_icon('origin');
|
c3nav.create_icons();
|
||||||
c3nav._add_icon('destination');
|
|
||||||
c3nav._add_icon('nearby');
|
|
||||||
|
|
||||||
// setup scale control
|
// setup scale control
|
||||||
L.control.scale({imperial: false}).addTo(c3nav.map);
|
L.control.scale({imperial: false}).addTo(c3nav.map);
|
||||||
|
@ -1502,6 +1500,8 @@ c3nav = {
|
||||||
document.querySelector('#theme-color-meta-dark').content = theme.theme_color_dark;
|
document.querySelector('#theme-color-meta-dark').content = theme.theme_color_dark;
|
||||||
document.querySelector('#theme-color-meta-light').content = theme.theme_color_light;
|
document.querySelector('#theme-color-meta-light').content = theme.theme_color_light;
|
||||||
|
|
||||||
|
c3nav.create_icons();
|
||||||
|
|
||||||
c3nav._levelControl.setTheme(id);
|
c3nav._levelControl.setTheme(id);
|
||||||
c3nav.create_key(id);
|
c3nav.create_key(id);
|
||||||
},
|
},
|
||||||
|
@ -1601,17 +1601,32 @@ c3nav = {
|
||||||
c3nav.update_map_state();
|
c3nav.update_map_state();
|
||||||
c3nav.update_location_labels();
|
c3nav.update_location_labels();
|
||||||
},
|
},
|
||||||
_add_icon: function (name) {
|
icons: {},
|
||||||
c3nav[name + 'Icon'] = new L.Icon({
|
create_icons: function () {
|
||||||
iconUrl: '/static/img/marker-icon-' + name + '.png',
|
const theme = c3nav.themes[c3nav.theme];
|
||||||
iconRetinaUrl: '/static/img/marker-icon-' + name + '-2x.png',
|
let rootPath = theme.icon_path;
|
||||||
shadowUrl: '/static/leaflet/images/marker-shadow.png',
|
let config = theme.marker_config ? JSON.parse(theme.marker_config) : null;
|
||||||
iconSize: [25, 41],
|
if (!rootPath) {
|
||||||
iconAnchor: [12, 41],
|
rootPath = '/static/img/';
|
||||||
popupAnchor: [1, -34],
|
}
|
||||||
tooltipAnchor: [16, -28],
|
if (!config) {
|
||||||
shadowSize: [41, 41]
|
config = {};
|
||||||
});
|
}
|
||||||
|
c3nav.icons = {};
|
||||||
|
for (const name of ['default', 'origin', 'destination', 'nearby']) {
|
||||||
|
c3nav.icons[name] = new L.Icon({
|
||||||
|
iconUrl: rootPath + 'marker-icon-' + name + '.png',
|
||||||
|
iconRetinaUrl: rootPath + 'marker-icon-' + name + '-2x.png',
|
||||||
|
shadowUrl: rootPath + 'marker-shadow.png',
|
||||||
|
iconSize: [25, 41],
|
||||||
|
iconAnchor: [12, 41],
|
||||||
|
popupAnchor: [1, -34],
|
||||||
|
tooltipAnchor: [16, -28],
|
||||||
|
shadowSize: [41, 41],
|
||||||
|
...config,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
visible_map_locations: [],
|
visible_map_locations: [],
|
||||||
update_map_locations: function () {
|
update_map_locations: function () {
|
||||||
|
@ -1624,24 +1639,24 @@ c3nav = {
|
||||||
c3nav._locationLayers[level_id].clearLayers()
|
c3nav._locationLayers[level_id].clearLayers()
|
||||||
}
|
}
|
||||||
c3nav._visible_map_locations = [];
|
c3nav._visible_map_locations = [];
|
||||||
if (origin) c3nav._merge_bounds(bounds, c3nav._add_location_to_map(origin, single ? new L.Icon.Default() : c3nav.originIcon));
|
if (origin) c3nav._merge_bounds(bounds, c3nav._add_location_to_map(origin, single ? c3nav.icons.default : c3nav.icons.origin));
|
||||||
if (destination) c3nav._merge_bounds(bounds, c3nav._add_location_to_map(destination, single ? new L.Icon.Default() : c3nav.destinationIcon));
|
if (destination) c3nav._merge_bounds(bounds, c3nav._add_location_to_map(destination, single ? c3nav.icons.default : c3nav.icons.destination));
|
||||||
var done = [];
|
var done = [];
|
||||||
if (c3nav.state.nearby && destination && 'areas' in destination) {
|
if (c3nav.state.nearby && destination && 'areas' in destination) {
|
||||||
if (destination.space) {
|
if (destination.space) {
|
||||||
c3nav._merge_bounds(bounds, c3nav._add_location_to_map(c3nav.locations_by_id[destination.space], c3nav.nearbyIcon, true));
|
c3nav._merge_bounds(bounds, c3nav._add_location_to_map(c3nav.locations_by_id[destination.space], c3nav.icons.nearby, true));
|
||||||
}
|
}
|
||||||
if (destination.near_area) {
|
if (destination.near_area) {
|
||||||
done.push(destination.near_area);
|
done.push(destination.near_area);
|
||||||
c3nav._merge_bounds(bounds, c3nav._add_location_to_map(c3nav.locations_by_id[destination.near_area], c3nav.nearbyIcon, true));
|
c3nav._merge_bounds(bounds, c3nav._add_location_to_map(c3nav.locations_by_id[destination.near_area], c3nav.icons.nearby, true));
|
||||||
}
|
}
|
||||||
for (var area of destination.areas) {
|
for (var area of destination.areas) {
|
||||||
done.push(area);
|
done.push(area);
|
||||||
c3nav._merge_bounds(bounds, c3nav._add_location_to_map(c3nav.locations_by_id[area], c3nav.nearbyIcon, true));
|
c3nav._merge_bounds(bounds, c3nav._add_location_to_map(c3nav.locations_by_id[area], c3nav.icons.nearby, true));
|
||||||
}
|
}
|
||||||
for (var location of destination.nearby) {
|
for (var location of destination.nearby) {
|
||||||
if (location in done) continue;
|
if (location in done) continue;
|
||||||
c3nav._merge_bounds(bounds, c3nav._add_location_to_map(c3nav.locations_by_id[location], c3nav.nearbyIcon, true));
|
c3nav._merge_bounds(bounds, c3nav._add_location_to_map(c3nav.locations_by_id[location], c3nav.icons.nearby, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c3nav._locationLayerBounds = bounds;
|
c3nav._locationLayerBounds = bounds;
|
||||||
|
|
|
@ -82,6 +82,10 @@ def make_themes(theme_models):
|
||||||
'randomize_primary_color': theme.randomize_primary_color,
|
'randomize_primary_color': theme.randomize_primary_color,
|
||||||
'primary_color': primary_color,
|
'primary_color': primary_color,
|
||||||
}
|
}
|
||||||
|
if theme.icon_path:
|
||||||
|
themes[theme.pk]['icon_path'] = theme.icon_path
|
||||||
|
if theme.leaflet_marker_config:
|
||||||
|
themes[theme.pk]['marker_config'] = theme.leaflet_marker_config
|
||||||
if theme.default:
|
if theme.default:
|
||||||
default_theme = {
|
default_theme = {
|
||||||
'css_vars': css_code,
|
'css_vars': css_code,
|
||||||
|
|
BIN
src/c3nav/static/img/marker-icon-default-2x.png
Normal file
BIN
src/c3nav/static/img/marker-icon-default-2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
BIN
src/c3nav/static/img/marker-icon-default.png
Normal file
BIN
src/c3nav/static/img/marker-icon-default.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
src/c3nav/static/img/marker-shadow.png
Normal file
BIN
src/c3nav/static/img/marker-shadow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 618 B |
Loading…
Add table
Add a link
Reference in a new issue