Skip to content

Commit

Permalink
Merge pull request #16 from mrzh4s/styling-not-fetch-function-WFS
Browse files Browse the repository at this point in the history
Style Function Not Work In WFS
  • Loading branch information
iamtekson authored Mar 6, 2023
2 parents f15bffc + 4b1c850 commit 1184630
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
20 changes: 0 additions & 20 deletions package-lock.json

This file was deleted.

27 changes: 18 additions & 9 deletions src/L.Geoserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ L.Geoserver = L.FeatureGroup.extend({
transparent: true,
CQL_FILTER: "INCLUDE",
zIndex: 1000,
version: "1.1.0",
version: "",
srsname: "EPSG:4326",
attribution: `layer`,
fitLayer: true,
Expand Down Expand Up @@ -34,6 +34,11 @@ L.Geoserver = L.FeatureGroup.extend({

//wms layer function
wms: function () {

if (!this.options.version) {
this.options.version = '1.1.1';
}

return L.tileLayer.wms(this.baseLayerUrl, this.options);
},

Expand All @@ -42,13 +47,16 @@ L.Geoserver = L.FeatureGroup.extend({
wfs: function () {
var that = this;

if (!this.options.version) {
this.options.version = '1.1.0';
}
//Geoserver Web Feature Service
$.ajax(this.baseLayerUrl, {
type: "GET",

data: {
service: "WFS",
version: "1.1.0",
version: this.options.version,
request: "GetFeature",
typename: this.options.layers,
CQL_FILTER: this.options.CQL_FILTER,
Expand Down Expand Up @@ -82,8 +90,9 @@ L.Geoserver = L.FeatureGroup.extend({
if (typeof that.options.style === "function") {
for (i = 0; i < layers.length; i++) {
that.addLayer(layers[i]);
if (i.setStyle) {
i.setStyle(that.options.style(i.feature));
if (layers[i].setStyle) {
// check if setStyle method exists
layers[i].setStyle(that.options.style(layers[i].feature));
}
}
} else {
Expand All @@ -110,7 +119,7 @@ L.Geoserver = L.FeatureGroup.extend({
var legend = L.control({ position: "bottomleft" });
legend.onAdd = function (map) {
var div = L.DomUtil.create("div", "info Legend");
var url = `${that.baseLayerUrl}/wms?REQUEST=GetLegendGraphic&VERSION=1.1.0&FORMAT=image/png&LAYER=${that.options.layers}&style=${that.options.style}`;
var url = `${that.baseLayerUrl}/wms?REQUEST=GetLegendGraphic&VERSION=${that.options.version}&FORMAT=image/png&LAYER=${that.options.layers}&style=${that.options.style}`;
div.innerHTML +=
"<img src=" +
url +
Expand All @@ -124,7 +133,7 @@ L.Geoserver = L.FeatureGroup.extend({
wmsImage: function () {
var that = this;
$.ajax({
url: `${that.baseLayerUrl}/ows?service=WFS&version=1.0.0&request=GetFeature&cql_filter=${that.options.wmsCQL_FILTER[0]}&typeName=${that.options.wmsLayers[0]}&srsName=EPSG:4326&maxFeatures=50&outputFormat=text%2Fjavascript`,
url: `${that.baseLayerUrl}/ows?service=WFS&version=${that.options.version}&request=GetFeature&cql_filter=${that.options.wmsCQL_FILTER[0]}&typeName=${that.options.wmsLayers[0]}&srsName=EPSG:4326&maxFeatures=50&outputFormat=text%2Fjavascript`,
dataType: "jsonp",
jsonpCallback: "parseResponse",
success: function (data) {
Expand All @@ -144,18 +153,18 @@ L.Geoserver = L.FeatureGroup.extend({
for (var i = 1; i < that.options.wmsLayers.length; i++) {
otherLayers += that.options.wmsLayers[i];
otherStyle += that.options.wmsStyle[i];
otherCqlFilter +=that.options.wmsCQL_FILTER[i];
otherCqlFilter += that.options.wmsCQL_FILTER[i];
if (i != that.options.wmsLayers.length - 1) {
otherLayers += ",";
otherStyle += ",";
otherCqlFilter += ';';
otherCqlFilter += ";";
}
}

//final wmsLayerUrl
var wmsLayerURL = `${
that.baseLayerUrl
}/wms?service=WMS&version=1.1.0&request=GetMap&\
}/wms?service=WMS&version=1.3.0&request=GetMap&\
layers=${otherLayers}&\
styles=${otherStyle}&\
cql_filter=${otherCqlFilter}&\
Expand Down

0 comments on commit 1184630

Please sign in to comment.