Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style Function Not Work In WFS #16

Merged
merged 4 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
iamtekson marked this conversation as resolved.
Show resolved Hide resolved
// 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