2019-04-04 11:49:55 +03:00
|
|
|
/* exported LabelOverlay */
|
|
|
|
/* globals AbstractIconOverlay: true */
|
2019-02-08 17:12:40 +03:00
|
|
|
|
2019-02-26 23:19:01 +03:00
|
|
|
|
2019-02-08 17:12:40 +03:00
|
|
|
var LabelOverlay = AbstractIconOverlay.extend({
|
|
|
|
initialize: function(wsChannel, layerMgr) {
|
2019-02-08 20:06:16 +03:00
|
|
|
AbstractIconOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "label");
|
2019-02-08 17:12:40 +03:00
|
|
|
},
|
|
|
|
|
2019-06-09 19:31:05 +03:00
|
|
|
getMaxDisplayedZoom: function(){
|
|
|
|
return 5;
|
|
|
|
},
|
|
|
|
|
2019-02-08 17:12:40 +03:00
|
|
|
getIcon: function(lbl){
|
2019-04-04 14:21:20 +03:00
|
|
|
|
2019-06-09 19:31:05 +03:00
|
|
|
var zoom = this.map.getZoom();
|
|
|
|
var factor = Math.pow(2, 12-zoom);
|
|
|
|
|
2019-04-04 22:19:25 +03:00
|
|
|
var height = 200;
|
|
|
|
var width = 200;
|
2019-06-09 19:31:05 +03:00
|
|
|
var fontSize = Math.min(lbl.attributes.size, 200) / factor;
|
|
|
|
|
|
|
|
var notVisible = (fontSize < 2 || fontSize > 50);
|
2019-04-04 22:19:25 +03:00
|
|
|
|
2019-04-04 14:21:20 +03:00
|
|
|
const html = `
|
2019-06-09 19:31:05 +03:00
|
|
|
<svg height='${height}' width='${width}' text-anchor='middle'>
|
2019-04-04 22:19:25 +03:00
|
|
|
<text x='${width/2}' y='${height/2}'
|
2019-06-09 19:31:05 +03:00
|
|
|
font-size='${fontSize}px'
|
2019-04-04 22:19:25 +03:00
|
|
|
fill='${lbl.attributes.color}'
|
|
|
|
dominant-baseline="central"
|
|
|
|
transform="rotate(${lbl.attributes.direction}, 100, 100)">
|
|
|
|
${lbl.attributes.text}
|
|
|
|
</text>
|
2019-04-04 14:21:20 +03:00
|
|
|
</svg>
|
|
|
|
`;
|
|
|
|
|
2019-06-09 19:31:05 +03:00
|
|
|
return L.divIcon({
|
|
|
|
html: notVisible ? "" : html,
|
|
|
|
bgPos: L.point(100,100),
|
|
|
|
className: "mapserver-label-icon"
|
2019-02-26 23:19:01 +03:00
|
|
|
});
|
2019-02-08 17:12:40 +03:00
|
|
|
},
|
|
|
|
|
2019-04-15 08:54:11 +03:00
|
|
|
createPopup: function(){}
|
2019-02-08 17:12:40 +03:00
|
|
|
});
|