123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <!--********************************************************************
- * 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_geometryOverlayBatchAnalystService"></title>
- <script type="text/javascript" src="../js/include-web.js"></script>
- <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
- <style>
- .ol-popup {
- position: absolute;
- background-color: white;
- -webkit-filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
- filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
- padding: 15px;
- border-radius: 10px;
- border: 1px solid #cccccc;
- bottom: 12px;
- left: -50px;
- min-width: 130px;
- }
- .ol-popup:after, .ol-popup:before {
- top: 100%;
- border: solid transparent;
- content: " ";
- height: 0;
- width: 0;
- position: absolute;
- pointer-events: none;
- }
- .ol-popup:after {
- border-top-color: white;
- border-width: 10px;
- left: 48px;
- margin-left: -10px;
- }
- .ol-popup:before {
- border-top-color: #cccccc;
- border-width: 11px;
- left: 48px;
- margin-left: -11px;
- }
- </style>
- </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>
- <div id="popup" class="ol-popup">
- <div id="popup-content"></div>
- </div>
- <script type="text/javascript">
- var host = window.isLocal ? window.server : "https://iserver.supermap.io";
- var map,
- baseUrl = host + "/iserver/services/map-jingjin/rest/maps/京津地区地图",
- serviceUrl = host + "/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst";
- var extent = [104.07, 30.54, 119.51, 42.31],
- container = document.getElementById('popup'),
- content = document.getElementById('popup-content'),
- overlay = new ol.Overlay(({
- element: container,
- autoPan: true,
- autoPanAnimation: {
- duration: 250
- },
- offset: [0, -5]
- }));
- new ol.supermap.MapService(baseUrl).getMapInfo(function (serviceResult) {
- var mapJSONObj = serviceResult.result;
- map = new ol.Map({
- target: 'map',
- controls: ol.control.defaults({attributionOptions: {collapsed: false}})
- .extend([new ol.supermap.control.Logo()]),
- view: new ol.View({
- center: [116.85, 39.79],
- zoom: 9,
- projection: "EPSG:4326",
- multiWorld: true
- }),
- overlays: [overlay]
- });
- options = ol.source.TileSuperMapRest.optionsFromMapJSON(baseUrl, mapJSONObj);
- var layer = new ol.layer.Tile({
- source: new ol.source.TileSuperMapRest(options)
- });
- map.addLayer(layer);
- overlayerBatchAnalystFromGeometry();
- });
- function overlayerBatchAnalystFromGeometry() {
- //叠加分析数据:
- var sourceGeometry1 = {
- "type": "Feature",
- "geometry": {
- "type": "Polygon",
- "coordinates": [[[116.25, 40.25],
- [116.25, 39.75],
- [117.25, 39.75],
- [117.25, 40.25],
- [116.25, 40.25]]]
- }
- };
- var sourceGeometry2 = {
- "type": "Feature",
- "geometry": {
- "type": "Polygon",
- "coordinates": [[[116.75, 40.25],
- [116.75, 39.75],
- [117.75, 39.75],
- [117.75, 40.25],
- [116.75, 40.25]]]
- }
- };
- var operateGeometry1 = {
- "type": "Feature",
- "geometry": {
- "type": "Polygon",
- "coordinates": [[[116.75, 39.75],
- [117.25, 39.75],
- [117.25, 40.75],
- [116.75, 40.75],
- [116.75, 39.75]]]
- }
- };
- var operateGeometry2 = {
- "type": "Feature",
- "geometry": {
- "type": "Polygon",
- "coordinates": [[[116.75, 40.25],
- [116.75, 39.25],
- [117.25, 39.25],
- [117.25, 40.25],
- [116.75, 40.25]]]
- }
- };
- //数据加载到地图:
- var geojsonFeature = {
- "type": "FeatureCollection",
- "features": [sourceGeometry1, sourceGeometry2, operateGeometry1, operateGeometry2]
- };
- var overlaySource = new ol.source.Vector({
- features: (new ol.format.GeoJSON()).readFeatures(geojsonFeature)
- });
- var overlayLayer = new ol.layer.Vector({
- source: overlaySource,
- style: new ol.style.Style({
- stroke: new ol.style.Stroke({
- color: 'blue',
- width: 1
- }),
- fill: new ol.style.Fill({
- color: 'rgba(174, 238, 238, 0.3)'
- })
- })
- });
- map.addLayer(overlayLayer);
- var OverlayBatchAnalystParameters = new SuperMap.GeometryOverlayAnalystParameters({
- sourceGeometries: [sourceGeometry1, sourceGeometry2],
- operateGeometries: [operateGeometry1, operateGeometry2],
- operation: SuperMap.OverlayOperationType.INTERSECT
- });
- new ol.supermap.SpatialAnalystService(serviceUrl).overlayAnalysis(OverlayBatchAnalystParameters, function (serviceResult) {
- serviceResult.result[0].resultGeometry.properties.isResultLayer = true;
- var resultSource = new ol.source.Vector({
- features: (new ol.format.GeoJSON()).readFeatures(serviceResult.result[0].resultGeometry)
- });
- var resultLayer = new ol.layer.Vector({
- source: resultSource,
- style: new ol.style.Style({
- stroke: new ol.style.Stroke({
- color: 'red',
- width: 1.5
- }),
- fill: new ol.style.Fill({
- color: 'rgba(255, 0, 0, 0.3)'
- })
- })
- });
- map.addLayer(resultLayer);
- map.on('pointermove', function (e) {
- var coordinates = e.coordinate;
- var isShowPop = false;
- map.forEachFeatureAtPixel(e.pixel, function (feature) {
- if (feature.getProperties().isResultLayer) {
- map.getTargetElement().style.cursor = 'pointer';
- var contentHTML = resources.text_overlayBatchAnalystResult;
- content.innerHTML = contentHTML;
- overlay.setPosition([117,40]);
- map.addOverlay(overlay);
- isShowPop = true;
- }
- }, {
- hitTolerance: 10
- });
- if (isShowPop) {
- return;
- } else {
- map.getTargetElement().style.cursor = '';
- overlay.setPosition(undefined);
- map.removeOverlay(overlay);
- }
- });
- });
- }
- </script>
- </body>
- </html>
|