123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- <!--********************************************************************
- * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
- *********************************************************************-->
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title data-i18n="resources.title_heatGridMapLayer"></title>
- <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
- <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
- <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="map"></div>
- <script>
- var map, layer, heatGridLayer, selectGrid, infowin;
- //定义网格的styles
- var items = [
- {
- start: 0,
- end: 2,
- style: {
- strokeColor: "#C69944",
- strokeWidth: 1,
- fillColor: "#B8E4B8",
- fillOpacity: 0.5
- }
- },
- {
- start: 2,
- end: 4,
- style: {
- strokeColor: "#C69944",
- strokeWidth: 1,
- fillColor: "#66dd66",
- fillOpacity: 0.5
- }
- },
- {
- start: 4,
- end: 6,
- style: {
- strokeColor: "#C69944",
- strokeWidth: 1,
- fillColor: "#00ee00",
- fillOpacity: 0.5
- }
- },
- {
- start: 6,
- end: 8,
- style: {
- strokeColor: "#C69944",
- strokeWidth: 1,
- fillColor: "#008800",
- fillOpacity: 0.5
- }
- },
- {
- start: 8,
- end: 10,
- style: {
- strokeColor: "#C69944",
- strokeWidth: 1,
- fillColor: "#df8505",
- fillOpacity: 0.5
- }
- },
- {
- start: 10,
- end: 12,
- style: {
- strokeColor: "#C69944",
- strokeWidth: 1,
- fillColor: "#CC9933",
- fillOpacity: 0.5
- }
- },
- {
- start: 12,
- end: 16,
- style: {
- strokeColor: "#C69944",
- strokeWidth: 1,
- fillColor: "#FF0000",
- fillOpacity: 0.5
- }
- }
- ];
- var host = window.isLocal ? window.server : "https://iserver.supermap.io";
- var url = host + "/iserver/services/map-world/rest/maps/World";
- //初始化
- init();
- function init() {
- map = new SuperMap.Map("map", {
- controls: [
- new SuperMap.Control.ScaleLine(),
- new SuperMap.Control.Zoom(),
- new SuperMap.Control.LayerSwitcher(),
- new SuperMap.Control.Navigation({
- dragPanOptions: {
- enableKinetic: true
- }
- })]
- });
- map.addControl(new SuperMap.Control.MousePosition());
- layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, {
- transparent: true,
- cacheEnabled: true
- }, {maxResolution: "auto"});
- //创建热点网格图
- heatGridLayer = new SuperMap.Layer.HeatGridLayer("heatGrid");
- layer.events.on({"layerInitialized": addLayer});
- }
- //添加图层、注册事件、激活格网选择控件
- function addLayer() {
- map.addLayers([layer, heatGridLayer]);
- map.setCenter(new SuperMap.LonLat(0, 0), 0);
- // 创建格网选择控件
- var select = new SuperMap.Control.SelectGrid(heatGridLayer, {
- callbacks: {
- //点击feature事件
- clickFeature: function (f) {
- closeInfoWin();
- openInfoWin(f);
- },
- clickout: function () {
- closeInfoWin();
- }
- }
- });
- map.events.on({
- "movestart": function () {
- closeInfoWin();
- }
- });
- map.addControl(select);
- select.activate();
- createHeatPoints();
- }
- //向服务器发送请求,获取数据
- function createHeatPoints() {
- var points = [new SuperMap.Geometry.Point(-180, 90),
- new SuperMap.Geometry.Point(180, 90),
- new SuperMap.Geometry.Point(180, -90),
- new SuperMap.Geometry.Point(-180, -90)
- ],
- linearRings = new SuperMap.Geometry.LinearRing(points),
- region = new SuperMap.Geometry.Polygon([linearRings]);
- var queryParam, queryByGeometryParameters, queryService;
- //设置查询数据集的查询过滤参数
- queryParam = new SuperMap.REST.FilterParameter({name: "Capitals@World.1"});
- //设置 Geometry查询的相关参数
- queryByGeometryParameters = new SuperMap.REST.QueryByGeometryParameters({
- queryParams: [queryParam],
- geometry: region,
- spatialQueryMode: SuperMap.REST.SpatialQueryMode.INTERSECT
- });
- queryService = new SuperMap.REST.QueryByGeometryService(url, {
- eventListeners: {
- "processCompleted": processCompleted,
- "processFailed": processFailed
- }
- });
- queryService.processAsync(queryByGeometryParameters);
- }
- function processCompleted(queryEventArgs) {
- var i, j, result = queryEventArgs.result;
- var heatFeatures = [];
- if (result && result.recordsets) {
- for (i = 0, recordsets = result.recordsets, len = recordsets.length; i < len; i++) {
- if (recordsets[i].features) {
- for (j = 0; j < recordsets[i].features.length; j++) {
- var feature = recordsets[i].features[j];
- var point = feature.geometry;
- if (point.CLASS_NAME == SuperMap.Geometry.Point.prototype.CLASS_NAME) {
- feature.attributes.temperature = parseInt(Math.random() * 45 * 10) / 10;
- feature.style = {
- pointRadius: 4,
- graphic: true,
- externalGraphic: "images/country.png",
- graphicWidth: 6,
- graphicHeight: 6
- };
- heatFeatures.push(feature);
- }
- }
- }
- }
- }
- //设置地图在第4级的时候进行格网散开
- heatGridLayer.spreadZoom = 4;
- heatGridLayer.items = items;
- //设置label显示的数据为字段temperature的内容
- heatGridLayer.dataField = "temperature";
- heatGridLayer.addFeatures(heatFeatures);
- }
- function processFailed(e) {
- widgets.alert.showAlert(e.error.errorMsg,false);
- }
- //弹出信息框
- function openInfoWin(feature) {
- var geo = feature.geometry;
- var bounds = geo.getBounds();
- var center = bounds.getCenterLonLat();
- var contentHTML = "<div style='font-size:.8em; opacity: 0.8; overflow-y:hidden;'>";
- contentHTML += "<div>" + "SmID:" + feature.data.SmID + "<br />" + resources.text_country + feature.data.COUNTRY + "<br />" + resources.text_capital + feature.data.CAPITAL + "</div></div>";
- var popup = new SuperMap.Popup.FramedCloud("popwin",
- new SuperMap.LonLat(center.lon, center.lat),
- null,
- contentHTML,
- null,
- true);
- feature.popup = popup;
- infowin = popup;
- map.addPopup(popup);
- }
- //关闭信息框
- function closeInfoWin() {
- if (infowin) {
- try {
- infowin.hide();
- infowin.destroy();
- }
- catch (e) {
- }
- }
- }
- </script>
- </body>
- </html>
|