Re: [OpenLayers-Dev] Vector labels
Hi Alexandre. We, at Camptocamp, haven't had any funding to pursue that work. Eric 2008/10/31, Alexandre Dube [EMAIL PROTECTED]: I searched the web and found out that's it was not yet possible ( last response in April 2008 ). I saw the CampToCamp example. Anybody knows more ? Alexandre Dube wrote: Hi dev, Anything new about vector labels ? -- Alexandre Dubé Mapgears www.mapgears.com ___ Dev mailing list Dev@openlayers.org http://openlayers.org/mailman/listinfo/dev ___ Dev mailing list Dev@openlayers.org http://openlayers.org/mailman/listinfo/dev
[OpenLayers-Dev] Vector labels
Hi dev, Anything new about vector labels ? -- Alexandre Dubé Mapgears www.mapgears.com ___ Dev mailing list Dev@openlayers.org http://openlayers.org/mailman/listinfo/dev
Re: [OpenLayers-Dev] vector labels - almost there!
Hi, I was wondering if there was any more progress on Vector Labels? I have gotten it too work in Firefox, but now I am having problems in IE7. When I try to add the feature (a point with a label defined), IE7 complains about an unexpected call to a method or property access. Thanks Mark -- View this message in context: http://www.nabble.com/vector-labels-tp16589123p18579171.html Sent from the OpenLayers Dev mailing list archive at Nabble.com. ___ Dev mailing list Dev@openlayers.org http://openlayers.org/mailman/listinfo/dev
Re: [OpenLayers-Dev] vector labels - almost there!
I dug a little more into this problem. The line that is erroring out is in this file: http://dev.openlayers.org/sandbox/camptocamp/text/lib/OpenLayers/Renderer/VML.js in the method drawText(): span.innerHTML = style.label; textbox.appendChild(span); The error occurs on the appendChild. Seems this is a common problem with IE when dynamically creating scripts or styles (or spans?) and using innerHTML. Unsure how to fix it. The documented fixes haven't worked for me. Mark Nine wrote: Hi, I was wondering if there was any more progress on Vector Labels? I have gotten it too work in Firefox, but now I am having problems in IE7. When I try to add the feature (a point with a label defined), IE7 complains about an unexpected call to a method or property access. Thanks Mark -- View this message in context: http://www.nabble.com/vector-labels-tp16589123p19075418.html Sent from the OpenLayers Dev mailing list archive at Nabble.com. ___ Dev mailing list Dev@openlayers.org http://openlayers.org/mailman/listinfo/dev
Re: [OpenLayers-Dev] vector labels - almost there!
Great that you seem to get it to work. I did not have any problems with non disappearing labels, but for the purpose of enabling/disabling labeling I had added a removeText function which seems to be missing from the diff I sent earlier, maybe it might be of use. Good luck. Piebe VML.js: removeText: function(node, style) { var label = this.nodeFactory("label" + node.id, "v:oval"); // remove label if (label label.firstChild) { label.removeChild(label.firstChild); } }, SVG.js: removeText: function(node, style) { var label = this.nodeFactory("label" + node.id, "text"); // remove label if (label label.firstChild) { label.removeChild(label.firstChild); } }, Zer wrote: Hello, After some more investigation, I found out that I had to add the changes in these files too. And now it works almost fine! There is oe issue regarding removing of vectors. I call the destroyFeatures() function on a vector layer. The vetctor objects are removed from the map, but the labels are are not removed. Does anyone know what, and where, to add in the code to destroy them? Thanks, -Z sandbox/camptocamp/text/lib/OpenLayers/Geometry/Point.js r5614 r7005 173 173 174 174 /** 175 * APIMethod: getCentroid 176 * 177 * Returns: 178 * {OpenLayers.Geometry.Point} The centroid of the collection 179 */ 180 getCentroid: function() { 181 return new OpenLayers.Geometry.Point(this.x, this.y); 182 }, 183 184 /** 175 185 * APIMethod: intersects 176 186 * Determine if the input geometry intersects this one. sandbox/camptocamp/text/lib/OpenLayers/Geometry/LinearRing.js r5673 r7005 197 197 } 198 198 return area; 199 }, 200 201 /** 202 * APIMethod: getCentroid 203 * 204 * Returns: 205 * {OpenLayers.Geometry.Point} The centroid of the collection 206 */ 207 getCentroid: function() { 208 if ( this.components (this.components.length 2)) { 209 var sumX = 0.0; 210 var sumY = 0.0; 211 for (var i = 0; i this.components.length - 1; i++) { 212 var b = this.components[i]; 213 var c = this.components[i+1]; 214 sumX += (b.x + c.x) * (b.x * c.y - c.x * b.y); 215 sumY += (b.y + c.y) * (b.x * c.y - c.x * b.y); 216 } 217 var x = sumX / (6 * Math.abs(this.getArea())); 218 var y = sumY / (6 * Math.abs(this.getArea())); 219 } 220 return new OpenLayers.Geometry.Point(x, y); 199 221 }, 200 222 # # sandbox/camptocamp/text/lib/OpenLayers/Geometry/Collection.js r5614 r7005 231 231 return area; 232 232 }, 233 234 /** 235 * APIMethod: getCentroid 236 * 237 * Returns: 238 * {OpenLayers.Geometry.Point} The centroid of the collection 239 */ 240 getCentroid: function() { 241 var centroid = this.components[0].getCentroid(); 242 return centroid; 243 }, 233 244 234 245 /** Arnd Wippermann wrote: Hi, i would also like to display labels on a map. I have tried using OpenLayers.Popup to do this. It seems to work. The labels could be moved after creating, but after zooming the position will new calculated to default values via OpenLayers.Popup. I have no idea, how to prevent this. http://gis.ibbeck.de/ginfo/apps/OLExamples/OL26/examples/labels.html http://gis.ibbeck.de/ginfo/apps/OLExamples/OL26/examples/labels.html Arnd Wippermann http://gis.ibbeck.de/ginfo ___ Dev mailing list Dev@openlayers.org http://openlayers.org/mailman/listinfo/dev
Re: [OpenLayers-Dev] vector labels - almost there!
Hello, After some more investigation, I found out that I had to add the changes in these files too. And now it works almost fine! There is oe issue regarding removing of vectors. I call the destroyFeatures() function on a vector layer. The vetctor objects are removed from the map, but the labels are are not removed. Does anyone know what, and where, to add in the code to destroy them? Thanks, -Z sandbox/camptocamp/text/lib/OpenLayers/Geometry/Point.js r5614 r7005 173 173 174 174 /** 175 * APIMethod: getCentroid 176 * 177 * Returns: 178 * {OpenLayers.Geometry.Point} The centroid of the collection 179 */ 180 getCentroid: function() { 181 return new OpenLayers.Geometry.Point(this.x, this.y); 182 }, 183 184 /** 175 185 * APIMethod: intersects 176 186 * Determine if the input geometry intersects this one. sandbox/camptocamp/text/lib/OpenLayers/Geometry/LinearRing.js r5673 r7005 197 197 } 198 198 return area; 199 }, 200 201 /** 202 * APIMethod: getCentroid 203 * 204 * Returns: 205 * {OpenLayers.Geometry.Point} The centroid of the collection 206 */ 207 getCentroid: function() { 208 if ( this.components (this.components.length 2)) { 209 var sumX = 0.0; 210 var sumY = 0.0; 211 for (var i = 0; i this.components.length - 1; i++) { 212 var b = this.components[i]; 213 var c = this.components[i+1]; 214 sumX += (b.x + c.x) * (b.x * c.y - c.x * b.y); 215 sumY += (b.y + c.y) * (b.x * c.y - c.x * b.y); 216 } 217 var x = sumX / (6 * Math.abs(this.getArea())); 218 var y = sumY / (6 * Math.abs(this.getArea())); 219 } 220 return new OpenLayers.Geometry.Point(x, y); 199 221 }, 200 222 # # sandbox/camptocamp/text/lib/OpenLayers/Geometry/Collection.js r5614 r7005 231 231 return area; 232 232 }, 233 234 /** 235 * APIMethod: getCentroid 236 * 237 * Returns: 238 * {OpenLayers.Geometry.Point} The centroid of the collection 239 */ 240 getCentroid: function() { 241 var centroid = this.components[0].getCentroid(); 242 return centroid; 243 }, 233 244 234 245 /** Arnd Wippermann wrote: Hi, i would also like to display labels on a map. I have tried using OpenLayers.Popup to do this. It seems to work. The labels could be moved after creating, but after zooming the position will new calculated to default values via OpenLayers.Popup. I have no idea, how to prevent this. http://gis.ibbeck.de/ginfo/apps/OLExamples/OL26/examples/labels.html http://gis.ibbeck.de/ginfo/apps/OLExamples/OL26/examples/labels.html Arnd Wippermann http://gis.ibbeck.de/ginfo -- View this message in context: http://www.nabble.com/vector-labels-tp16589123p18238904.html Sent from the OpenLayers Dev mailing list archive at Nabble.com. ___ Dev mailing list Dev@openlayers.org http://openlayers.org/mailman/listinfo/dev
Re: [OpenLayers-Dev] vector labels
Hi, i would also like to display labels on a map. I have tried using OpenLayers.Popup to do this. It seems to work. The labels could be moved after creating, but after zooming the position will new calculated to default values via OpenLayers.Popup. I have no idea, how to prevent this. http://gis.ibbeck.de/ginfo/apps/OLExamples/OL26/examples/labels.html http://gis.ibbeck.de/ginfo/apps/OLExamples/OL26/examples/labels.html Arnd Wippermann http://gis.ibbeck.de/ginfo -- View this message in context: http://www.nabble.com/vector-labels-tp16589123p18225862.html Sent from the OpenLayers Dev mailing list archive at Nabble.com. ___ Dev mailing list Dev@openlayers.org http://openlayers.org/mailman/listinfo/dev
Re: [OpenLayers-Dev] vector labels
Besides its speed, I found the rendering of labels to work fine. I have extracted the needed changes from the sandbox, I am not completely sure but I think the attached diff includes all the adjustments needed to get labeling going. However it also includes a quick hack: labels will only be drawn if labelsVisible is true. I had to include this since rendering the labels (as is all the vector rendering) is awfully slow especially in IE, so I had to give the user the option to turn of labeling. Enable labeling by doing something like: var context = { getTitle: function(feature) { return "blabla " + feature.attributes['titel']; } }; var template = { , label : "${getTitle}" , fontColor: "yellow" , fontWeight: "bold" }; var style = new OpenLayers.Style(template, {context: context}); var styleMap = new OpenLayers.StyleMap( { 'default': style, select: { fillColor: '#ff', externalGraphic:"blabla.png", graphicHeight: 20} } ); layer = new OpenLayers.Layer.WFS( "Blabla", host + "geoserver/wfs", {typename: 'bla:bla'}, { typename: 'bla', featureNS: 'http://bla.bla.bla', extractAttributes: true, styleMap: styleMap } ); Good luck, Piebe Zer wrote: Hi! I also need this function. Has anything more been done since April? What is left to be done? -Z Pierre GIRAUD wrote: Hi Piebe, You're right, there was no activity on this feature since december. In my opinion, there won't be any if there is no clear and loud demand for that, or if there's no fund given. Though, I think the code doesn't require much work to be ready to go into trunk. It's currently available in a sandbox. Don't hesitate to try a merge against current trunk version and to play with it ! Regards, Pierre Index: Elements.js === --- Elements.js (revision 6549) +++ Elements.js (working copy) @@ -151,6 +151,9 @@ this.root.appendChild(node); } this.postDraw(node); + + // draw potential label + this.drawLabel(node, geometry, style); } else { node = OpenLayers.Util.getElement(geometry.id); if (node) { @@ -210,6 +213,32 @@ return this.setStyle(node, style, options, geometry); }, + /** + * Method: drawLabel + * Draws a potential label if set in style + * + * Parameters: + * node - {DOMElement} + * geometry - {OpenLayers.Geometry} + * style - {Object} + */ +drawLabel: function(node, geometry, style) { +if (labelsVisible) // HACK + { + if (style.label) + { + this.drawText(node, style, geometry.getBounds().getCenterPixel()); + } + } + else + { + if (style.label) + { + this.removeText(node, style) + } + } +}, + /** * Method: postDraw * Things that have do be done after the geometry node is appended Index: SVG.js === --- SVG.js (revision 6549) +++ SVG.js (working copy) @@ -464,6 +464,50 @@ node.setAttributeNS(null, d, ); } }, + +/** + * Method: drawText + * This method is only called by the renderer itself. + * + * Parameters: + * node - {DOMElement} + * style - + * location - {OpenLayers.Geometry.Point} + */ +drawText: function(node, style, location) { +var resolution = this.getResolution(); + +var x = (location.x / resolution + this.left); +var y = (location.y / resolution - this.top); + +var label = this.nodeFactory(label + node.id, text); +label.setAttributeNS(null, x, x); +label.setAttributeNS(null, y, -y); + +if (style.fontColor) { +label.setAttributeNS(null, fill, style.fontColor); +} +if (style.fontFamily) { +label.setAttributeNS(null, font-family, style.fontFamily); +} +if (style.fontSize) { +label.setAttributeNS(null, font-size, style.fontSize); +} +if (style.fontWeight) { +label.setAttributeNS(null, font-weight, style.fontWeight); +} + +/* No need to scale Text... */ +label.setAttributeNS(null, transform, scale(1, -1)); + +// prevent label duplication +if (label.firstChild) { +label.removeChild(label.firstChild); +} +var data = document.createTextNode(style.label); +label.appendChild(data); +node.parentNode.appendChild(label); +
Re: [OpenLayers-Dev] vector labels
Hi! I also need this function. Has anything more been done since April? What is left to be done? -Z Pierre GIRAUD wrote: Hi Piebe, You're right, there was no activity on this feature since december. In my opinion, there won't be any if there is no clear and loud demand for that, or if there's no fund given. Though, I think the code doesn't require much work to be ready to go into trunk. It's currently available in a sandbox. Don't hesitate to try a merge against current trunk version and to play with it ! Regards, Pierre -- View this message in context: http://www.nabble.com/vector-labels-tp16589123p18179010.html Sent from the OpenLayers Dev mailing list archive at Nabble.com. ___ Dev mailing list Dev@openlayers.org http://openlayers.org/mailman/listinfo/dev
[OpenLayers-Dev] vector labels
Hi, I really need to display labels on a vector layer. I found http://dev.openlayers.org/sandbox/camptocamp/text/examples/vector-features-with-text.html which looks promising but it seems there has not been much activity since december. Can somebody tell me the current status? Are there any plans to integrate this in trunk anywhere soon, and, if not, for what reason? How hard will it be to do it myself? etc cheers, Piebe ___ Dev mailing list Dev@openlayers.org http://openlayers.org/mailman/listinfo/dev