Closed YangShuqing closed 1 year ago
使用 mapbox 版本,在引入增强包后,设置地图的最大范围 maxBounds, 发现 纬度的限制已生效,经度的限制未生效,地图左右移动到最大后仍可移动
同样的参数,使用原生mapbox 可生效
在线示例: https://iclient.supermap.io/examples/mapboxgl/editor.html#01_tiledMapLayer_4326
核心参数
center: [118.157743, 39.63389], maxBounds: [[117.5703807,38.83232], [119.494011,40.498628] ], zoom: 12
完整代码
<!--******************************************************************** * Copyright© 2000 - 2023 SuperMap Software Co.Ltd. All rights reserved. *********************************************************************--> <!--******************************************************************** * 该示例需要引入 * mapbox-gl-enhance (https://iclient.supermap.io/web/libs/mapbox-gl-js-enhance/1.12.0-1/mapbox-gl-enhance.js) *********************************************************************--> <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" /> <title data-i18n="resources.title_tiledMapLayer_4326WGS84"></title> <script type="text/javascript" src="../js/include-web.js"></script> <script type="text/javascript" include="mapbox-gl-enhance" src="../../dist/mapboxgl/include-mapboxgl.js" ></script> <style> body { margin: 0; padding: 0; } #map { position: absolute; top: 0; bottom: 0; width: 100%; } </style> </head> <body> <div id="map"></div> <script type="text/javascript"> var host = window.isLocal ? window.server : 'https://iserver.supermap.io'; var map = new mapboxgl.Map({ container: 'map', // container id style: { version: 8, sources: { 'raster-tiles': { type: 'raster', tileSize: 256, //xyz形式,原生支持 //"tiles": ['https://t0.tianditu.gov.cn/DataServer?T=vec_c&x={x}&y={y}&l={z}'], //iserver image资源模板;扩展支持 //"tiles": ['http://localhost:8090/iserver/services/map-World/rest/maps/World/image.png?viewBounds={viewBounds}&width={width}&height={height}'], //iserver tileimage资源模板;扩展支持 //"tiles": ['https://iserver.supermap.io/iserver/services/map-jingjin/rest/maps/%E4%BA%AC%E6%B4%A5%E5%9C%B0%E5%8C%BA%E5%9C%B0%E5%9B%BE/tileimage.png?scale={scale}&x={x}&y={y}&width={width}&height={height}&origin={"x":-180,"y":90}'], //推荐; iserver tileimage资源;扩展支持 //参数列表: //地图服务地址(到地图名)必填 ; //rasterSource为"iserver";必填; //transparent:可选,默认为true; //cacheEnabled: 是否使用缓存,默认为true; //redirect: 如果为 true,则将请求重定向到瓦片的真实地址;如果为 false,则响应体中是瓦片的字节流,默认为false; //layersID:要显示的图层id字符串; //tileversion: 切片版本名称,cacheEnabled 为 true 时有效; //rasterfunction: 栅格分析参数,类型为mapboxgl.supermap.NDVIParameter或mapboxgl.supermap.HillshadeParameter; //format:瓦片格式,默认为'png'; tiles: [host + '/iserver/services/map-world/rest/maps/World'], rasterSource: 'iserver' } }, layers: [ { id: 'simple-tiles', type: 'raster', source: 'raster-tiles', minzoom: 0, maxzoom: 22 } ] }, crs: 'EPSG:4326', // 或者 mapboxgl.CRS.EPSG4326 或者 new mapboxgl.CRS('EPSG:4326',[-180,-90,180,90]); center: [118.157743, 39.63389], maxBounds: [[117.5703807,38.83232], [119.494011,40.498628] ], zoom: 12 }); map.on('load', function() { //从 iServer 查询 var idsParam = new mapboxgl.supermap.GetFeaturesByIDsParameters({ IDs: [234], datasetNames: ['World:Countries'] }); var service = new mapboxgl.supermap.FeatureService(host + '/iserver/services/data-world/rest/data'); service.getFeaturesByIDs(idsParam, function(serviceResult) { map.addSource('queryDatas', { type: 'geojson', data: serviceResult.result.features }); map.addLayer({ id: 'queryDatas', type: 'fill', source: 'queryDatas', paint: { 'fill-color': '#008080', 'fill-opacity': 0.4 }, filter: ['==', '$type', 'Polygon'] }); }); map.addControl(new mapboxgl.NavigationControl(), 'top-left'); }); </script> </body> </html>
可生效的原生mapbox 代码
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Mapbox 示例</title> <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no"> <script src="https://api.mapbox.com/mapbox-gl-js/v2.4.1/mapbox-gl.js"></script> <link href="https://api.mapbox.com/mapbox-gl-js/v2.4.1/mapbox-gl.css" rel="stylesheet"> <style> body { margin: 0; padding: 0; } #map { position: absolute; top: 0; bottom: 0; width: 100%; } </style> </head> <body> <div id="map"></div> <script> mapboxgl.accessToken = 'MAP_BOX_TOKEN'; // 在这里替换为你自己的Mapbox访问令牌 // 创建地图 var map = new mapboxgl.Map({ container: 'map', // 地图容器的HTML元素ID style: 'mapbox://styles/mapbox/streets-v11', // 使用的地图样式 center: [118.157743,39.63389], // 地图中心的经纬度坐标 maxBounds: [[117.5703807,38.83232], [119.494011,40.498628] ], zoom: 12 // 地图缩放级别 }); // 添加标记 var marker = new mapboxgl.Marker() .setLngLat([118.157743,39.63389]) .addTo(map); </script> </body> </html>
经测试 原生 mapbox 代码 使用 官网的1.13.2版本 也是可以生效的
@songyumeng 大约多久可以修复啊?
请使用这个,https://iclient.supermap.io/web/libs/mapbox-gl-js-enhance/1.12.1-1/mapbox-gl-enhance.js
现象:
使用 mapbox 版本,在引入增强包后,设置地图的最大范围 maxBounds, 发现 纬度的限制已生效,经度的限制未生效,地图左右移动到最大后仍可移动
同样的参数,使用原生mapbox 可生效
复现流程
在线示例: https://iclient.supermap.io/examples/mapboxgl/editor.html#01_tiledMapLayer_4326
核心参数
完整代码
可生效的原生mapbox 代码