123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <!--********************************************************************
- * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
- *********************************************************************-->
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
- <title data-i18n="resources.title_heatMapLayer"></title>
- <style type="text/css">
- body {
- margin: 0;
- overflow: hidden;
- background: #fff;
- width: 100%;
- height: 100%
- }
- #map {
- position: absolute;
- width: 100%;
- height: 100%;
- }
- #toolbar {
- position: absolute;
- top: 50px;
- right: 10px;
- width: 300px;
- text-align: center;
- z-index: 100;
- border-radius: 4px;
- }
- </style>
- </head>
- <body>
- <div id="toolbar" class="panel panel-primary">
- <div class='panel-heading'>
- <h5 class='panel-title text-center' data-i18n="resources.text_fastHeatMapLayer"></h5></div>
- <div class='panel-body content'>
- <div class='panel'>
- <div class='input-group'>
- <span class='input-group-addon' data-i18n="resources.text_countsDraw"></span>
- <input type='text' class='form-control' id='heatNums' value='200'/>
- </div>
- </div>
- <div class='panel'>
- <div class='input-group'>
- <span class='input-group-addon' data-i18n="resources.text_radius"></span>
- <input class='form-control' style='width: 50px' value='50' id='heatradius'/>
- <select class='form-control' style='width:auto' id='radiusUnit'>
- <option value='px'>px</option>
- <option data-i18n='[value]resources.text_degree;resources.text_degree'></option>
- </select>
- </div>
- </div>
- <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_startDraw"
- onclick="createHeatPoints()"/>
- <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_clear"
- onclick="clearHeatPoints()"/>
- </div>
- </div>
- <div id="map"></div>
- <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
- <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
- <script type="text/javascript">
- var host = window.isLocal ? window.server : "https://iserver.supermap.io";
- var map, heatMapLayer,
- url = host + "/iserver/services/map-world/rest/maps/World";
- map = new ol.Map({
- target: 'map',
- controls: ol.control.defaults({attributionOptions: {collapsed: false}})
- .extend([new ol.supermap.control.Logo()]),
- view: new ol.View({
- center: [0, 0],
- zoom: 3,
- projection: 'EPSG:4326',
- multiWorld: true
- })
- });
- map.addLayer(new ol.layer.Tile({
- source: new ol.source.TileSuperMapRest({
- url: url,
- }),
- }));
- var heatMapSource;
- function createHeatPoints() {
- clearHeatPoints();
- heatMapSource = new ol.source.HeatMap(
- "heatMap",
- {
- "map": map,
- "id": "heatmap",
- "radius": 45,
- //featureWeight指定以哪个属性值为热力权重值创建热力图:
- "featureWeight": "value",
- }
- );
- var num = parseInt(document.getElementById('heatNums').value);
- var radius = parseInt(document.getElementById('heatradius').value);
- var unit = document.getElementById("radiusUnit").value;
- //resources.text_degree 表示 id=radiusUnit 选项的第一选项值
- if (resources.text_degree == unit) {
- //热力半径单位使用地理单位
- heatMapSource.useGeoUnit = true;
- } else {
- //热力半径单位不使用用地理单位
- heatMapSource.useGeoUnit = false;
- }
- heatMapSource.radius = radius;
- var features = [];
- for (var i = 0; i < num; i++) {
- features[i] = new ol.Feature({
- geometry: new ol.geom.Point([Math.random() * 340 - 170, Math.random() * 160 - 80]),
- Properties: {
- "value": Math.random() * 9,
- }
- });
- /*参数为geojson格式:
- features[i] = {
- "type": "feature",
- "geometry": {
- "type": "Point",
- "coordinates": [
- Math.random() * 340 - 170,
- Math.random() * 160 - 80]
- },
- "properties": {
- "value": Math.random() * 9,
- "geoRadius": useGeoRadius ? radius : null
- }
- };*/
- }
- //参数为geojson格式:
- /*var heatPoints = {
- "type": "FeatureCollection",
- "features": features
- };
- heatMapSource.addFeatures(heatPoints);
- */
- heatMapSource.addFeatures(features);
- heatMapLayer = new ol.layer.Image({
- source: heatMapSource
- });
- map.addLayer(heatMapLayer);
- }
- function clearHeatPoints() {
- if (heatMapLayer) {
- map.removeLayer(heatMapLayer);
- heatMapLayer = null;
- }
- }
- </script>
- </body>
- </html>
|