Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is there an OpenLayers layer type that supports just labels on a map without an underlying feature? I think this is called an annotations layer in GIS?

If not, I'm not sure how to approach this and any advice would be appreciated. I thought styling a vector point layer so that the point itself would be invisible might be a good approach but then the user won't be able to select/edit/delete the feature, which is part of the requirement.

Thanks, Andy

Edit

Thanks for suggestions so far.

A bit of further explanation might help. The application is a bit like the 'Create Map' functionality in Google Maps. The user can add markers, lines and polygons to the map using OpenLayers vector editing controls. A popup allows them to edit a label, change the styling and delete the feature. The map settings (zoom, centre, background layer) and features are saved to a SQL Server database and stored as geometry. This is sent to the database as WKT but the layers are loaded as GeoJSON from a handler on the website.

The client has asked for the ability for users to just place labels on the map (without a marker) and save these too. As I mentioned above, I thought about implementing this as a labelled point layer with the points styled to be invisible but this stops the user from selecting/editing existing features.

My question was whether there was an annotation layer type where the user can create annotations, select them and move them around on the map - similar to vector layers. It looks like there isn't so how should I go about approaching this?

share|improve this question
add comment

2 Answers 2

Vector Features with Text

(for your solution just make the vector features opacity 1)

You need to create styles in this example, the text is coming from the attributes of the vector features.

http://openlayers.org/dev/examples/vector-features-with-text.html

            var vectorLayer = new OpenLayers.Layer.Vector("Simple Geometry", {
            styleMap: new OpenLayers.StyleMap({'default':{
                strokeColor: "#00FF00",
                strokeOpacity: 1,
                strokeWidth: 3,
                fillColor: "#FF5500",
                fillOpacity: 0.5,
                pointRadius: 6,
                pointerEvents: "visiblePainted",
                // label with \n linebreaks
                label : "name: ${name}\n\nage: ${age}",
share|improve this answer
    
I'll give that a go. Thanks. –  andyb Nov 13 '12 at 16:41
    
I think you want the opacity to be 0 rather than 1. –  djq Nov 14 '12 at 16:29
    
beside @Mapperz answer you can make Scale Dependent Labels as this example, too. –  Aragon Nov 14 '12 at 16:45
add comment

It depends of what you have on the server side.

In case you use MapServer, you can create layer of TYPE annotation that will show only features names. From MapServer's documentation:

TYPE [annotation|chart|circle|line|point|polygon|raster|query] Specifies how the data should be drawn. Need not be the same as the shapefile type. For example, a polygon shapefile may be drawn as a point layer, but a point shapefile may not be drawn as a polygon layer. Common sense rules. Annotation means that a label point will be calculated for the features, but the feature itself will not be drawn although a marker symbol can be optionally drawn. this allows for advanced labeling like numbered highway shields. Points are labeled at that point. Polygons are labeled first using a centroid, and if that doesn’t fall in the polygon a scanline approach is used to guarantee the label falls within the feature. Lines are labeled at the middle of the longest arc in the visible portion of the line. Query only means the layer can be queried but not drawn (http://goo.gl/Y3HqU).

Then, the client - OpenLayers, for instance - can get this layer via WMS.

In case you use GeoServer a similar solution can be gotten by creating an style - using SLD - that will tell the server to render just the labels, and not the features. Once this style has been created, all the client has to do is requesting the WMS layer with a GetMap request with the parameter styles set to the one created for this task. In my personal blog there is a post with a detailed example that uses this approach (http://goo.gl/pKDhZ).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.