123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <!--********************************************************************
- * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
- *********************************************************************-->
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title data-i18n="resources.title_Cluster"></title>
- <script type="text/javascript" src="../js/include-web.js"></script>
- <!-- 此范例基于 openlayers@4.6.5 版本 -->
- <script type="text/javascript" include="animatedclusterlayer,ol@4.6.5" src="../../dist/ol/include-ol.js"></script>
- </head>
- <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
- <div id="map" style="width: 100%;height:100%"></div>
- <script type="text/javascript">
- var url = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/map-china400/rest/maps/China_4326";
- new ol.supermap.MapService(url).getMapInfo(function (serviceResult) {
- var mapJSONObj = serviceResult.result;
- var map = new ol.Map({
- target: 'map',
- controls: ol.control.defaults({attributionOptions: {collapsed: false}})
- .extend([new ol.supermap.control.Logo()]),
- view: new ol.View({
- center: [103, 30],
- zoom: 4,
- projection: 'EPSG:4326'
- })
- });
- var options = ol.source.TileSuperMapRest.optionsFromMapJSON(url, mapJSONObj);
- var layer = new ol.layer.Tile({
- source: new ol.source.TileSuperMapRest(options)
- });
- map.addLayer(layer);
- var clusterSource = new ol.source.Cluster({
- distance: 40,
- source: new ol.source.Vector(),
- wrapX: false
- });
- var clusterLayer = new ol.layer.AnimatedCluster({
- name: 'Cluster',
- source: clusterSource,
- animationDuration: 700,
- style: getStyle
- });
- map.addLayer(clusterLayer);
- function addFeatures(nb) {
- var features = [];
- var xmax = 130, xmin = 80, ymax = 50, ymin = 20;
- for (var i = 0; i < nb; ++i) {
- features[i] = new ol.Feature(new ol.geom.Point([Math.floor(Math.random() * (xmax - xmin + 1) + xmin), Math.floor(Math.random() * (ymax - ymin + 1) + ymin)]));
- features[i].set('id', i);
- }
- clusterSource.getSource().clear();
- clusterSource.getSource().addFeatures(features);
- }
- addFeatures(2000);
- });
- function getStyle(feature) {
- var styleCache = {};
- var size = feature.get('features').length;
- var style = styleCache[size];
- if (!style) {
- var color = size > 25 ? "192,0,0" : size > 8 ? "255,128,0" : "0,128,0";
- var radius = Math.max(8, Math.min(size * 0.75, 20));
- var dash = 2 * Math.PI * radius / 6;
- dash = [0, dash, dash, dash, dash, dash, dash];
- style = styleCache[size] = [new ol.style.Style({
- image: new ol.style.Circle({
- radius: radius,
- stroke: new ol.style.Stroke({
- color: "rgba(" + color + ",0.5)",
- width: 15,
- lineDash: dash,
- lineCap: "butt"
- }),
- fill: new ol.style.Fill({
- color: "rgba(" + color + ",1)"
- })
- }),
- text: new ol.style.Text({
- text: size.toString(),
- fill: new ol.style.Fill({
- color: '#fff'
- })
- })
- })
- ];
- }
- return style;
- }
- </script>
- </body>
- </html>
|