Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
205 lines (170 sloc) 8 KB
<!DOCTYPE html>
<html lang="en">
<head>
<title>WFS filter example - Azure Maps Web SDK Samples</title>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="IE=Edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="This is a simple tool for exploring WFS services on Azure Maps." />
<meta name="keywords" content="Microsoft maps, map, gis, API, SDK, WFS, web feature service, ogc, spatial data, spatial io module" />
<meta name="author" content="Microsoft Azure Maps" />
<!-- Add references to the Azure Maps Map control JavaScript and CSS files. -->
<link rel="stylesheet" href="https://atlas.microsoft.com/sdk/javascript/mapcontrol/2/atlas.min.css" type="text/css" />
<script src="https://atlas.microsoft.com/sdk/javascript/mapcontrol/2/atlas.min.js"></script>
<!-- Add reference to the Azure Maps Spatial IO module. -->
<script src="https://atlas.microsoft.com/sdk/javascript/spatial/0/atlas-spatial.min.js"></script>
<script type='text/javascript'>
var map, client, layer, f;
function GetMap() {
//Point the Azure Maps domain to the US Azure Gov Cloud domain.
atlas.setDomain('atlas.azure.us');
//Initialize a map instance.
map = new atlas.Map('myMap', {
view: 'Auto',
//Add your Azure Maps subscription key to the map SDK. Get an Azure Maps key at https://azure.com/maps
authOptions: {
authType: 'subscriptionKey',
subscriptionKey: '<Your Azure Maps Key>'
}
});
//Create the WFS client to access the service.
client = new atlas.io.ogc.WfsClient({
url: 'https://giswebservices.massgis.state.ma.us/geoserver/wfs?request=GetCapabilities&service=WFS'
});
//Wait until the map resources are ready.
map.events.add('ready', function () {
//Cache a reference to the filters namespace for shorter filter creation code later.
f = atlas.io.ogc.filter;
//Create a data source and add it to the map.
datasource = new atlas.source.DataSource();
map.sources.add(datasource);
//Add a simple data layer for rendering the data.
layer = new atlas.layer.SimpleDataLayer(datasource);
map.layers.add(layer);
});
}
function getFirst500() {
//Retrieve the first 500 results.
processQuery({
typeNames: 'massgis:GISDATA.CENSUS1990BLOCKGROUPS_POLY',
count: 500
});
}
function getNext500() {
//Page to the next 500 results.
processQuery({
typeNames: 'massgis:GISDATA.CENSUS1990BLOCKGROUPS_POLY',
count: 500,
startIndex: 500
});
}
function idFilter() {
//Get feature by ID.
processQuery({
typeNames: 'massgis:GISDATA.CENSUS1990BLOCKGROUPS_POLY',
featureId: 'GISDATA.CENSUS1990BLOCKGROUPS_POLY.4389'
});
}
function propertyFilter1() {
//Logic based filter: if(pop100/1000 > 2 && households >= 500)
processQuery({
typeNames: 'massgis:GISDATA.CENSUS1990BLOCKGROUPS_POLY',
filter:
new f.And(
new f.IsGreaterThan(new f.Div(new f.PropertyName('pop100'), 1000), 2),
new f.IsGreaterThanOrEqual(new f.PropertyName('households'), 500)
)
});
}
function propertyFilter2() {
//Multiple property value filters.
//https://wiki.state.ma.us/display/massgis/GeoServer+-+WFS+-+Filter+-+Get+Subset+of+Attribute+Values+for+a+Feature+-+Complex+Filter
processQuery({
typeNames: 'massgis:GISDATA.SCHOOLS_PT',
filter:
new f.And(
new f.IsEqual(new f.PropertyName('type'), 'CHA'),
new f.IsEqual(new f.PropertyName('town'), 'SPRINGFIELD'),
new f.IsLike(new f.PropertyName('grades'), '*K*'),
new f.IsLike(new f.PropertyName('grades'), '*12*')
)
});
}
function propertyFilter3() {
//Value is within a range filter.
//https://wiki.state.ma.us/display/massgis/GeoServer+-+WFS+-+Filter+-+PropertyIsBetween
processQuery({
typeNames: 'massgis:GISDATA.TOWNS_POLYM',
filter: new f.IsBetween(new f.PropertyName('pop2000'), 5000, 6000)
});
}
function propertyFilter4() {
//Property value filter.
//https://wiki.state.ma.us/display/massgis/GeoServer+-+WFS+-+Get+Shape+Coordinates+for+Feature
processQuery({
typeNames: 'massgis:GISDATA.TOWNS_POLY',
propertyName: 'shape',
filter: new f.IsEqual(new f.PropertyName('town'), 'HANCOCK')
});
}
function bboxFilter1() {
//Bounding box filter.
processQuery({
typeNames: 'massgis:GISDATA.CENSUS1990BLOCKGROUPS_POLY',
bbox: [-71.16686, 42.35918, -71.03708, 42.420035]
});
}
function cqlFilter() {
//A CQL filter.
processQuery({
typeNames: 'massgis:GISDATA.SCHOOLS_PT',
cql_filter: "BBOX(shape,45004,909195,55684,932912)"
});
}
function customFilter() {
//A custom XML filter.
processQuery({
typeNames: 'massgis:GISDATA.TOWNS_POLY',
filter: new f.CustomFilter('<Filter><PropertyIsEqualTo><PropertyName>town</PropertyName><Literal>HANCOCK</Literal></PropertyIsEqualTo></Filter>')
});
}
function processQuery(featureRequest) {
datasource.clear();
//Request features using the filtered request.
client.getFeatures(featureRequest).then(fc => {
if (fc) {
//Set the view of the map over the data.
if (fc.bbox) {
map.setCamera({ bounds: fc.bbox, padding: 50 });
}
//Update data in the data source.
datasource.setShapes(fc);
}
}, error => {
alert(error);
});
}
</script>
</head>
<body onload="GetMap()">
<div id="myMap" style="position:relative;width:100%;min-width:290px;height:600px;"></div><div id="myMap"></div>
<fieldset style="width:calc(100% - 30px);min-width:290px;margin-top:10px;">
<legend><h1 style="font-size:16px">WFS filter example</h1></legend>
This sample shows how to easily query a Web Feature Service (WFS) and overlay the results on a map.
<br /><br />
<input type="button" value="Get first 500" onclick="getFirst500()" />
<input type="button" value="Get second 500" onclick="getFirst500()" />
<input type="button" value="ID filter" onclick="idFilter()" />
<br /><br />
<input type="button" value="Logic based filter" onclick="propertyFilter1()" />
<input type="button" value="Multiple property value filters" onclick="propertyFilter2()" />
<input type="button" value="Value is within a range filter" onclick="propertyFilter3()" />
<input type="button" value="Property value filter" onclick="propertyFilter4()" />
<br /><br />
<input type="button" value="BBox filter" onclick="bboxFilter1()" />
<br /><br />
<input type="button" value="CQL filter" onclick="cqlFilter()" />
<input type="button" value="Custom filter" onclick="customFilter()" />
</fieldset>
</body>
</html>
You can’t perform that action at this time.