123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <!--********************************************************************
- * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
- *********************************************************************-->
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title data-i18n="resources.title_AnimationFeature"></title>
- <script type="text/javascript" src="../js/include-web.js"></script>
- <script type="text/javascript" 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',
- multiWorld: true
- })
- });
- var options = ol.source.TileSuperMapRest.optionsFromMapJSON(url, mapJSONObj);
- var layer = new ol.layer.Tile({
- source: new ol.source.TileSuperMapRest(options)
- });
- map.addLayer(layer);
- function addRandomFeature() {
- var xmax = 130, xmin = 80, ymax = 50, ymin = 20;
- var feature = new ol.Feature(new ol.geom.Point([Math.floor(Math.random() * (xmax - xmin + 1) + xmin), Math.floor(Math.random() * (ymax - ymin + 1) + ymin)]));
- source.addFeature(feature);
- }
- function flash(feature) {
- var start = new Date().getTime();
- var listenerKey;
- function animate(event) {
- var duration = 3000;
- // ol6 废除了 event.vectorContext 接口,通过 ol.render.getVectorContext 来获取 vectorContext
- var vectorContext = new ol.render.getVectorContext(event);
- var frameState = event.frameState;
- var flashGeom = feature.getGeometry().clone();
- var elapsed = frameState.time - start;
- var elapsedRatio = elapsed / duration;
- var radius = ol.easing.easeOut(elapsedRatio) * 25 + 5;
- var opacity = ol.easing.easeOut(1 - elapsedRatio);
- var style = new ol.style.Style({
- image: new ol.style.Circle({
- radius: radius,
- stroke: new ol.style.Stroke({
- color: 'rgba(255, 0, 0, ' + opacity + ')',
- width: 0.25 + opacity
- })
- })
- });
- vectorContext.setStyle(style);
- vectorContext.drawGeometry(flashGeom);
- if (elapsed > duration) {
- ol.Observable.unByKey(listenerKey);
- return;
- }
- map.render();
- }
- listenerKey = vector.on('postrender', animate);
- }
- var source = new ol.source.Vector({
- wrapX: false
- });
- source.on('addfeature', function (e) {
- flash(e.feature);
- });
- var vector = new ol.layer.Vector({
- source: source
- });
- map.addLayer(vector);
- window.setInterval(addRandomFeature, 1000);
- });
- </script>
- </body>
- </html>
|