1
0
forked from MTSR/mapserver
mapserver/server/static/js/overlays/LabelOverlay.js

54 lines
1.3 KiB
JavaScript
Raw Normal View History

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
var LabelIcon = L.Icon.extend({
initialize: function(options) {
L.Icon.prototype.initialize.call(this, options);
},
2019-04-04 11:49:55 +03:00
createIcon: function() {
2019-02-26 23:19:01 +03:00
var div = document.createElement('div'),
options = this.options;
div.innerHTML = options.html || "";
2019-04-04 22:19:25 +03:00
div.style.width = "200px";
div.style.height = "200px";
div.style.marginLeft = "-100px";
div.style.marginTop = "-175px";
2019-02-26 23:19:01 +03:00
return div;
}
});
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
},
getIcon: function(lbl){
2019-04-04 14:21:20 +03:00
2019-04-04 22:19:25 +03:00
var height = 200;
var width = 200;
var fontSize = Math.min(lbl.attributes.size, 20);
2019-04-04 14:21:20 +03:00
const html = `
2019-04-04 22:19:25 +03:00
<svg height='${height}' width='${width}' text-anchor='middle' font-size='${fontSize}px'>
<text x='${width/2}' y='${height/2}'
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-02-26 23:19:01 +03:00
return new LabelIcon({
2019-04-04 22:19:25 +03:00
html: html,
height: height,
width: width
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
});