How can I use a point/marker style created on GeoServer within my Leaflet map when I am drawing data from the server using PHP.

I am currently PHP to draw geodata from my GIS server, however I would like to use one of my custom styles created within GeoServer as the marker which shows on Leaflet as Leaflet does not support triangle or cross shaped markers by default. Is it possible to draw my marker type using WMS or PHP and apply it to the data drawn from my database using PHP?

Current marker options

var markerOptions = {
            radius: 4,
            fillColor: '#FF6600',
            color: '#000',
            weight: 1,
            opacity: 1,
            fillOpacity: 0.4 }

GeoServer custom style AKA Pub Style

  mark: symbol(triangle);
  mark-size: 8px;
  :mark {

current call using AJAX to get PHP data using markerOptions as the style

var pTable = 'geoupload.pubs';
var pIRETable = 'geoupload.Pubs_and_Clubs_in_Causeway_Coast_and_Glens NI';
var pColumn =["id", "p_name", "address1", "postcode", "local_authority"];
var pGeom = "geom";

        url: "knn.php",
        data:{table: pTable, inclu: pColumn, geomy: pGeom}
        pubsLay = L.geoJSON(JSON.parse(data),{
            pointToLayer: function (feature, latlng){
                return L.circleMarker(latlng,markerOptions);

KNN.php call to get data from server

//call table and data
    $table = $_GET['table'];
    $inclu = $_GET['inclu'];
    $geomy = $_GET['geomy'];

    //construct substitutions
    $fields = "";
    foreach ($inclu as $i => $col) {
        $fields = $fields . $col . ", ";
    $fields = $fields . $geomy;
    $geom = " - " . $geomy;

    //build query
    $sql1 =
    "SELECT jsonb_build_object(
            'type',     'FeatureCollection',
            'features', jsonb_agg(feature))
    FROM (
        SELECT jsonb_build_object(
            'type',       'Feature',
            'geometry',   ST_AsGeoJSON(st_transform(geom,4326),4)::jsonb,
            'properties', to_jsonb(row) #omits#
        ) AS feature
        FROM (SELECT #fields# FROM #table#) row) features;";

    //replace placeholders
    $sql2 = str_replace("#table#", $table, $sql1);
    $sql3 = str_replace("#fields#", $fields, $sql2);
    $sql4 = str_replace("#omits#", $geom, $sql3);

//execute query
if (!$response = pg_query($conn, $sql4)) {
    ChromePhp::error("*SQL failed*");
//return data
while ($row = pg_fetch_row($response)) {
    foreach ($row as $i => $attr){
        echo $attr;
  • 1
    have you considered using GeoServer to serve the data as it is designed to do? Look at the view options (gis.stackexchange.com/questions/305192/…) – Ian Turton Mar 29 at 7:54
  • @IanTurton The reason I have chosen to use php is because I am planning on creating a knn function through the server so need to call the data via php to be able to execute this script – WMTS Mar 29 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.