I have India country WMS layer, and I want to add label for each state and point or small circle for each state. I created a layer from GeoServer using a PostgreSQL database. Using the database how can I show the labels and points for each state with OpenLayers 3?
-
You will have to create an SLD file docs.geoserver.org/stable/en/user/styling/sld/cookbook– julsbreakdownCommented Mar 15, 2017 at 17:46
-
Thanks ,but how to use wms url path in the sld code,i wan't to display lable and points using database and display on wms layer.– Seema BarateCommented Mar 15, 2017 at 18:58
Add a comment
|
1 Answer
So several things,
First, you can assign for a database table (a layer) a default style see here geoserverdocs
You can have red points with a green label if you like.
Second with WMS you can request a different style to the default one. This is done with the the key STYLE:
http://localhost:8080/geoserver/wms?
request=GetMap
&service=WMS
&version=1.1.1
&layers=topp%3Astates
&styles=population
&srs=EPSG%3A4326
&bbox=-145.15104058007,21.731919794922,-57.154894212888,58.961058642578&
&width=780
&height=330
&format=image%2Fpng
With OpenLayers you would do :
var layer= new ol.layer.Tile({
title: layerTitle,
layerType: 'WMS',
legend: 'query',
source: new ol.source.TileWMS({
url: 'url',
crossOrigin: 'anonymous',
params: {
'VERSION': "1.1.1",
'LAYERS': 'layername'
'FORMAT': 'image/png',
'transparent': true,
'STYLES' : sld,
'format': 'application/openlayers',
},
serverType: 'geoserver'
})
});
-
Thanks sir for giving solution.Sir I have one question,If I wan't to display map,layer,point and label or anything from PostgreSQL database using leaflet or open-layer,Then is there necessary to query in PHP and use java script or directly I use database from Geo-server .I new for this so I confused a lot.So If I use PHP then how to connect front end languages.Thanks Commented Mar 17, 2017 at 12:17
-
No need for Sir... I dont really get your question. But you just need to request Geoserver though WMS /WFS HTTP Requests. As shown above you can do this with ol3. Commented Mar 17, 2017 at 12:44