123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <!--********************************************************************
- * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
- *********************************************************************-->
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8" />
- <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
- <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width" />
- <title data-i18n="resources.title_mb_deckglLayer_pathLayer"></title>
- <style>
- body {
- margin: 0;
- overflow: hidden;
- background: #fff;
- width: 100%;
- height: 100%;
- }
- #map {
- position: absolute;
- top: 0;
- bottom: 0;
- width: 100%;
- }
- </style>
- </head>
- <body>
- <div id="map"></div>
- <script type="text/javascript" include="widgets" src="../js/include-web.js"></script>
- <script type="text/javascript" include="deck" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
- <script type="text/javascript">
- var host = window.isLocal ? window.server : 'https://iserver.supermap.io',
- url = host + '/iserver/services/map-china400/rest/maps/ChinaDark';
- var map, deckglLayer;
- var 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='https://uber.github.io/deck.gl' target='_blank'>deck.gl</a></span> ";
- map = new mapboxgl.Map({
- container: 'map',
- style: {
- version: 8,
- sources: {
- 'raster-tiles': {
- attribution: attribution,
- type: 'raster',
- tiles: [url + '/zxyTileImage.png?z={z}&x={x}&y={y}'],
- tileSize: 256
- }
- },
- layers: [
- {
- id: 'simple-tiles',
- type: 'raster',
- source: 'raster-tiles',
- minzoom: 0,
- maxzoom: 22
- }
- ]
- },
- center: [-122.271604, 37.803664],
- zoom: 12
- });
- map.addControl(new mapboxgl.NavigationControl(), 'top-left');
- widgets.loader.showLoader('data loading...');
- $.get('../data/deck.gl/bart-lines.json', function(features) {
- widgets.loader.removeLoader();
- addLayer(features);
- });
- function addLayer(features) {
- deckglLayer = new mapboxgl.supermap.DeckglLayer('path-layer', {
- data: features,
- props: {
- widthScale: 20, //线宽比例
- widthMinPixels: 2 //线宽最小像素值
- //该类型可配置的其他参数有:
- //widthMaxPixels 线宽最大像素值,默认为 Number.MAX_SAFE_INTEGER;
- //rounded 节点是否绘制为弧形,可选参数,默认为 false;
- //miterLimit 节点相对于线宽的最大范围,默认为 4,仅在 rounded 为 false 时有效;
- //fp64 否应以高精度64位模式呈现图层,默认为 false;
- //dashJustified 是否虚线形式显示,默认为 false,仅在 getDashArray() 回调函数被指定时有效;
- },
- callback: {
- getPath: function(d) {
- return d.path;
- },
- getColor: function(d) {
- return d.color.colorRgb();
- },
- getWidth: function(d) {
- return 5;
- }
- }
- });
- map.addLayer(deckglLayer);
- }
- var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
- /*16进制颜色转为RGB格式*/
- String.prototype.colorRgb = function() {
- var sColor = this.toLowerCase();
- if (sColor && reg.test(sColor)) {
- if (sColor.length === 4) {
- var sColorNew = '#';
- for (var i = 1; i < 4; i += 1) {
- sColorNew += sColor.slice(i, i + 1).concat(sColor.slice(i, i + 1));
- }
- sColor = sColorNew;
- }
- //处理六位的颜色值
- var sColorChange = [];
- for (var i = 1; i < 7; i += 2) {
- sColorChange.push(parseInt('0x' + sColor.slice(i, i + 2)));
- }
- return sColorChange;
- } else {
- return sColor;
- }
- };
- </script>
- </body>
- </html>
|