Клиентский уровень OGC WFS-T для буклета.
Через НПМ:
npm i leaflet-wfst --save
Через Бауэр:
bower i leaflet-wfst --save
Из ГитХаба:
npm i -S git://github.com/Flexberry/Leaflet-WFST.git#v1.1.1
где #v1.1.1 — версия конкретного выпуска.
options: {
crs : L . CRS . EPSG3857 ,
showExisting : true ,
geometryField : 'Shape' ,
url : '' ,
typeNS : '' ,
typeName : '' ,
opacity : 1 ,
style : {
color : 'black' ,
weight : 1
}
}
const wfstPointOptions = {
crs : L . CRS . EPSG4326 ,
showExisting : true ,
geometryField : 'geom' ,
url : `http://localhost:8080/geoserver/wfs` ,
typeNS : 'test' ,
typeName : 'test' ,
maxFeatures : 90 ,
opacity : 1 ,
style : function ( layer ) {
// you can use if statemt etc
return {
color : 'black' ,
weight : 1
}
} ,
} ;
const wfstPoint = new L . WFST ( wfstPointOptions , new L . Format . GeoJSON ( {
crs : L . CRS . EPSG4326 ,
pointToLayer ( geoJsonPoint , latlng ) {
const layer = new L . CircleMarker ( latlng , {
radius : 10 ,
} ) ;
return layer ;
} ,
} ) ) ;
wfstPoint . addTo ( map ) ;
имя опции | по умолчанию | комментарий |
---|---|---|
крс | Л.CRS.EPSG3857 | система пространственной привязки для слоя должна реализовывать ICRS, например Proj4Leaflet |
показатьСуществующий | истинный | загрузить существующие объекты в слой создания |
ГеометрияПоле | 'Форма' | поле для хранения геометрии, для нетранзакционных сервисов можно опустить |
URL | - | URL-адрес WFS, например http://demo.opengeo.org/geoserver/osm/ows |
типNS | - | тип пространства имен |
ТипИмя | - | введите имя |
типNSName | - | введите имя пространства имен |
Uri пространства имен | - | URI пространства имен |
непрозрачность | 1 | непрозрачность слоя |
стиль | - | векторный стиль листовки. функция или объект |
фильтр | - | любой фильтр. см. фильтр |
maxFeatures | - | ограничить количество возвращаемых функций |
var map = L . map ( 'map' ) . setView ( [ 0 , 0 ] , 2 ) ;
var boundaries = new L . WFS ( {
url : 'http://demo.opengeo.org/geoserver/ows' ,
typeNS : 'topp' ,
typeName : 'tasmania_state_boundaries' ,
crs : L . CRS . EPSG4326 ,
style : {
color : 'blue' ,
weight : 2
}
} ) . addTo ( map )
. on ( 'load' , function ( ) {
map . fitBounds ( boundaries ) ;
} )
Расширяет классы листовок с помощью функции toGml(crs):
Запускает два типа событий:
Геометрия маркеров записывается как posNode, геометрия всех остальных слоев записывается как posList.
Реализация кодирования фильтра OGC v1.1.0
Реализации фильтра возвращают только внутреннее содержимое фильтрующего элемента.
Некоторые соображения для всех конструкторов фильтров:
Имя | Конструктор |
---|---|
ИДЕНТИФИКАТОР | |
ГмлОбжектид | L.Filter.GmlObjectId(идентификатор значения) |
Сравнения | |
СвойствоIsEqualTo | L.Filter.EQ(propertyExpression firstArgument, literalExpression SecondArgument, bool matchCase) |
СвойствоIsNotEqualTo | L.Filter.NotEQ(propertyExpression firstArgument, literalExpression SecondArgument, bool matchCase) |
СвойствоIsLessThan | L.Filter.LT(propertyExpression firstArgument, literalExpression SecondArgument, bool matchCase) |
СвойствоIsGreaterThan | L.Filter.GT(propertyExpression firstArgument, literalExpression SecondArgument, bool matchCase) |
СвойствоIsLessThanOrEqualTo | L.Filter.LEQ(propertyExpression firstArgument, literalExpression SecondArgument, bool matchCase) |
СвойствоIsGreaterThanOrEqualTo | L.Filter.GEQ(propertyExpression firstArgument, literalExpression SecondArgument, bool matchCase) |
СвойствоIsLike | L.Filter.Like(строка имя_свойства, строка LikeExpression, атрибуты объекта) |
СвойствоIsNull | L.Filter.IsNull(строковое имя свойства) |
СвойствоIsBetween | L.Filter.IsBetween(propertyExpression firstArgument, literalExpression LowerBoundary, literalExpression UpperBoundary) |
Операторы | |
Добавлять | L.Filter.Add(выражение, выражение) |
Саб | L.Filter.Sub(выражение, выражение) |
Мул | L.Filter.Mul(выражение, выражение) |
Див | L.Filter.Div(выражение, выражение) |
Логика | |
И | L.Filter.And(выражение[, выражение]*) |
Или | L.Filter.Or(выражение[, выражение]*) |
Нет | L.Filter.Not(выражение) |
Пространственный | |
БиБокс | L.Filter.BBox(string propertyName, границы latLngBounds, ICRS crs) |
Равно | L.Filter.Equals(строковое имя свойства, геометрия слоя, ICRS crs) |
Непересекающийся | L.Filter.Disjoint(строковое имя свойства, геометрия слоя, ICRS crs) |
Прикосновения | L.Filter.Touches(строковое имя свойства, геометрия слоя, ICRS crs) |
В пределах | L.Filter.Within(строковое имя свойства, геометрия слоя, ICRS crs) |
Перекрытия | L.Filter.Overlaps(строковое имя свойства, геометрия слоя, ICRS crs) |
Кресты | L.Filter.Crosses(строковое имя свойства, геометрия слоя, ICRS crs) |
Пересекается | L.Filter.Intersects(строковое имя свойства, геометрия слоя, ICRS crs) |
Содержит | L.Filter.Contains(строковое имя свойства, геометрия слоя, ICRS crs) |
Пространственный буфер расстояний | |
DВнутри | L.Filter.DWithin(string propertyName, геометрия слоя, ICRS crs, расстояние значения, строковые единицы) |
Вне | L.Filter.Beyond(имя свойства строки, геометрия слоя, ICRS crs, расстояние значения, строковые единицы) |
Другой | |
Функция | L.Filter.Function(строка имя_функции[, выражение]*) |
ИмяСвойства | L.Filter.propertyName(имя строки) |
Буквальный | L.Filter.literal(значение) |
PropertyName и Literal являются функциями и напрямую возвращают Gml.
В стандарте есть два фильтра — GmlObjectID и FeatureID, но последний помечен как устаревший и поэтому не реализован.
Пример:
var filter = new L . Filter . GmlObjectID ( 1 ) ;
результат xml:
< ogc : Filter xmlns : ogc = " http://www.opengis.net/ogc " >
< ogc : GmlObjectId xmlns : gml = " http://www.opengis.net/gml " gml : id = " 1 " />
</ ogc : Filter >
var filter = new L . Filter . EQ ( 'city' , 'Perm' ) ;
filter . toGml ( )
результат xml:
< ogc : PropertyIsEqualTo >
< ogc : PropertyName >city</ ogc : PropertyName >
< ogc : Literal >Perm</ ogc : Literal >
</ ogc : PropertyIsEqualTo >
Этот фильтр принимает объект необязательных атрибутов:
attributes: {
wildCard : '*' ,
singleChar : '#' ,
escapeChar : '!' ,
matchCase : true
}
var filter = new L . Filter . Like ( 'city' , '*perm*' , { matchCase : false } ) ;
filter . toGml ( )
результат xml:
< ogc : ogc:PropertyIsLike wildCard = " * " singleChar = " # " escapeChar = " ! " matchCase = " false " >
< ogc : PropertyName >city</ ogc : PropertyName >
< ogc : Literal >*perm*</ ogc : Literal >
</ ogc : ogc:PropertyIsLike >
Пример:
var filter = new L . Filter . BBox ( 'ogr_geometry' , L . latLngBounds ( L . latLng ( 40.712 , - 74.227 ) , L . latLng ( 40.774 , - 74.125 ) ) , L . CRS . EPSG4326 ) ;
filter . toGml ( )
результат xml:
< ogc : Filter xmlns : ogc = " http://www.opengis.net/ogc " >
< ogc : BBOX >
< ogc : PropertyName >ogr_geometry</ ogc : PropertyName >
< gml : Envelope xmlns : gml = " http://www.opengis.net/gml " srsName = " EPSG:4326 " >
< gml : lowerCorner >-74.227 40.712</ gml : lowerCorner >
< gml : upperCorner >-74.125 40.774</ gml : upperCorner >
</ gml : Envelope >
</ ogc : BBOX >
</ ogc : Filter >
Пример:
var filter = new L . Filter . Intersects ( 'ogr_geometry' , L . polygon ( [ L . latLng ( 40.712 , - 74.227 ) , L . latLng ( 40.774 , - 74.125 ) , L . latLng ( 40.734 , - 74.175 ) ] ) , L . CRS . EPSG4326 ) ;
filter . toGml ( ) ;
результат xml:
< ogc : Filter xmlns : ogc = " http://www.opengis.net/ogc " >
< ogc : Intersects >
< ogc : PropertyName >ogr_geometry</ ogc : PropertyName >
< gml : Polygon xmlns : gml = " http://www.opengis.net/gml " srsName = " EPSG:4326 " srsDimension = " 2 " >
< gml : exterior >
< gml : LinearRing srsDimension = " 2 " >
< gml : posList >-74.227 40.712 -74.125 40.774 -74.175 40.734 -74.227 40.712</ gml : posList >
</ gml : LinearRing >
</ gml : exterior >
</ gml : Polygon >
</ ogc : Intersects >
</ ogc : Filter >
Плагин редактирования — Leaflet.Editable
L . WFST . include ( MultiEditableMixin ) ;
var wfst = new L . WFST ( {
url : 'http://myserver/geoserver/ows' ,
typeNS : 'myns' ,
typeName : 'POIPOINT' ,
style : {
color : 'blue' ,
weight : 2
}
} ) . addTo ( map ) . once ( 'load' , function ( ) {
map . fitBounds ( wfst ) ;
wfst . enableEdit ( ) ;
} ) ;
map . on ( 'editable:created' , function ( e ) {
wfst . addLayer ( e . layer ) ;
} ) ;
map . on ( 'editable:editing' , function ( e ) {
wfst . editLayer ( e . layer ) ;
} ) ;
чтобы сделать вызов POST-запроса "wfs:Transaction" методом save(), пример с Leaflet.EasyButton
L . easyButton ( 'fa-save' , function ( ) {
wfst . save ( ) ;
} , 'Save changes' ) ;
//simple layer
layer = new L . Marker ( [ 0 , 0 ] ) ;
layer . feature = {
id : 1 ,
properties : {
a : 'a' ,
b : 'b'
}
} ;
//get value by key 'a'
var a = layer . getProperty ( 'a' ) ;
//change values
layer . setProperties ( {
a : 'b' ,
b : 'a'
} ) ;
//add new property
layer . setProperties ( {
c : 'c'
} ) ;
//delete properties
layer . deleteProperties ( [ 'a' , 'b' , 'c' ] ) ;
демо для формата чтения GML
демо для формата чтения GeoJSON
демонстрационный фильтр bbox
Лицензия MIT