vectorTileLayerMVT.html 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="UTF-8">
  8. <title data-i18n="resources.title_vectorTileLayerMVT"></title>
  9. <script type="text/javascript" src="../js/include-web.js"></script>
  10. </head>
  11. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  12. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  13. <script type="text/javascript" src="../../dist/leaflet/include-leaflet.js"></script>
  14. <script type="text/javascript">
  15. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  16. var map, selectId, selectLayerName, vectorLayer,
  17. url = host + "/iserver/services/map-china400/rest/maps/China";
  18. map = L.map('map', {
  19. center: [39.89, 116.43],
  20. maxZoom: 15,
  21. zoom: 1
  22. });
  23. vectorLayer = L.supermap.tiledVectorLayer(url, {
  24. tileSize: 512,
  25. format: L.supermap.VectorTileFormat.MVT,
  26. cacheEnabled: true,
  27. returnAttributes: true,
  28. attribution: "Tile Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a></span>"
  29. }).addTo(map);
  30. vectorLayer.on('click', function (evt) {
  31. var id = evt.layer.properties.id;
  32. var layerName = evt.layer.layerName;
  33. clearHighlight();
  34. selectId = id;
  35. selectLayerName = layerName;
  36. var selectStyle = {
  37. fillColor: '#800026',
  38. fillOpacity: 0.5,
  39. stroke: true,
  40. fill: true,
  41. color: 'red',
  42. opacity: 1,
  43. weight: 2
  44. };
  45. vectorLayer.setFeatureStyle(id, layerName, selectStyle);
  46. });
  47. function clearHighlight() {
  48. if (selectId && selectLayerName) {
  49. vectorLayer.resetFeatureStyle(selectId, selectLayerName);
  50. }
  51. selectId = null;
  52. selectLayerName = null;
  53. }
  54. </script>
  55. </body>
  56. </html>