1
0
forked from MTSR/mapserver
mapserver/public/js/map/overlays/LabelOverlay.js

45 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2019-06-11 15:01:16 +02:00
import AbstractIconOverlay from './AbstractIconOverlay.js';
2020-04-30 11:31:51 +02:00
import { HtmlSanitizer } from '../../lib/HtmlSanitizer.js';
2019-02-08 15:12:40 +01:00
2019-06-11 15:01:16 +02:00
export default AbstractIconOverlay.extend({
2019-09-18 11:53:58 +02:00
initialize: function() {
AbstractIconOverlay.prototype.initialize.call(this, "label");
2019-02-08 15:12:40 +01:00
},
2019-06-09 18:31:05 +02:00
getMaxDisplayedZoom: function(){
return 5;
},
2019-02-08 15:12:40 +01:00
getIcon: function(lbl){
2019-04-04 13:21:20 +02:00
2019-06-09 18:31:05 +02:00
var zoom = this.map.getZoom();
var factor = Math.pow(2, 12-zoom);
2019-04-04 21:19:25 +02:00
var height = 200;
var width = 200;
2019-06-09 18:31:05 +02:00
var fontSize = Math.min(lbl.attributes.size, 200) / factor;
var notVisible = (fontSize < 2 || fontSize > 50);
2019-04-04 21:19:25 +02:00
2019-04-04 13:21:20 +02:00
const html = `
2019-08-13 19:26:52 +02:00
<svg height='${height}' width='${width}' text-anchor='middle' style='pointer-events: none;'>
2019-04-04 21:19:25 +02:00
<text x='${width/2}' y='${height/2}'
2019-06-09 18:31:05 +02:00
font-size='${fontSize}px'
2019-04-04 21:19:25 +02:00
fill='${lbl.attributes.color}'
dominant-baseline="central"
transform="rotate(${lbl.attributes.direction}, 100, 100)">
2020-04-30 11:31:51 +02:00
${HtmlSanitizer.SanitizeHtml(lbl.attributes.text)}
2019-04-04 21:19:25 +02:00
</text>
2019-04-04 13:21:20 +02:00
</svg>
`;
2019-06-09 18:31:05 +02:00
return L.divIcon({
html: notVisible ? "" : html,
bgPos: L.point(100,100),
className: "mapserver-label-icon"
2019-02-26 21:19:01 +01:00
});
2019-02-08 15:12:40 +01:00
},
2019-04-15 07:54:11 +02:00
createPopup: function(){}
2019-02-08 15:12:40 +01:00
});