osmbuildings.html 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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_osmBuildingsLeaflet"></title>
  9. <script type="text/javascript" include="jquery" 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" include="osmbuildings" src="../../dist/leaflet/include-leaflet.js"></script>
  14. <script>
  15. var map = new L.Map('map', {
  16. center: [39.916, 116.450],
  17. zoom: 16
  18. });
  19. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  20. var url = host + "/iserver/services/map-china400/rest/maps/China";
  21. L.supermap.tiledMapLayer(url).addTo(map);
  22. loadData();
  23. function loadData() {
  24. var data;
  25. $.get('../data/buildings.json', function (geojson) {
  26. data = geojson;
  27. new OSMBuildings(map)
  28. .date(new Date(2017, 5, 15, 17, 30))
  29. .set(geojson)
  30. .click(bindPopup);
  31. });
  32. function bindPopup(evt) {
  33. var name = getFeatureNameById(evt.feature);
  34. name = name || "<span style='color:red'>" + resources.text_noData + "</span>";
  35. L.popup().setContent(name).setLatLng(L.latLng(evt.lat, evt.lon)).openOn(map);
  36. }
  37. function getFeatureNameById(id) {
  38. if (!data || !id) {
  39. return null;
  40. }
  41. var features = data.features;
  42. for (var i = 0; i < features.length; i++) {
  43. if (features[i].properties.id === id) {
  44. return features[i].properties.name;
  45. }
  46. }
  47. }
  48. }
  49. </script>
  50. </body>
  51. </html>