Skip to content

Commit 924a2e7

Browse files
committed
feat: Add support for ArcGIS Feature Service
1 parent fa7e2f9 commit 924a2e7

File tree

3 files changed

+89
-3
lines changed

3 files changed

+89
-3
lines changed

src/LayersControl.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ export function SourceControl() {
123123
return [
124124
'url',
125125
'projection',
126-
// Add other relevant source parameters for arcgis-vector-tiles here
126+
];
127+
case 'arcgis-feature-service':
128+
return [
129+
'url',
130+
'projection',
127131
];
128132
default:
129133
return [] // Empty configuration for unsupported types
@@ -169,6 +173,7 @@ var LayerObjectOption = new MultiCompBuilder(
169173
{ label: "MVT", value: "mvt" },
170174
{ label: "Mapbox StyleGL", value: "stylegl" },
171175
{ label: "ArcGIS Mapserver", value: "arcgis-mapserver" },
176+
{ label: "ArcGIS Feature Service", value: "arcgis-feature-service" },
172177
{ label: "ArcGIS Vector Tiles", value: "arcgis-vector-tiles" },
173178
{ label: "PMTiles", value: "pmtiles" },
174179
]),

src/i18n/comps/locales/enObj.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ import { I18nObjects } from "./types";
22

33
export const enObj: I18nObjects = {
44
defaultData: [
5+
{
6+
"label": "ArcGIS Feature Servies",
7+
"title": "ArcGIS Feature Servies",
8+
"type": "arcgis-feature-service",
9+
"order": 11,
10+
"minZoom": 0,
11+
"maxZoom": 22,
12+
"visible": true,
13+
"selectable": true,
14+
"source": {
15+
"url": "https://services-eu1.arcgis.com/NPIbx47lsIiu2pqz/ArcGIS/rest/services/Neptune_Coastline_Campaign_Open_Data_Land_Use_2014/FeatureServer/0",
16+
}
17+
},
518
{
619
"label": "ArcGIS - Vector Tile PBF",
720
"title": "ArcGIS - Vector Tile PBF",

src/vendors/helpers/Layers.js

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ import { geoJsonStyleFunction } from './Styles'
1919
import { applyBackground, applyStyle } from 'ol-mapbox-style';
2020
import UndoRedo from 'ol-ext/interaction/UndoRedo'
2121
import EsriPBF from "./EsriPBF.js";
22+
import EsriJSON from 'ol/format/EsriJSON.js';
2223
import { createStyleFunctionFromUrl } from 'ol-esri-styles';
24+
import { tile as tileStrategy } from 'ol/loadingstrategy.js';
25+
import { createXYZ } from 'ol/tilegrid.js';
2326

2427
/**
2528
* Creates and returns an OpenLayers layer instance for the given layer configuration object.
@@ -308,13 +311,78 @@ export function createLayer(layerConfig, map) {
308311
) +
309312
'&geometryType=esriGeometryEnvelope&inSR=3857&outFields=*&resultType=tile' +
310313
'&outSR=3857',
314+
strategy: tileStrategy(
315+
createXYZ({
316+
tileSize: [512, 512],
317+
}),
318+
),
311319
}),
312320
})
313321
createStyleFunctionFromUrl(layerConfig.source.url, map.getView().getProjection() || 'EPSG:3857').then(styleFunction => {
314-
esriVectorTiles.setStyle(styleFunction)
315-
console.log(styleFunction);
322+
esriVectorTiles.setStyle(styleFunction);
316323
});
317324
return esriVectorTiles;
325+
case 'arcgis-feature-service':
326+
const esriFeatureService = new VectorLayer({
327+
name: layerConfig.label,
328+
title: layerConfig.title || layerConfig.name,
329+
minZoom: layerConfig.minZoom,
330+
maxZoom: layerConfig.maxZoom,
331+
visible: layerConfig.visible,
332+
opacity: layerConfig.opacity,
333+
selectable: layerConfig.selectable,
334+
groups: layerConfig.groups,
335+
extra: layerConfig.extra,
336+
order: layerConfig.order,
337+
splitscreen: layerConfig.splitscreen,
338+
displayInLayerSwitcher: layerConfig.userVisible,
339+
source: new VectorSource({
340+
format: new EsriJSON(),
341+
url: function (extent, resolution, projection) {
342+
// ArcGIS Server only wants the numeric portion of the projection ID.
343+
const srid = projection
344+
.getCode()
345+
.split(/:(?=\d+$)/)
346+
.pop();
347+
348+
const url =
349+
layerConfig.source.url +
350+
'/query/?f=json&' +
351+
'returnGeometry=true&spatialRel=esriSpatialRelIntersects&geometry=' +
352+
encodeURIComponent(
353+
'{"xmin":' +
354+
extent[0] +
355+
',"ymin":' +
356+
extent[1] +
357+
',"xmax":' +
358+
extent[2] +
359+
',"ymax":' +
360+
extent[3] +
361+
',"spatialReference":{"wkid":' +
362+
srid || '3857' +
363+
'}}',
364+
) +
365+
'&geometryType=esriGeometryEnvelope&inSR=' +
366+
srid || '3857' +
367+
'&outFields=*' +
368+
'&outSR=' +
369+
srid || '3857';
370+
371+
return url;
372+
},
373+
strategy: tileStrategy(
374+
createXYZ({
375+
tileSize: [512, 512],
376+
}),
377+
),
378+
})
379+
});
380+
createStyleFunctionFromUrl("https://services-eu1.arcgis.com/NPIbx47lsIiu2pqz/ArcGIS/rest/services/Neptune_Coastline_Campaign_Open_Data_Land_Use_2014/FeatureServer/0", map.getView().getProjection() || 'EPSG:3857').then(styleFunction => {
381+
esriFeatureService.setStyle(styleFunction);
382+
});
383+
384+
return esriFeatureService;
385+
318386

319387
/* History ?
320388
new ol.layer.Geoportail({

0 commit comments

Comments
 (0)