123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- <!--********************************************************************
- * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
- *********************************************************************-->
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title data-i18n="resources.title_findLocation"></title>
- <script type="text/javascript" src="../js/include-web.js"></script>
- <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
- </head>
- <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
- <div id="map" style="width: 100%;height:100%"></div>
- <script type="text/javascript">
- var map, options,
- baseUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/map-changchun/rest/maps/长春市区图",
- serviceUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/transportationanalyst-sample/rest/networkanalyst/RoadNet@Changchun";
- var extent = [48.4, -7668.25, 8958.85, -55.58];
- var projection = new ol.proj.Projection({
- code:'',
- extent: extent,
- units: 'm'
- });
- 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: [4800, -3700],
- zoom: 2,
- projection: projection,
- multiWorld: true
- }),
- });
- options = ol.source.TileSuperMapRest.optionsFromMapJSON(baseUrl, mapJSONObj);
- var layer = new ol.layer.Tile({
- source: new ol.source.TileSuperMapRest(options)
- });
- map.addLayer(layer);
- findLocationProcess();
- });
- function findLocationProcess() {
- //添加设施点
- var facilityPoint1 = new ol.geom.Point([1675.9256791377206, -593.56822512495194]);
- var facilityPoint2 = new ol.geom.Point([2820.35101097629, -2358.0414663985171]);
- var facilityPoint3 = new ol.geom.Point([2909.4396668115278, -3647.0074300836109]);
- var facilityPoint4 = new ol.geom.Point([1544.5037476378677, -5616.5950974905827]);
- var facilityPoint5 = new ol.geom.Point([6623.5972101719526, -2130.4887600981415]);
- var facilityPoint6 = new ol.geom.Point([5482.4979617984973, -4504.2328567816048]);
- var facilityPoint7 = new ol.geom.Point([6940.6579024271468, -1627.6012900626256]);
- var facilityPoint8 = new ol.geom.Point([8215.9188781715948, -5747.5063918659716]);
- var facilityFeature1 = new ol.Feature(facilityPoint1);
- var facilityFeature2 = new ol.Feature(facilityPoint2);
- var facilityFeature3 = new ol.Feature(facilityPoint3);
- var facilityFeature4 = new ol.Feature(facilityPoint4);
- var facilityFeature5 = new ol.Feature(facilityPoint5);
- var facilityFeature6 = new ol.Feature(facilityPoint6);
- var facilityFeature7 = new ol.Feature(facilityPoint7);
- var facilityFeature8 = new ol.Feature(facilityPoint8);
- var iconStyle_facility = new ol.style.Style({
- image: new ol.style.Icon(({
- src: '../img/marker.png',
- anchor: [0.5, 1]
- }))
- });
- facilityFeature1.setStyle(iconStyle_facility);
- facilityFeature2.setStyle(iconStyle_facility);
- facilityFeature3.setStyle(iconStyle_facility);
- facilityFeature4.setStyle(iconStyle_facility);
- facilityFeature5.setStyle(iconStyle_facility);
- facilityFeature6.setStyle(iconStyle_facility);
- facilityFeature7.setStyle(iconStyle_facility);
- facilityFeature8.setStyle(iconStyle_facility);
- var facilitySource = new ol.source.Vector({
- features: [
- facilityFeature1, facilityFeature2,
- facilityFeature3, facilityFeature4,
- facilityFeature5, facilityFeature6,
- facilityFeature7, facilityFeature8
- ]
- });
- var facilityLayer = new ol.layer.Vector({
- source: facilitySource
- });
- // 设置设施点的资源供给中心
- var supplyCenterType_FIXEDCENTER = SuperMap.SupplyCenterType.FIXEDCENTER,
- supplyCenterType_NULL = SuperMap.SupplyCenterType.NULL;
- var supplyCenterType_OPTIONALCENTER = SuperMap.SupplyCenterType.OPTIONALCENTER,
- supplyCenters = [new SuperMap.SupplyCenter({
- maxWeight: 500, // 资源供给中心的最大耗费值,必设参数
- nodeID: 139, // 资源供给中心点的结点 ID 号,必设参数
- resourceValue: 100, // 资源供给中心能提供的最大服务量或商品数量,必设参数
- type: supplyCenterType_OPTIONALCENTER //选址分区中资源中心的类型包括固定中心和可选中心两种
- }),
- new SuperMap.SupplyCenter({
- maxWeight: 500,
- nodeID: 1358,
- resourceValue: 100,
- type: supplyCenterType_OPTIONALCENTER
- }),
- new SuperMap.SupplyCenter({
- maxWeight: 500,
- nodeID: 2972,
- resourceValue: 100,
- type: supplyCenterType_OPTIONALCENTER
- }),
- new SuperMap.SupplyCenter({
- maxWeight: 500,
- nodeID: 5523,
- resourceValue: 100,
- type: supplyCenterType_OPTIONALCENTER
- }),
- new SuperMap.SupplyCenter({
- maxWeight: 500,
- nodeID: 1161,
- resourceValue: 100,
- type: supplyCenterType_OPTIONALCENTER
- }),
- new SuperMap.SupplyCenter({
- maxWeight: 500,
- nodeID: 4337,
- resourceValue: 100,
- type: supplyCenterType_OPTIONALCENTER
- }),
- new SuperMap.SupplyCenter({
- maxWeight: 500,
- nodeID: 5732,
- resourceValue: 100,
- type: supplyCenterType_NULL
- }),
- new SuperMap.SupplyCenter({
- maxWeight: 500,
- nodeID: 663,
- resourceValue: 100,
- type: supplyCenterType_FIXEDCENTER
- })
- ];
- //创建选址分区分析参数实例
- var findLocationParameter = new SuperMap.FindLocationParameters({
- // 期望用于最终设施选址的资源供给中心数量,必设字段
- expectedSupplyCenterCount: 8,
- // 是否从中心点开始分配资源。默认为 false
- isFromCenter: false,
- nodeDemandField: "Demand",
- // 转向权值字段的名称
- turnWeightField: "TurnCost",
- // 阻力字段的名称, 必设
- weightName: "length",
- // 资源供给中心集合,必设字段
- supplyCenters: supplyCenters
- });
- //进行查找
- new ol.supermap.NetworkAnalystService(serviceUrl).findLocation(findLocationParameter, function (serviceResult) {
- var vectorSource = new ol.source.Vector({
- features: (new ol.format.GeoJSON()).readFeatures(serviceResult.result.demandResults)
- });
- var polygonLayer = new ol.layer.Vector({
- source: vectorSource,
- style: new ol.style.Style({
- image: new ol.style.Circle({
- radius: 2.5,
- fill: new ol.style.Fill({
- color: 'dodgerblue'
- })
- })
- })
- });
- map.addLayer(polygonLayer);
- map.addLayer(facilityLayer);
- });
- }
- </script>
- </body>
- </html>
|