Good way to move/hide measurement line labels in 4.5/2.6?
Does anyone have a recommendation for moving the new labels for measurement lines? Specifically the total distance box. It displays right over the end of the line? And if the line is small enough, it displays over the entire line.
Example:
I do like the labels, but they may need to be more responsive to the size of the line as well as the final length off the end of the line like it was in 4.4:
For now, I'm working on a button to show/hide the div "Drawings_measurement_layer".
0
-
Hello, Did you find a way to get this working? I have managed to create a button to show/hide drawings, but I could not hide the measurement labels. Thanks! 0 -
Good afternoon, 0 -
That's great Marshall! Do you mind if we add your code to our Code Gallery for others to try and use? 0 -
Sure thing, I didn't know if you wanted it in there with the edit to the Mapping.js that I did for the offset. But yeah, I'm fine with you adding it to the code gallery. 0 -
Thanks Marshall! I was hesitant to modify any code, but I'm glad you work it out. 0 -
An excellent solution to measurement labels, Marshall! Thanks so much for sharing that. 0 -
Marshall, 0 -
Justin, that is a great question. I'm sure there is a solution for it and when things calm down a little here I'll take a look. The tough part is that each measurement (including the final) is part of the same graphic layer so for me it was easier to just hide/show that layer. 0 -
not the most elegant solution for the text movement of the total measurement label. But in Essentials.js, look for b.adjustTextSymbl=function(a,b) and just before the statement 'return d', towards the end of the function, add 'if(d.text.indexOf("Total:") !==-1)d.yoffset=-7;' b.adjustTextSymbol = function(a, b) { if (a && a.symbol instanceof esri.symbol.TextSymbol) { var c = function(a, b) { b.font.size = void 0 != a.font.size && "number" === typeof a.font.size ? Math.round(a.font.size) + "px" : a.font.size; b.x = a.x; b.y = a.y; b.xoffset = a.xoffset; b.yoffset = a.yoffset; b.align = a.align; b.angle = a.angle; b.color.hasOwnProperty("a") && (b.color.a = 0 <= a.color.a && 1 >= a.color.a ? 255 * a.color.a : a.color.a) }, d = new esri.symbol.TextSymbol(a.symbol.toJson()); d.color = new esri.Color({ r: a.symbol.color.r, g: a.symbol.color.g, b: a.symbol.color.b, a: a.symbol.color.a }); c(a.symbol, d); if (d.toJson && "function" === typeof d.toJson) { var f = d.toJson; d.toJson = function() { var a = f.call(d); c(d, a); return a } } var l = null, k = null; if (b) { var q = document.getElementById(b + "_layer"), p = null, p = document.createElementNS("http://www.w3.org/2000/svg", "text"); p.setAttributeNS(null, "font-size", d.font.size); p.setAttributeNS(null, "font-family", d.font.family); p.setAttributeNS(null, "visibility", "hidden"); p.textContent = d.text; q.appendChild(p); var r = p.getBBox(), k = null === k ? r.height : k, l = null === l ? p.getComputedTextLength() : l } else { q = document.body; p = document.createElement("div"); l = { fontFamily: d.font.family, fontSize: d.font.size, fontWeight: d.font.weight, padding: "0", position: "absolute", lineHeight: "1", visibility: "hidden" }; for (r in l) p.style[r] = l[r]; p.appendChild(document.createTextNode(d.text)); q.appendChild(p); l = p.clientWidth; k = p.clientHeight } q.removeChild(p); d.xoffset = 0 === d.angle ? d.xoffset : 0; d.yoffset = 0 === d.angle ? d.yoffset : 0; if ((a.measurementId || a.coordinateId) && a.attributes && a.attributes.numberOfLines) d.xoffset = a.measurementId ? -(l / 2 + k / 4) : -(l / 4 + k / 2), d.yoffset = a.attributes.numberOfLines && 1 == a.attributes.numberOfLines ? k / 2 : d.yoffset, "start" == d.verticalAlignment && a.attributes.numberOfLines && 1 < a.attributes.numberOfLines && (d.yoffset = d.yoffset - 0.5 * k / 2 + k * a.attributes.numberOfLines / 2); else { switch (d.verticalAlignment) { case "top": break; case "middle": d.yoffset += k / 2; break; default: d.yoffset += 0.75 * k } a.attributes && a.attributes.customVerticalAlignment && "middle" === a.attributes.customVerticalAlignment && (d.xoffset = 0, d.yoffset = 0, d.yoffset += Math.ceil(k / 2)); if (q = d.horizontalAlignment || d.align || null) switch (q) { case esri.symbol.TextSymbol.ALIGN_MIDDLE: case "center": case "justify": d.xoffset -= Math.ceil(l / 2); a.coordinateId || (d.xoffset -= Math.ceil(k / 4)); break; case esri.symbol.TextSymbol.ALIGN_END: case "right": d.xoffset -= l } } if (d.text.indexOf("Total:") !== -1) d.yoffset = -7; return d } return null };
0 -
Thank you Marshall! This worked great! 0 -
Marshall, thanks for both tips!! 0 -
Marshall, I've got a site I created that uses the same GVH as the one on which I successfully implemented your label offsets. Trouble I noticed just today is that its measurement tool will draw lines just fine, but it draws no labels. 0 -
I've answered my own question. After adding the geometry Service URL to the troublesome site after noticing it was blank, the labels appeared on the measurement lines. 0 -
Marshall, 0 -
Thank you, Marshall. I'll definitely be trying this out The measurement tools sure could use some help! I do wish we could turn off individual pieces of the labels. If the user is only drawing one line, it gets labeled twice - - one for the segment and then again for the total length. That's a bit redundant. With polygons, the perimeter lengths are not always needed either. Users also miss the ability to choose whether or not to have the measurement ouput persist as a graphic or disappear when they are done measuring. 0 -
Thank you Marshall, I was able to implement this very useful function with your code and instructions. Much appreciated. Wendy 0 -
Hi Marshall, 0 -
Hi Marshall, 0 -
Hi Stephanie, 0 -
Hey Marshall, 0 -
Thanks for creating this solution Marshall! 0 -
Chelsea, from my pespective, being able to correct the measurement label position was more important than toggling the labels on and off. With help from Amanda at Latitude support I learned how to correct the measurement label position in 2.8.x.
Justin
0 -
When printing or exporting the map with GVH 2.8 you will want to update how the label is offset there as well. As mentioned by Marshall on September 20th, 2016 you will need to edit one more file. This file is now the "C:\inetpub\wwwroot\Html5Viewer\Resources\Compiled\Essentials.bundle.js" file. Search for e.adjustTextSymbol = function (e, t) and just before the 'return r' you will want to enter in' if (r.text.indexOf("Total:") !== -1) r.yoffset = -7; ' return e.adjustTextSymbol = function (e, t) { if (e && e.symbol instanceof esri.symbol.TextSymbol) { var i = function (e, t) { t.font.size = void 0 != e.font.size && "number" == typeof e.font.size ? Math.round(e.font.size) + "px" : e.font.size, t.x = e.x, t.y = e.y, t.xoffset = e.xoffset, t.yoffset = e.yoffset, t.align = e.align, t.angle = e.angle, t.color.hasOwnProperty("a") && (t.color.a = e.color.a >= 0 && e.color.a <= 1 ? 255 * e.color.a : e.color.a) }, r = new esri.symbol.TextSymbol(e.symbol.toJson()); if (r.color = new esri.Color({ r : e.symbol.color.r, g : e.symbol.color.g, b : e.symbol.color.b, a : e.symbol.color.a }), i(e.symbol, r), r.toJson && "function" == typeof r.toJson) { var n = r.toJson; r.toJson = function () { var e = n.call(r); return i(r, e), e } } var s = null, a = null; if (t) { var o = document.getElementById(t + "_layer"), l = null; l = document.createElementNS("http://www.w3.org/2000/svg", "text"), l.setAttributeNS(null, "font-size", r.font.size.toString()), l.setAttributeNS(null, "font-family", r.font.family), l.setAttributeNS(null, "visibility", "hidden"), l.textContent = r.text, o.appendChild(l); var c = l.getBBox(); a = null === a ? c.height : a, s = null === s ? l.getComputedTextLength() : s, o.removeChild(l) } else { var u = document.body, p = document.createElement("div"), h = { fontFamily : r.font.family, fontSize : r.font.size, fontWeight : r.font.weight, padding : "0", position : "absolute", lineHeight : "1", visibility : "hidden" }; for (var d in h) p.style[d] = h[d]; p.appendChild(document.createTextNode(r.text)), u.appendChild(p), s = p.clientWidth, a = p.clientHeight, u.removeChild(p) } if (r.xoffset = 0 === r.angle ? r.xoffset : 0, r.yoffset = 0 === r.angle ? r.yoffset : 0, (e.measurementId || e.coordinateId) && e.attributes && e.attributes.numberOfLines) { if (e.measurementId ? r.xoffset = - (s / 2 + a / 4) : r.xoffset = - (s / 4 + a / 2), r.yoffset = e.attributes.numberOfLines && 1 == e.attributes.numberOfLines ? a / 2 : r.yoffset, "start" == r.verticalAlignment && e.attributes.numberOfLines && e.attributes.numberOfLines > 1) { var f = e.attributes.numberOfLines; r.yoffset = r.yoffset - .5 * a / 2 + a * f / 2 } } else { switch (r.verticalAlignment) { case "top": break; case "middle": r.yoffset += a / 2; break; default: r.yoffset += .75 * a } e.attributes && e.attributes.customVerticalAlignment && "middle" === e.attributes.customVerticalAlignment && (r.xoffset = 0, r.yoffset = 0, r.yoffset += Math.ceil(a / 2)); var y = r.horizontalAlignment || r.align || null; if (y) switch (y) { case esri.symbol.TextSymbol.ALIGN_MIDDLE: case "center": case "justify": r.xoffset -= Math.ceil(s / 2), e.coordinateId || (r.xoffset -= Math.ceil(a / 4)); break; case esri.symbol.TextSymbol.ALIGN_END: case "right": r.xoffset -= s } } if (r.text.indexOf("Total:") !== -1) r.yoffset = -23; return r } return null
0 -
Thanks Marshall for posting this. 0 -
Hi everyone, - Navigate to the viewer's dekstop config file. The default location is: C:\Program Files (x86)\Latitude Geographics\Geocortex Essentials\Default\REST Elements\Sites\SITENAME\Viewers\VIEWERNAME\VirtualDirectory\Resources\Config\Default\Desktop.json.js
- Backup the file and edit the original in a text editor like Notepad
- Use CTRL + F to search for "id": "MeasurementViewModel"
- In the list of configuration properties below, add a new line at the bottom:
, "polylineLabelOffset": 50
(use whatever number you want instead of 50, the default is 5 if it is not set). Example:{ "id": "MeasurementViewModel", "type": "geocortex.essentialsHtmlViewer.mapping.modules.measurement.MeasurementViewModel", "configuration": { "markupLayerName": "Drawings", "lineColor": "#0000FF", "fillColor": "#6495ED", "textColor": "#000000", "highlightColor": "#FFFFFF", "outlineColor": "#000000", "outlineWidth": "1", "totalMeasurementTextColor": "#FFFFFF", "totalMeasurementHighlightColor": "#000000", "totalMeasurementOutlineColor": "#FFFFFF", "totalMeasurementOutlineWidth": "2", "highlightRadius": "5", "textSize": "12px", "addMarkupToMapByDefault": true, "polylineLabelOffset": 50 } }
- Save the file and test the viewer
- Repeat for Tablet.json.js and Handheld.json.js if necessary
0 -
Toggling the measurement labels can be done really simply now from Workflow 5 (requires GE 4.8/GVH 2.9+). I've posted a workflow for this here (https://communities.geocortex.com/s/question/0D5f200004wvzy4CAA/toggle-measurement-labels-in-the-geocortex-html5-viewer-using-workflow-5) if anyone is interested in getting a "toggle measurement labels" button for their viewer without needing to modify any code. 0 -
Hi Amanda, 0 -
Hi Amanda, 0 -
Hello Marshall or to whom it may concern, 0 -
Thanks to Marshall, Daniel and Justin's notes. The code is working now for offset the lable. Truly appreciated. 0
Please sign in to leave a comment.
Comments
33 comments