maptalks.esri
A plugin to load ArcGIS service.
Demo
Install
npm i maptalks.esri --save
Usage
In Browser
<script src="https://unpkg.com/maptalks/dist/maptalks.js"></script>
<script src="https://unpkg.com/maptalks.esri/dist/maptalks.esri.js"></script>
<script type="text/javascript">
const service = new maptalks.esri.FeatureLayerService();
const service1 = new maptalks.esri.ImageLayerService();
</script>
ESM Module
import { FeatureLayerService, ImageLayerService } from 'maptalks.esri';
const service = new FeatureLayerService();
const service1 = new ImageLayerService();
Code samples
Load FeatureLayer Service
const service = new maptalks.esri.FeatureLayerService({
url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/Earthquakes_Since1970/MapServer/0',
symbol: {
markerType: 'ellipse',
markerWidth: 12,
markerHeight: 12,
markerFill: '#f00',
markerFillOpacity: 0.5,
markerLineColor: '#000',
markerLineWidth: 2
}
});
const pointLayer = new maptalks.PointLayer('polygon');
const groupLayer = new maptalks.GroupGLLayer('group', [pointLayer]).addTo(map);
function query() {
const extent = map.getExtent();
const geometry = [extent.xmin, extent.ymin, extent.xmax, extent.ymax].join(',');
service.query({
geometry: geometry,
geometryType: 'esriGeometryEnvelope'
}).then(json => {
json = JSON.parse(json);
console.log('fetures count:', json.features.length);
const geometries = service.toGeometry(json);
pointLayer.clear();
pointLayer.addGeometry(geometries);
});
}
map.on('viewchange', query);
query();
Load Image Map Service
var service = new maptalks.esri.ImageLayerService({
url: 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/PoolPermits/MapServer/export',
debug: true,
map,
});
var imageLayer = new maptalks.ImageLayer('imagemaplayer');
map.addLayer(imageLayer);
function query() {
service.query().then(json => {
json = JSON.parse(json);
if (json.href) {
const extent = map.getExtent();
const geometry = [extent.xmin, extent.ymin, extent.xmax, extent.ymax];
imageLayer.setImages([{
url: json.href,
extent: geometry
}]);
}
})
}
map.on('viewchange', query);
query();