123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- <!--********************************************************************
- * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
- *********************************************************************-->
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title data-i18n="resources.title_geometryBatchAnalystService"></title>
- <script type="text/javascript" src="../js/include-web.js"></script>
- </head>
- <body style="margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
- <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
- <script type="text/javascript" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
- <script type="text/javascript">
- var host = window.isLocal ? window.server : "https://iserver.supermap.io";
- var map,
- attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
- " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
- " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ",
- baseUrl = host + "/iserver/services/map-jingjin/rest/maps/京津地区地图/zxyTileImage.png?z={z}&x={x}&y={y}",
- serviceUrl = host + "/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst";
- map = new mapboxgl.Map({
- container: 'map',
- style: {
- "version": 8,
- "sources": {
- "raster-tiles": {
- "attribution": attribution,
- "type": "raster",
- "tiles": [baseUrl],
- "tileSize": 256
- }
- },
- "layers": [{
- "id": "simple-tiles",
- "type": "raster",
- "source": "raster-tiles",
- }]
- },
- center: [117, 40],
- zoom: 8
- });
- map.addControl(new mapboxgl.NavigationControl(), 'top-left');
- map.addControl(new mapboxgl.supermap.LogoControl(), 'bottom-right');
- map.on("load", function () {
- batchAnalystFromGeometry();
- });
- function batchAnalystFromGeometry() {
- //缓冲区分析数据:
- var bufferLine = {
- "type": "Feature",
- "geometry": {
- "type": "LineString",
- "coordinates": [[117, 40.50], [118, 40]]
- }
- };
- var bufferPoint = {
- "type": "Feature",
- "geometry": {
- "type": "Point",
- "coordinates": [117, 40]
- }
- };
- //叠加分析数据:
- var sourceGeometry = {
- "type": "Feature",
- "geometry": {
- "type": "Polygon",
- "coordinates": [[[116, 39.75],
- [116, 39.15],
- [117, 39.15],
- [117, 39.85],
- [116, 39.85]]]
- }
- };
- var operateGeometry = {
- "type": "Feature",
- "geometry": {
- "type": "Polygon",
- "coordinates": [[[116.25, 40.5],
- [116.25, 38.5],
- [116.75, 38.5],
- [116.75, 40.5],
- [116.25, 40.5]]]
- }
- };
- //数据加载到地图:
- map.addSource("analystSource", {
- "type": "geojson",
- "data": {
- "type": "FeatureCollection",
- "features": [bufferLine, bufferPoint, sourceGeometry, operateGeometry]
- }
- });
- //绘制缓冲区线
- map.addLayer({
- "id": "bufferLine",
- "type": "line",
- "source": "analystSource",
- "layout": {
- "line-join": "round",
- "line-cap": "round"
- },
- "paint": {
- "line-color": "red",
- "line-width": 4
- },
- "filter": ["==", "$type", "LineString"]
- });
- //绘制缓冲区点
- map.addLayer({
- "id": "bufferPoint",
- "type": "circle",
- "source": "analystSource",
- "paint": {
- "circle-radius": 6, /* 圆的直径,单位像素 */
- "circle-color": "blue", /* 圆的颜色 */
- },
- "filter": ["==", "$type", "Point"],
- });
- //绘制叠加分析面:
- map.addLayer({
- "id": "overlayPolygon",
- "type": "fill",
- "source": "analystSource",
- 'paint': {
- 'fill-outline-color': 'blue',
- 'fill-color': 'rgba(0, 0, 255, 0.1)'
- },
- "filter": ["==", "$type", "Polygon"],
- });
- //缓冲区分析参数
- var geoBufferAnalystParams = {
- analystName: "buffer",
- param: new SuperMap.GeometryBufferAnalystParameters({
- sourceGeometry: bufferLine,
- sourceGeometrySRID: 4326,
- bufferSetting: new SuperMap.BufferSetting({
- endType: SuperMap.BufferEndType.ROUND,
- leftDistance: new SuperMap.BufferDistance({value: 5000}),
- rightDistance: new SuperMap.BufferDistance({value: 5000}),
- radiusUnit: "METER",
- semicircleLineSegment: 10
- })
- })
- };
- var geoBufferAnalystParams_Point = {
- analystName: "buffer",
- param: new SuperMap.GeometryBufferAnalystParameters({
- sourceGeometry: bufferPoint,
- sourceGeometrySRID: 4326,
- bufferSetting: new SuperMap.BufferSetting({
- endType: SuperMap.BufferEndType.ROUND,
- leftDistance: new SuperMap.BufferDistance({value: 10000}),
- rightDistance: new SuperMap.BufferDistance({value: 10000}),
- radiusUnit: "METER",
- semicircleLineSegment: 10
- })
- })
- };
- //叠加分析参数
- var OverlayBatchAnalystParameters = {
- analystName: "overlay",
- param: new SuperMap.GeometryOverlayAnalystParameters({
- sourceGeometry: sourceGeometry,
- operateGeometry: operateGeometry,
- operation: SuperMap.OverlayOperationType.CLIP
- })
- };
- //批量分析参数
- var paramter = [geoBufferAnalystParams, OverlayBatchAnalystParameters, geoBufferAnalystParams_Point];
- //批量分析
- new mapboxgl.supermap.SpatialAnalystService(serviceUrl).geometrybatchAnalysis(paramter, function (serviceResult) {
- //结果展示
- map.addSource("bufferResultLine", {
- "type": "geojson",
- "data": {
- "type": "FeatureCollection",
- "features": [
- serviceResult.result[0].resultGeometry,
- ]
- }
- });
- map.addSource("bufferResultPoint", {
- "type": "geojson",
- "data": {
- "type": "FeatureCollection",
- "features": [
- serviceResult.result[2].resultGeometry,
- ]
- }
- });
- map.addSource("overlayResult", {
- "type": "geojson",
- "data": {
- "type": "FeatureCollection",
- "features": [
- serviceResult.result[1].resultGeometry,
- ]
- }
- });
- map.addLayer({
- "id": "bufferResultLayer_line",
- "type": "fill",
- "source": "bufferResultLine",
- "paint": {
- "fill-color": "red", /* 填充的颜色 */
- "fill-opacity": 0.4 /* 透明度 */
- },
- });
- map.addLayer({
- "id": "bufferResultLayer_point",
- "type": "fill",
- "source": "bufferResultPoint",
- "paint": {
- "fill-color": "red", /* 填充的颜色 */
- "fill-opacity": 0.4 /* 透明度 */
- },
- });
- map.addLayer({
- "id": "overlayResultLayer",
- "type": "fill",
- "source": "overlayResult",
- "paint": {
- "fill-color": "red", /* 填充的颜色 */
- "fill-opacity": 0.4 /* 透明度 */
- },
- });
- var bufferPop = new mapboxgl.Popup()
- .setLngLat([117.15, 40.45])
- .setHTML("<h4>" + resources.text_bufferAnalystResult + "</h4>");
- var overlayPop = new mapboxgl.Popup()
- .setLngLat([116.35, 39.75])
- .setHTML("<h4>" + resources.text_overlayAnalystResult + "</h4>");
- map.on('mouseenter', 'bufferResultLayer_line', function (e) {
- bufferPop.remove();
- map.getCanvas().style.cursor = 'pointer';
- bufferPop.setLngLat([117.5, 40.25])
- .setHTML("<h4>" + resources.text_bufferAnalystResult + "</h4>")
- .addTo(map);
- });
- map.on('mouseleave', 'bufferResultLayer_line', function () {
- map.getCanvas().style.cursor = '';
- bufferPop.remove();
- });
- map.on('mouseenter', 'bufferResultLayer_point', function (e) {
- bufferPop.remove();
- map.getCanvas().style.cursor = 'pointer';
- bufferPop.setLngLat([117, 40])
- .setHTML("<h4>" + resources.text_bufferAnalystResult + "</h4>")
- .addTo(map);
- });
- map.on('mouseleave', 'bufferResultLayer_point', function () {
- map.getCanvas().style.cursor = '';
- bufferPop.remove();
- });
- map.on('mouseenter', 'overlayResultLayer', function (e) {
- map.getCanvas().style.cursor = 'pointer';
- overlayPop.setLngLat([116.5, 39.5])
- .setHTML("<h4>" + resources.text_overlayAnalystResult + "</h4>")
- .addTo(map);
- });
- map.on('mouseleave', 'overlayResultLayer', function () {
- map.getCanvas().style.cursor = '';
- overlayPop.remove();
- });
- });
- }
- </script>
- </body>
- </html>
|