gluon-config-mode-geo-location-osm, gluon-web-osm: add support for custom tile layers (#2072)
Allow replacing the default OSM layer with a custom XYZ layer in site.conf.
This commit is contained in:
parent
9b3ee477fa
commit
1fc71a73b3
@ -464,9 +464,14 @@ config_mode \: optional
|
|||||||
The *geo_location.osm* section is only relevant when the *gluon-config-mode-geo-location-osm*
|
The *geo_location.osm* section is only relevant when the *gluon-config-mode-geo-location-osm*
|
||||||
package is used. The *center.lon* and *center.lat* values are mandatory in this case and
|
package is used. The *center.lon* and *center.lat* values are mandatory in this case and
|
||||||
define the default center of the map when no position has been picked yet. The *zoom* level
|
define the default center of the map when no position has been picked yet. The *zoom* level
|
||||||
defaults to 12 in this case. *openlayers_url* allows to override the base URL of the
|
defaults to 12 in this case.
|
||||||
|
|
||||||
|
*openlayers_url* allows to override the base URL of the
|
||||||
*build/ol.js* and *css/ol.css* files (the default is
|
*build/ol.js* and *css/ol.css* files (the default is
|
||||||
``https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.2.0``).
|
``https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.2.0``).
|
||||||
|
It is also possible to replace the default tile layer (which is OpenStreetMap)
|
||||||
|
with a custom one using the *tile_layer* section. Only XYZ layers are supported
|
||||||
|
at this point.
|
||||||
|
|
||||||
The remote login page only shows SSH key configuration by default. A
|
The remote login page only shows SSH key configuration by default. A
|
||||||
password form can be displayed by setting *remote_login.show_password_form*
|
password form can be displayed by setting *remote_login.show_password_form*
|
||||||
@ -488,6 +493,11 @@ config_mode \: optional
|
|||||||
},
|
},
|
||||||
zoom = 13,
|
zoom = 13,
|
||||||
-- openlayers_url = 'http://ffac.example.org/openlayer',
|
-- openlayers_url = 'http://ffac.example.org/openlayer',
|
||||||
|
-- tile_layer = {
|
||||||
|
-- type = 'XYZ',
|
||||||
|
-- url = 'https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||||
|
-- attributions = '© <a href="https://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors.',
|
||||||
|
-- },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
remote_login = {
|
remote_login = {
|
||||||
|
@ -2,3 +2,9 @@ need_number(in_site({'config_mode', 'geo_location', 'osm', 'center', 'lon'}))
|
|||||||
need_number(in_site({'config_mode', 'geo_location', 'osm', 'center', 'lat'}))
|
need_number(in_site({'config_mode', 'geo_location', 'osm', 'center', 'lat'}))
|
||||||
need_number(in_site({'config_mode', 'geo_location', 'osm', 'zoom'}), false)
|
need_number(in_site({'config_mode', 'geo_location', 'osm', 'zoom'}), false)
|
||||||
need_string(in_site({'config_mode', 'geo_location', 'osm', 'openlayers_url'}), false)
|
need_string(in_site({'config_mode', 'geo_location', 'osm', 'openlayers_url'}), false)
|
||||||
|
|
||||||
|
if need_table(in_site({'config_mode', 'geo_location', 'osm', 'tile_layer'}), nil, false) then
|
||||||
|
need_one_of(in_site({'config_mode', 'geo_location', 'osm', 'tile_layer', 'type'}), {'XYZ'})
|
||||||
|
need_string(in_site({'config_mode', 'geo_location', 'osm', 'tile_layer', 'url'}))
|
||||||
|
need_string(in_site({'config_mode', 'geo_location', 'osm', 'tile_layer', 'attributions'}))
|
||||||
|
end
|
||||||
|
@ -19,6 +19,7 @@ function M.options()
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
openlayers_url = config.openlayers_url(),
|
openlayers_url = config.openlayers_url(),
|
||||||
|
tile_layer = config.tile_layer(),
|
||||||
zoom = config.zoom(12),
|
zoom = config.zoom(12),
|
||||||
pos = config.center(),
|
pos = config.center(),
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
<%- end %>
|
<%- end %>
|
||||||
}, {once: true});
|
}, {once: true});
|
||||||
|
|
||||||
initOSM(<%=json(self.openlayers_url)%>, function(createMap) {
|
initOSM(<%=json(self.options)%>, function(createMap) {
|
||||||
elMap.style.display = '';
|
elMap.style.display = '';
|
||||||
|
|
||||||
var pos = <%=json(self:cfgvalue().pos)%>;
|
var pos = <%=json(self:cfgvalue().pos)%>;
|
||||||
|
@ -1 +1 @@
|
|||||||
"use strict";function initOSM(e,o){var t=document.createElement("link");t.rel="stylesheet",t.type="text/css",t.href=e+"/css/ol.css",document.head.appendChild(t);var n=document.createElement("script"),r=!1;n.onload=n.onreadystatechange=function(){if(!(r||this.readyState&&"loaded"!==this.readyState&&"complete"!==this.readyState)){r=!0;var t=new Image;t.onload=function(){var e=new ol.style.Style({image:new ol.style.Icon({img:t,imgSize:[30,45],anchor:[.5,1]})}),c=new ol.Feature;c.setStyle(e),o(function(e,t,o,n,r){var a=new ol.Map({target:e,layers:[new ol.layer.Tile({source:new ol.source.OSM}),new ol.layer.Vector({source:new ol.source.Vector({features:[c]})})],view:new ol.View({center:ol.proj.fromLonLat(t),zoom:o})}),l=function(e){c.setGeometry(new ol.geom.Point(e))};return a.addEventListener("click",function(e){l(e.coordinate),r(ol.proj.toLonLat(e.coordinate))}),n&&l(ol.proj.fromLonLat(t)),a})},t.src="data:image/svg+xml,"+escape('<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="30" height="45"><path d="M2,15A13,13,0,0,1,28,13Q28,28,15,45Q2,28,2,15" fill="#48b" stroke="#369" stroke-width="1.5" /><circle cx="15" cy="15" r="6" fill="#fff" /></svg>')}},n.src=e+"/build/ol.js",document.head.appendChild(n)}
|
"use strict";function initOSM(o,r){var e=document.createElement("link");e.rel="stylesheet",e.type="text/css",e.href=o.openlayers_url+"/css/ol.css",document.head.appendChild(e);var t=document.createElement("script"),l=!1;t.onload=t.onreadystatechange=function(){if(!(l||this.readyState&&"loaded"!==this.readyState&&"complete"!==this.readyState)){l=!0;var t=new Image;t.onload=function(){var i,e=new ol.style.Style({image:new ol.style.Icon({img:t,imgSize:[30,45],anchor:[.5,1]})}),s=new ol.Feature;s.setStyle(e),i=o.tile_layer&&"XYZ"===o.tile_layer.type?new ol.source.XYZ({url:o.tile_layer.url,attributions:o.tile_layer.attributions}):new ol.source.OSM,r(function(e,t,o,r,l){function n(e){s.setGeometry(new ol.geom.Point(e))}var a=new ol.Map({target:e,layers:[new ol.layer.Tile({source:i}),new ol.layer.Vector({source:new ol.source.Vector({features:[s]})})],view:new ol.View({center:ol.proj.fromLonLat(t),zoom:o})});return a.addEventListener("click",function(e){n(e.coordinate),l(ol.proj.toLonLat(e.coordinate))}),r&&n(ol.proj.fromLonLat(t)),a})},t.src="data:image/svg+xml,"+escape('<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="30" height="45"><path d="M2,15A13,13,0,0,1,28,13Q28,28,15,45Q2,28,2,15" fill="#48b" stroke="#369" stroke-width="1.5" /><circle cx="15" cy="15" r="6" fill="#fff" /></svg>')}},t.src=o.openlayers_url+"/build/ol.js",document.head.appendChild(t)}
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function initOSM(openlayers_url, ready) {
|
function initOSM(options, ready) {
|
||||||
var markerSvg = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="30" height="45">'
|
var markerSvg = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="30" height="45">'
|
||||||
+ '<path d="M2,15A13,13,0,0,1,28,13Q28,28,15,45Q2,28,2,15" fill="#48b" stroke="#369" stroke-width="1.5" />'
|
+ '<path d="M2,15A13,13,0,0,1,28,13Q28,28,15,45Q2,28,2,15" fill="#48b" stroke="#369" stroke-width="1.5" />'
|
||||||
+ '<circle cx="15" cy="15" r="6" fill="#fff" />'
|
+ '<circle cx="15" cy="15" r="6" fill="#fff" />'
|
||||||
@ -15,7 +15,7 @@ function initOSM(openlayers_url, ready) {
|
|||||||
var style = document.createElement('link');
|
var style = document.createElement('link');
|
||||||
style.rel = 'stylesheet';
|
style.rel = 'stylesheet';
|
||||||
style.type = 'text/css';
|
style.type = 'text/css';
|
||||||
style.href = openlayers_url + '/css/ol.css';
|
style.href = options.openlayers_url + '/css/ol.css';
|
||||||
document.head.appendChild(style);
|
document.head.appendChild(style);
|
||||||
|
|
||||||
var script = document.createElement('script');
|
var script = document.createElement('script');
|
||||||
@ -42,12 +42,22 @@ function initOSM(openlayers_url, ready) {
|
|||||||
var marker = new ol.Feature();
|
var marker = new ol.Feature();
|
||||||
marker.setStyle(markerStyle);
|
marker.setStyle(markerStyle);
|
||||||
|
|
||||||
|
var source;
|
||||||
|
if (options.tile_layer && options.tile_layer.type === 'XYZ') {
|
||||||
|
source = new ol.source.XYZ({
|
||||||
|
url: options.tile_layer.url,
|
||||||
|
attributions: options.tile_layer.attributions,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
source = new ol.source.OSM();
|
||||||
|
}
|
||||||
|
|
||||||
ready(function(elMap, pos, zoom, set, onUpdate) {
|
ready(function(elMap, pos, zoom, set, onUpdate) {
|
||||||
var map = new ol.Map({
|
var map = new ol.Map({
|
||||||
target: elMap,
|
target: elMap,
|
||||||
layers: [
|
layers: [
|
||||||
new ol.layer.Tile({
|
new ol.layer.Tile({
|
||||||
source: new ol.source.OSM()
|
source: source
|
||||||
}),
|
}),
|
||||||
new ol.layer.Vector({
|
new ol.layer.Vector({
|
||||||
source: new ol.source.Vector({
|
source: new ol.source.Vector({
|
||||||
@ -79,6 +89,6 @@ function initOSM(openlayers_url, ready) {
|
|||||||
|
|
||||||
markerImg.src = 'data:image/svg+xml,' + escape(markerSvg);
|
markerImg.src = 'data:image/svg+xml,' + escape(markerSvg);
|
||||||
};
|
};
|
||||||
script.src = openlayers_url + '/build/ol.js';
|
script.src = options.openlayers_url + '/build/ol.js';
|
||||||
document.head.appendChild(script);
|
document.head.appendChild(script);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,10 @@ M.MapValue = MapValue
|
|||||||
function MapValue:__init__(title, options)
|
function MapValue:__init__(title, options)
|
||||||
classes.AbstractValue.__init__(self, title)
|
classes.AbstractValue.__init__(self, title)
|
||||||
self.subtemplate = "model/osm/map"
|
self.subtemplate = "model/osm/map"
|
||||||
self.openlayers_url = options.openlayers_url or DEFAULT_URL
|
self.options = {
|
||||||
|
openlayers_url = options.openlayers_url or DEFAULT_URL,
|
||||||
|
tile_layer = options.tile_layer,
|
||||||
|
}
|
||||||
self.lon = options.lon
|
self.lon = options.lon
|
||||||
self.lat = options.lat
|
self.lat = options.lat
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user