123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369 |
- <!--********************************************************************
- * 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_facility"></title>
- <style>
- html,
- body {
- margin: 0;
- padding: 0;
- height: 100%;
- width: 100%;
- position: relative;
- }
- #map {
- width: 100%;
- height: 100%;
- }
- </style>
- </head>
- <body>
- <div id="map"></div>
- <script type="text/javascript" include="jquery" src="../js/include-web.js"></script>
- <script
- type="text/javascript"
- include="three,MTLLoader,OBJLoader"
- src="../../dist/mapboxgl/include-mapboxgl.js"
- ></script>
- <script>
- 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='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
- var map,
- threeLayer,
- position = [116.466502, 39.990706];
- //https://iclient.supermap.io https://iserver.supermap.io
- var host = window.isLocal ? window.server : 'https://iserver.supermap.io',
- url = host + '/iserver/services/map-china400/rest/maps/ChinaDark';
- 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
- }
- ],
- glyphs:
- host +
- '/iserver/services/map-beijing/rest/maps/beijingMap/tileFeature/sdffonts/{fontstack}/{range}.pbf'
- },
- center: [116.46548484988489, 39.990389660427695],
- zoom: 15.91,
- bearing: 59.19,
- pitch: 60
- });
- map.addControl(new mapboxgl.NavigationControl(), 'top-left');
- //加载obj模型
- loaderModels();
- //添加设施点,路径以及标签
- map.on('load', function () {
- loadOverlays();
- });
- function loaderModels() {
- var mtlLoader = new THREE.MTLLoader(new THREE.LoadingManager());
- mtlLoader.load('./js/facility/building.mtl', function (materials) {
- materials.preload();
- var objLoader = new THREE.OBJLoader(new THREE.LoadingManager());
- objLoader.setMaterials(materials);
- objLoader.load(
- './js/facility/building.obj',
- function (obj) {
- // https://discourse.threejs.org/t/obj-mtl-model-is-loaded-but-is-black/18488
- obj.traverse(function (child) {
- if (child.isMesh) child.geometry.computeVertexNormals();
- });
- var meshes = obj;
- meshes.rotation.x = -Math.PI / 2;
- meshes.rotation.y = (1.4 * Math.PI) / 5;
- meshes.scale.multiplyScalar(3);
- addThreeLayer(meshes);
- },
- null,
- null,
- null,
- false
- );
- });
- }
- function addThreeLayer(meshes) {
- threeLayer = new mapboxgl.supermap.ThreeLayer('three');
- threeLayer.on('initialized', render);
- function render() {
- var renderer = threeLayer.getThreeRenderer(),
- scene = threeLayer.getScene(),
- camera = threeLayer.getCamera();
- this.light = new THREE.PointLight(0xffffff, 0.8);
- this.light.position.copy(camera.position);
- scene.add(this.light);
- scene.add(new THREE.AmbientLight(0xffffff));
- threeLayer.setPosition(meshes, position);
- scene.add(meshes);
- }
- //均匀光照,与相机位置同步
- threeLayer.on('render', function () {
- threeLayer.light.position.copy(threeLayer.renderer.camera.position);
- });
- threeLayer.addTo(map);
- }
- function loadOverlays() {
- var facilityPositions = {
- shopping: [116.462834, 39.991234],
- hospital: [116.467154, 39.995506],
- school: [116.46506, 39.992958]
- };
- var labelPositions = {
- shoppingText: [116.464668, 39.990965],
- hospitalText: [116.466828, 39.993106],
- schoolText: [116.465781, 39.991832]
- };
- //添加设施点
- var shoppingImg = new Image();
- shoppingImg.src = './js/facility/shopping.png';
- var shoppingMall = new mapboxgl.Marker(shoppingImg, { x: -32, y: -54 })
- .setLngLat(facilityPositions.shopping)
- .addTo(map);
- var hospitalImg = new Image();
- hospitalImg.src = './js/facility/hospital.png';
- var hospital = new mapboxgl.Marker(hospitalImg, { x: -32, y: -54 })
- .setLngLat(facilityPositions.hospital)
- .addTo(map);
- var schoolImg = new Image();
- schoolImg.src = './js/facility/school.png';
- var school = new mapboxgl.Marker(schoolImg, { x: -32, y: -54 })
- .setLngLat(facilityPositions.school)
- .addTo(map);
- //添加购物中心距离路径
- map.addLayer({
- id: 'shopping-route',
- type: 'line',
- source: {
- type: 'geojson',
- data: {
- type: 'Feature',
- properties: {},
- geometry: {
- type: 'LineString',
- coordinates: [position, facilityPositions.shopping]
- }
- }
- },
- layout: {
- 'line-join': 'round',
- 'line-cap': 'round'
- },
- paint: {
- 'line-color': '#0000ff',
- 'line-width': 5
- }
- });
- //添加医院距离路径
- map.addLayer({
- id: 'hospital-route',
- type: 'line',
- source: {
- type: 'geojson',
- data: {
- type: 'Feature',
- properties: {},
- geometry: {
- type: 'LineString',
- coordinates: [position, facilityPositions.hospital]
- }
- }
- },
- layout: {
- 'line-join': 'round',
- 'line-cap': 'round'
- },
- paint: {
- 'line-color': '#ff0000',
- 'line-width': 5
- }
- });
- //添加学校距离路径
- map.addLayer({
- id: 'school-route',
- type: 'line',
- source: {
- type: 'geojson',
- data: {
- type: 'Feature',
- properties: {},
- geometry: {
- type: 'LineString',
- coordinates: [position, facilityPositions.school]
- }
- }
- },
- layout: {
- 'line-join': 'round',
- 'line-cap': 'round'
- },
- paint: {
- 'line-color': '#00ff00',
- 'line-width': 5
- }
- });
- //添加购物中心距离提示标签
- map.addLayer({
- id: 'text-shopping',
- type: 'symbol',
- source: {
- type: 'geojson',
- data: {
- type: 'FeatureCollection',
- features: [
- {
- type: 'Feature',
- properties: { text: '购物320米' },
- geometry: {
- type: 'Point',
- coordinates: labelPositions.shoppingText
- }
- }
- ]
- }
- },
- paint: {
- 'text-halo-color': '#ffffff',
- 'text-halo-width': 2
- },
- layout: {
- 'text-field': '{text}'
- }
- });
- //添加医院距离提示标签
- map.addLayer({
- id: 'text-hospital',
- type: 'symbol',
- source: {
- type: 'geojson',
- data: {
- type: 'FeatureCollection',
- features: [
- {
- type: 'Feature',
- properties: { text: '医院550米' },
- geometry: {
- type: 'Point',
- coordinates: labelPositions.hospitalText
- }
- }
- ]
- }
- },
- paint: {
- 'text-halo-color': '#ffffff',
- 'text-halo-width': 2
- },
- layout: {
- 'text-field': '{text}'
- }
- });
- //添加学校距离提示标签
- map.addLayer({
- id: 'text-school',
- type: 'symbol',
- source: {
- type: 'geojson',
- data: {
- type: 'FeatureCollection',
- features: [
- {
- type: 'Feature',
- properties: { text: '学校300米' },
- geometry: {
- type: 'Point',
- coordinates: labelPositions.schoolText
- }
- }
- ]
- }
- },
- paint: {
- 'text-halo-color': '#ffffff',
- 'text-halo-width': 2
- },
- layout: {
- 'text-field': '{text}'
- }
- });
- //添加大厦名称标签
- map.addLayer({
- id: 'text-building',
- type: 'symbol',
- source: {
- type: 'geojson',
- data: {
- type: 'FeatureCollection',
- features: [
- {
- type: 'Feature',
- properties: { text: 'xxxx大厦' },
- geometry: {
- type: 'Point',
- coordinates: position
- }
- }
- ]
- }
- },
- paint: {
- 'text-translate': [0, -140],
- 'text-color': '#ffffff',
- 'text-halo-color': '#ff0000',
- 'text-halo-width': 2,
- 'text-translate-anchor': 'viewport'
- },
- layout: {
- 'text-field': '{text}'
- }
- });
- }
- </script>
- </body>
- </html>
|