This is the leaflet plugin for GeoServer. Using this plugin user can have access to wms and wfs request easily.

Overview

Documentation leaflet-geoserver-request

Build Status GitHub release (latest by date) GitHub file size in bytes GitHub issues

This is the plugin for Geoserver various kind of requests. Using this plugin, we can make WMS, WFS, getLegendGraphic, WMS-Image request.

demo

Installation and setup

  • using NPM:
npm install leaflet-geoserver-request
  • Quick use :
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="[path to js]/L.Geoserver.js"></script>

Web-Map-Service (WMS) Request

WMS request will provides georeferenced map image.

var wmsLayer = L.Geoserver.wms("http://localhost:8080/geoserver/wms", {
  layers: "topp:tasmania_roads",
});
wmsLayer.addTo(map);
WMS options
Option Type Default Description
layers string undefined This is required filed. If you have multiple layers, you can add them in a comma seperated values: "workspace:layer1,workspace:layer2"
format string image/png formate of the wms request. It may be image/jpeg, image/tiff, application/openlayers
transparent boolean true transparent of the map
CQL_FILTER string INCLUDE To filter the layer based on their attribute. read more about this
zIndex integer 1000 zIndex of the layer
attribution string layer attribution of the layer. It will be added at the bottom-left cornor of the map
style string undefined style file associated with that layer. If you didn't provide the style field, it will take default style of the layer

Web-Feature-Service (WFS) Request

In WFS request, you need to enable the jsonp for GeoServer. By default, jsonp for GeoServer was desabled. open $GEOSERVER_HOME\webapps\geoserver\WEB-INF\web.xml file and uncomment following line,

<context-param>
    <param-name>ENABLE_JSONP</param-name>
    <param-value>true</param-value>
</context-param>

Note: WFS request only applicable for vector layer, not for raster

var wfsLayer = L.Geoserver.wfs("http://localhost:8080/geoserver/wfs", {
  layers: "topp:tasmania_roads",
});
wfsLayer.addTo(map);
WFS options
Options Type Default Description
layers string undefined This is required filed. If you have multiple layers, you can add them in a comma seperated values: "workspace:layer1,workspace:layer2"
style js object/function null The style file can be in form of javascript oject or function. eg `style = {color: "black",fillOpacity: "0", opacity: "0.5" }
onEachFeature function null Common region to add this feature is to add popup when the layer cicked. more detail
CQL_FILTER string INCLUDE To filter the layer based on their attribute. read more about this
fitLayer boolean true The map automatically zoomed into the loaded data region

Web-Mapping-Service-Image (WMSImage) request

This is the custom request naming by me. It will generate the image which will zoomed to the desired location. The main different between wms and wmsImage request is, it can be zoomed to the desired location based on vector layer.

There are certain convention for this request. Please read carefully

  • The first layer must be vector layer in option wmsLayers. Rest of other layers can be vector or raster

  • You need to provide the same number of data list in wmsLayers, wmsCQL_FILTER & wmsStyle fields

  • The map will zoomed to the first parameter of wmsCQL_FILTER region

  • The default value for the style and cql_filter will be include

  • The wmsLayers and wmsId fields are required field

<img src="" id="wmsImage" />
<!-- The id field is required. This id will used in js script option "wmsId"-->
L.Geoserver.wmsImage("http://localhost:8080/geoserver/wms", {
  wmsLayers: [
    "workspace:first_layer",
    "workspace:second_layer",
    "workspace:third_layer",
  ],
  wmsCQL_FILTER: ["district=='Syangja'", "INCLUDE", "INCLUDE"],
  wmsStyle: ["style1", "style2", "INCLUDE"],
  format: "image/png",
  wmsId: "wmsImage",
  width: 300,
  height: 300,
});

Legend Request

The legend request will provide the crossponding legend of the layer to the bottom-left position of the map. In case of not providing style parameter, it will take the default style from GeoServer.

var layerLegend = L.Geoserver.legend("http://localhost:8080/geoserver/wms", {
  layers: "topp:tasmania_roads",
  style: `stylefile`,
});

layerLegend.addTo(map);

Advance WFS request demo

var wfsLayerAdvance = L.Geoserver.wfs("http://localhost:8080/geoserver/wms", {
  layers: "topp:tasmania_roads",
  style: {
    color: "black",
    fillOpacity: "0",
    opacity: "0.5",
  },
  onEachFeature: function (feature, layer) {
    layer.bindPopup("this is popuped");
  },
  CQL_FILTER: "district='Syangja'",
});

map.fitBounds(wfsLayerAdvance.getBounds());
wfsLayerAdvance.addTo(map);

Contribution:

Would ❤️ to see any contributions.

Appreciate:

If you liked my work, show some ❤️ by repo.

Also you can appreciate by

Buy Me A Coffee PayPal Logo

Comments
  • ReferenceError: $ is not defined at NewClass.wfs (L.Geoserver.js:46:1)

    ReferenceError: $ is not defined at NewClass.wfs (L.Geoserver.js:46:1)

    Hi!

    I'm using your plugin to load both WMS and WFS layers from a GeoServer instance on a leaflet map inside an Angular app. WMS are working fine, but when I switched to WFS, I got this error:

    image

    JSONP for GeoServer is enabled. If I try to preview the WFS "Levels" layer from GeoServer web UI, I got the following JSONP data back:

    {
        "type": "FeatureCollection",
        "features": [
            {
                "type": "Feature",
                "id": "V_Levels.fid-6ecc0c01_1813d891570_169",
                "geometry": {
                    "type": "MultiPolygon",
                    "coordinates": [
                        [
                            [
                                [
                                    7.7826615200000008,
                                    45.3871735
                                ],
                                [
                                    7.79106001,
                                    45.38629957
                                ],
                                ...other coordinates...
                            ]
                        ]
                    ]
                },
                "geometry_name": "Geom",
                "properties": {
                    "Id": 1,
                    "CodRip": 1,
                    "CodRegione": 1,
                    "CodProvincia": 1,
                    "CodComune": 201,
                    "CodUts": 201,
                    "CodProvinciaComune": 1001,
                    "CodIstatComune": "001001",
                    "Comune": "Agliè",
                    "ComuneAltro": null,
                    "Area": 13314604.171518622,
                    "Perimetro": 16102.469408787643,
                    "ConcentrazioneMedia": 71
                }
            },
            ...other features...
        ],
        "totalFeatures": 7904,
        "numberMatched": 7904,
        "numberReturned": 50,
        "timeStamp": "2022-06-07T10:04:08.658Z",
        "crs": {
            "type": "name",
            "properties": {
                "name": "urn:ogc:def:crs:EPSG::4326"
            }
        }
    }
    

    Layers' configuration

    // WORKS!
    let boundaries = L.Geoserver.wms('https://mygeoserver.dev/geoserver/wms', {
        layers: 'boundaries:all',
        attribution: '<a href="https://mygeoserver.dev">My data</a>'
    });
    boundaries.addTo(this.map);
    
    // WORKS!
    let wmsLevels = L.Geoserver.wms('https://mygeoserver.dev/geoserver/wms', {
         layers: 'rad:Levels',
         attribution: '<a href="https://mygeoserver.dev">My levels</a>'
    });
    wmsLevels.addTo(this.map);
    
    // DOESN'T WORK!
    let wfsLevels = L.Geoserver.wfs("https://mygeoserver.dev/geoserver/wfs", {
        layers: "rad:Levels",
        attribution: '<a href="https://mygeoserver.dev">My levels</a>'
    });
    wfsLevels.addTo(this.map);
    

    Since the issue seems to be related to $ jQuery function not being found, I've also tried to add a reference to jquery in my module, but with no success. The jquery npm package is already installed in my application.

    import * as $_ from 'jquery';
    const $ = $_;
    
    opened by OculiViridi 3
  • One issue, two differents messages..

    One issue, two differents messages..

    This is my call to L.Geoserver and I have an issue, with two different messages on Chrome and Geoserver I'm using Leaflet.motion as well

    var dataCoords = [];
    
    function doMotion() {
      var seqGroup = L.motion.seq([
        L.motion.polyline(dataCoords, {
        color: "MediumVioletRed",
        weight: 10,
        opacity: 0.8
        }, {
          easing: L.Motion.Ease.easeInOutQuad
        }, {
          removeOnEnd: false,
          icon: L.divIcon({html: "<i class='fa fa-hiking fa-2x' aria-hidden='true'></i>", iconSize: L.point(27.5, 24)})
        }).motionDuration(8000)
      ]).addTo(map);
      seqGroup.on("click", function(){
        seqGroup.motionStart();
      });
      seqGroup.on("dblclick", function(e){
        seqGroup.motionToggle();
      });
      setTimeout(function () {
        seqGroup.motionStart();
      }, 1000);
    };
    
    
    
    var wfsLayer = L.Geoserver.wfs("https://mappingforyou.eu/geoserver/worldmap/ows", {
     layers: "worldmap:debra",
    });
    
    
    wfsLayer.on('layeradd', function(evt) {
      var coords;
      var geometry = evt.layer.feature.geometry;
      if (geometry.type = 'MultiLineString')
        coords = geometry.coordinates[0];
      else if (geometry.type = 'LineString')
        coords = geometry.coordinates;
      else {
        return;
      }
      coords.forEach(function(coords) {
         dataCoords.push([coords[1], coords[0]]);
      });
      doMotion();
    });
    

    Screenshot_22-06-23_11:01:56

    Screenshot_22-06-23_11:02:53

    opened by vincedchart 2
  • Using Multiple LayersLegend with LayerControl

    Using Multiple LayersLegend with LayerControl

    Hello,

    I am using your leaflet-geoserver-request code (thank you for providing it !!!!) on a huge bunch of layers that are controled/displayed via a Layer Control.

    I would like to open the according Legend each time a Layer is Added to the map.

    I tried to use a layerGroup to associate both the WMS layer and it's Legend in a single Layer triggered by the Control Layer, but unfortunately I have a message that states that the "The provided object is not a Layer".

    DO you see a work-around to achieve what I tent to do ???

    Thank you for your help.

    Regards

    Raphael

    Here is the code I am using :

    var norway_map = L.Geoserver.wms('http://15.236.29.28:8080/geoserver/cymo/wms', { layers: 'cymo:norway_floodmap' , format: 'image/png', transparent: true,}); var norway_Legend = L.Geoserver.legend("http://15.236.29.28:8080/geoserver/cymo/wms", { layers: "cymo:norway_floodmap", }); var norway_flood = L.layerGroup([norway_map, norway_Legend]);

    the following message appears when I try to display norway_flood.

    Layer.js:163 Uncaught Error: The provided object is not a Layer. at i.addLayer (Layer.js:163) at i.eachLayer (LayerGroup.js:123) at i.onAdd (LayerGroup.js:107) at i._layerAdd (Layer.js:114) at i.whenReady (Map.js:1465) at i.addLayer (Layer.js:176) at i._onInputClick (Control.Layers.js:383) at HTMLInputElement.c (DomEvent.js:92)

    Thank you for your help one more time !!!!!

    question 
    opened by Rafiosan 2
  • Benefits of  leaflet-geoserver-request over L.tileLayer.wms

    Benefits of leaflet-geoserver-request over L.tileLayer.wms

    I am wondering if there are particular use cases for Using leaflet-geoserver-request over leaflet.tileLayer.wms or if both exist just due to development history and features coming available at different times.

    opened by mylesmc123 1
  • I cannot define more than one L.Geoserver.wfs separate layer

    I cannot define more than one L.Geoserver.wfs separate layer

    When I try to make two or more layers with L.Geoserver.wfs, my layers break (The first layers don't show in the map, and the last layer shows the first layer instead of the correct one.

    I want to fix it, but I need assistance, I don't understand the source of the bug

    To reproduce see this fork where I tried to define 2 layers wfs1 and wfs2 https://github.com/nez/leaflet-geoserver-request/blob/e1bd8687147950fbc514d9f07e2f27e985a2b6f8/examples/maps.html#L61-L89 (In this example I am trying to make two layers with the same dataset, the first is red, and the second is white with half transparency, so the color should look pale red but it shows white.

    There is also the following error in the browser parsererror Error: getJson was not called Uncaught ReferenceError: getJson is not defined

    Thanks for the great lib and for your assistance

    opened by nez 1
  • Legend Request builds wrong URI for Legend

    Legend Request builds wrong URI for Legend

    I'm trying to use the Geoserver with WMS 1.3.0 of the german weather service "DWD". Getting the layer itself with

        var wmsLayer = L.Geoserver.wms('https://maps.dwd.de/geoserver/ows?', {
            layers: 'dwd:Warnungen_Gemeinden',
            version: '1.3.0',
            opacity: 0.5,
            attribution: 'DWD'
        }).addTo(map);
    

    works.

    But when I try to get the legend with

        var layerLegend = L.Geoserver.legend('https://maps.dwd.de/geoserver/ows?', {
            layers: 'dwd:Warnungen_Gemeinden',
            style: `stylefile`,
        });
        layerLegend.addTo(map);
    

    I only get the "broken graphic" symbol. When I inspect the source of the page I see that the wrong URI gets built:

    <img src="https://maps.dwd.de/geoserver/ows?/wms?REQUEST=GetLegendGraphic&amp;VERSION=1.1.0&amp;FORMAT=image/png&amp;LAYER=dwd:Warnungen_Gemeinden&amp;style=stylefile" alt="legend" data-toggle="tooltip" title="Map legend">
    

    The right URI according to the "getCapabilities" document is

    <LegendURL width="306" height="160">
    <Format>image/png</Format>
    <OnlineResource xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="https://maps.dwd.de/geoserver/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=dwd%3AWarnungen_Gemeinden"/>
    </LegendURL>
    

    Or short: Worngly built: https://maps.dwd.de/geoserver/ows?/wms?REQUEST=GetLegendGraphic&amp;VERSION=1.1.0&amp;FORMAT=image/png&amp;LAYER=dwd:Warnungen_Gemeinden&amp;style=stylefile Correct according to GeoServer; https://maps.dwd.de/geoserver/ows?service=WMS&request=GetLegendGraphic&format=image%2Fpng&width=20&height=20&layer=dwd%3AWarnungen_Gemeinden

    opened by oldwired 0
Releases(v1.2.2)
  • v1.2.2(Dec 10, 2021)

    This is the official Leafletjs plugin for Geoserver's various kinds of requests.

    Using this plugin, you can make the following requests,

    1. WMS,
    2. WFS,
    3. getLegendGraphic,
    4. WMS-Image
    Source code(tar.gz)
    Source code(zip)
  • v1.0.3(Jun 20, 2020)

  • v1.0.0(Jun 19, 2020)

Owner
Tek Kshetri
Research Associate at Geo-Informatics Center, AIT || Web-GIS developer
Tek Kshetri
WMS server using node-mapnik

landspeed.js A simple WMS server written in node.js Only supports WMS 1.1 GetMap requests (bbox, width, height, and srs). Requirements Node.js 0.10.x

Dane Springmeyer 52 Jul 21, 2022
Mapbox JavaScript API, a Leaflet Plugin

mapbox.js A Mapbox plugin for Leaflet, a lightweight JavaScript library for traditional raster maps. For the state-of-the-art Mapbox vector maps libra

Mapbox 1.9k Dec 23, 2022
This map is tracking the position of ISS(international space setallite) at every 1 second. I use Nasa's "where the iss" API and "Leaflet.js" for the map.

ISS-tracking-map About This map is tracking the position of ISS(international space setallite) at every 1 second. I use Nasa's "where the iss" API and

Waz.sheeran 2 Oct 25, 2021
React components for Leaflet maps

React Leaflet React components for Leaflet maps. Documentation Getting started API reference Changes See the CHANGELOG file. Contributing See the CONT

Paul Le Cam 4.4k Jan 3, 2023
Vue 2 components for Leaflet maps

Vue2Leaflet Vue2Leaflet is a JavaScript library for the Vue framework that wraps Leaflet making it easy to create reactive maps. How to install npm in

Vue Leaflet 1.9k Dec 29, 2022
Add time dimension capabilities on a Leaflet map.

Leaflet TimeDimension Add time dimension capabilities on a Leaflet map. Examples and basic usage API L.Map L.TimeDimension L.TimeDimension.Layer L.Tim

SOCIB public code 379 Dec 23, 2022
AngularJS directive to embed an interact with maps managed by Leaflet library

Angular Leaflet Why the fork? While we are grateful for all the original work at tombatossals/angular-leaflet-directive. We need to be able to operate

AngularUI 313 Nov 10, 2022
Simple location picker on Leaflet map

Leaflet Location Picker Simple location picker with Leaflet map Usage: <label>Insert a Geo Location <input id="geoloc" type="text" value="" /> </lab

Stefano Cudini 37 Nov 17, 2022
Information about the application internals and instructions on how to run it can be found in our Technical Documentation.

Swisstopo Showcases Welcome to our approach on bringing geodata closer to the user. This is our semester project during our Bachelor studies at the Be

Jonas Hofer 3 Sep 30, 2022
Dashboards-maps is a frontend plugin that helps you in uploading custom GeoJSON to OpenSearch and communicates with the geospatial backend plugin for the same.

Welcome! Project Resources Code of Conduct License Copyright Dashboards-Maps Dashboards-maps is a frontend plugin that helps you in uploading custom G

null 9 Dec 28, 2022
Serverless raster and vector map tile generation using Mapnik and AWS Lambda

tilegarden ??️ ?? Contents About Usage Deployment to AWS Additional Configuration Options Required AWS Permissions Features Configuration Selection an

Azavea 89 Dec 22, 2022
MERN stack travel app using mapbox API, Travel and drop pin , share reviews and rate the location

MERN-Travel-Map Travel Map Pin A single page application built with MERN Stack from scratch (MongoDB + Mongoose, Express, React & NodeJs) Table of Con

Bùi Quốc Trọng 11 Dec 29, 2022
A web based data mining tool for OpenStreetMap using the Overpass API.

overpass turbo https://overpass-turbo.eu/ – stable version https://tyrasd.github.io/overpass-turbo/ – latest version This is a GUI for testing and dev

Martin Raifer 607 Dec 29, 2022
3D web map rendering engine written in TypeScript using three.js

3D web map rendering engine written in TypeScript using three.js

HERE Technologies 1.2k Dec 30, 2022
jQuery plugin for zooming images on mouseover.

About Zoom A small jQuery plugin for zooming images on mouseover or mousedown. See the project page for documentation and a demonstration. Released un

Jack Moore 1.5k Dec 6, 2022
🏸 A simple plugin for image zooming without dependencies ~1.65KB gzip

ZOOOM.JS A simple plugin for image zoooming without dependencies. Only pure javascipt. Installation CDN JavaScript <script src="https://cdn.jsdelivr.n

Grzegorz Tomicki 13 Aug 30, 2022
An online tool to generate and visualize maps for irregular and/or gapped LED layouts, for use with FastLED, Pixelblaze and other libraries.

An online tool to generate and visualize maps for irregular and/or gapped LED layouts, for use with FastLED, Pixelblaze and other libraries.

Jason Coon 172 Dec 8, 2022
The NASA WorldWind Javascript SDK (WebWW) includes the library and examples for creating geo-browser web applications and for embedding a 3D globe in HTML5 web pages.

Web WorldWind New versions of WorldWind released Web WorldWind 0.10.0 and WorldWind Java 2.2.0 are now available on GitHub. The new version of Web Wor

NASA WorldWind 770 Jan 1, 2023
geotiff.js is a small library to parse TIFF files for visualization or analysis. It is written in pure JavaScript, and is usable in both the browser and node.js applications.

geotiff.js Read (geospatial) metadata and raw array data from a wide variety of different (Geo)TIFF files types. Features Currently available function

geotiff.js 649 Dec 21, 2022