如何解决如何获取图层的几何类型?
我正在制作这样的图层:
// Vector source for geoserver services
const vectorSource = (layer) => {
return new ol.source.Vector({
format: new ol.format.GeoJSON(),url: (extent) => {
return (`http://localhost:8080/geoserver/Bugra/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=Bugra:${layer}&outputFormat=application/json&srsname=EPSG:3857&bbox=${extent.join(',')},EPSG:3857`);
},strategy: ol.loadingstrategy.bbox,})
};
,然后再使用一个:
// Layer creating class
class LayerCreator {
constructor(
lyrName,lyrGeoServerName,lyrStrokeColor,lyrStrokeWidth,lyrFillColor,lyrOpacity,lyrPointRadius,lyrMinZoom,lyrMaxZoom,lyrLabelField,lyrFontFamily,lyrFontFillColor,lyrFontStrokeColor,lyrFontStrokeWidth,lyrFontBold,lyrFontSize,lyrFontPlacement,lyrFontOffsetY) {
return new ol.layer.Vector({
className: `${lyrName}-${lyrGeoServerName}`,source: vectorSource(lyrGeoServerName),style: function text(feature) {
return new ol.style.Style({
stroke: new ol.style.Stroke({
color: lyrStrokeColor,width: lyrStrokeWidth,}),fill: new ol.style.Fill({
color: lyrFillColor
}),image: new ol.style.Circle({
radius: lyrPointRadius,fill: new ol.style.Fill({
color: lyrFillColor
}),stroke: new ol.style.Stroke({
color: lyrStrokeColor,})
}),text: new ol.style.Text({
text: feature.get(lyrLabelField),font: `${lyrFontBold} ${lyrFontSize}px ${lyrFontFamily}`,fill: new ol.style.Fill({
color: lyrFontFillColor,stroke: new ol.style.Stroke({
color: lyrFontStrokeColor,width: lyrFontStrokeWidth,placement: lyrFontPlacement,offsetY: lyrFontOffsetY
}),})
},opacity: lyrOpacity,minZoom: lyrMinZoom,maxZoom: lyrMaxZoom,});
}
}
问题是,我得到了一个Draw小部件,并且您知道它需要一个“ type”值才能知道它将创建的几何类型。我得到了一个与上面创建的所有10层组合框。它们是ol.layer.Vector类型的对象。因此,我必须根据我从组合框中选择的图层的几何类型来动态更改Draw Widget的“类型”值。如果它的类型为“ MultiPolygon”,则必须将其作为“类型:“ MultiPolygon””发送给Draw小部件,但我无法从ol.layer.Vector对象中获取几何类型。
您能帮我吗?
解决方法
麦克再次回答了这个问题。
layer.getSource()。getFeatures()[0] .getGeometry()。getType()为您提供图层的几何类型(因为图层可以混合使用类型)
,如果您想正确执行此操作,可以提出一个DescribeFeature
请求,该请求将为您提供要素类型的完整架构,包括几何类型。
例如:
http://localhost:8080/geoserver-2.17.2/ows?service=wfs&version=1.1.0&request=DescribeFeatureType&typeName=topp:states
返回:
<?xml version="1.0" encoding="UTF-8"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" xmlns:topp="http://www.openplans.org/topp" elementFormDefault="qualified" targetNamespace="http://www.openplans.org/topp">
<xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://localhost:8080/geoserver-2.17.2/schemas/gml/3.1.1/base/gml.xsd"/>
<xsd:complexType name="statesType">
<xsd:complexContent>
<xsd:extension base="gml:AbstractFeatureType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="the_geom" nillable="true" type="gml:MultiSurfacePropertyType"/>
<xsd:element maxOccurs="1" minOccurs="0" name="STATE_NAME" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="STATE_FIPS" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="SUB_REGION" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="STATE_ABBR" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="LAND_KM" nillable="true" type="xsd:double"/>
<xsd:element maxOccurs="1" minOccurs="0" name="WATER_KM" nillable="true" type="xsd:double"/>
<xsd:element maxOccurs="1" minOccurs="0" name="PERSONS" nillable="true" type="xsd:double"/>
<xsd:element maxOccurs="1" minOccurs="0" name="FAMILIES" nillable="true" type="xsd:double"/>
<xsd:element maxOccurs="1" minOccurs="0" name="HOUSHOLD" nillable="true" type="xsd:double"/>
<xsd:element maxOccurs="1" minOccurs="0" name="MALE" nillable="true" type="xsd:double"/>
<xsd:element maxOccurs="1" minOccurs="0" name="FEMALE" nillable="true" type="xsd:double"/>
<xsd:element maxOccurs="1" minOccurs="0" name="WORKERS" nillable="true" type="xsd:double"/>
<xsd:element maxOccurs="1" minOccurs="0" name="DRVALONE" nillable="true" type="xsd:double"/>
<xsd:element maxOccurs="1" minOccurs="0" name="CARPOOL" nillable="true" type="xsd:double"/>
<xsd:element maxOccurs="1" minOccurs="0" name="PUBTRANS" nillable="true" type="xsd:double"/>
<xsd:element maxOccurs="1" minOccurs="0" name="EMPLOYED" nillable="true" type="xsd:double"/>
<xsd:element maxOccurs="1" minOccurs="0" name="UNEMPLOY" nillable="true" type="xsd:double"/>
<xsd:element maxOccurs="1" minOccurs="0" name="SERVICE" nillable="true" type="xsd:double"/>
<xsd:element maxOccurs="1" minOccurs="0" name="MANUAL" nillable="true" type="xsd:double"/>
<xsd:element maxOccurs="1" minOccurs="0" name="P_MALE" nillable="true" type="xsd:double"/>
<xsd:element maxOccurs="1" minOccurs="0" name="P_FEMALE" nillable="true" type="xsd:double"/>
<xsd:element maxOccurs="1" minOccurs="0" name="SAMP_POP" nillable="true" type="xsd:double"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="states" substitutionGroup="gml:_Feature" type="topp:statesType"/>
</xsd:schema>
因此该层包含gml:MultiSurfacePropertyType
或对您和我来说都是MultiPolygons。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。