123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- <!--********************************************************************
- * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
- *********************************************************************-->
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title data-i18n="resources.title_graphicSymbolData"></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_graphicSymbolData"></h5>
- </div>
- <div class='panel-body content'>
- <div class='panel'>
- <div class='input-group'>
- <span class='input-group-addon'><span data-i18n="resources.text_countsDraw"></span><span
- data-i18n="[title]resources.text_requiredField" style='color: red;'> * </span></span>
- <input id='total' type='text' class='form-control' value='1000'/>
- </div>
- </div>
- <div class='input-group'>
- <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_noEventDraw"
- onclick="addData1()"/>
- <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_openEventDraw"
- onclick="addData2()"/>
- </div>
- </div>
- </div>
- <div id="map"></div>
- <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>
- <script>
- var map, layer, img, selectGraphic, vectorLayer, graphicLayer1, graphicLayer2, hitGraphicLayer,
- host = window.isLocal ? window.server : "https://iserver.supermap.io",
- url = host + "/iserver/services/map-china400/rest/maps/China";
- init();
- function init() {
- if (!document.createElement("canvas").getContext) {
- widgets.alert.showAlert(resources.msg_supportCanvas, false);
- return;
- }
- map = new SuperMap.Map("map", {
- controls: [
- new SuperMap.Control.Zoom(),
- new SuperMap.Control.Navigation(),
- ]
- });
- map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
- layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, null, {maxResolution: "auto"});
- layer.events.on({"layerInitialized": addLayer});
- graphicLayer1 = new SuperMap.Layer.Graphics("Graphic Layer"); //不可以选择,未开启事件
- graphicLayer2 = new SuperMap.Layer.Graphics("Can Select Graphic Layer", null, {hitDetection: true}); //可以选择,开启事件
- hitGraphicLayer = new SuperMap.Layer.Graphics("hit Graphic Layer");
- }
- function addLayer() {
- map.addLayers([layer, graphicLayer1, graphicLayer2, hitGraphicLayer]);
- //显示地图范围
- map.setCenter(new SuperMap.LonLat(0, 0), 3);
- //选择控件
- selectGraphic = new SuperMap.Control.SelectGraphic(graphicLayer2, {
- onSelect: onGraphicSelect,
- onUnselect: onGraphicUnSelect
- });
- map.addControl(selectGraphic);
- selectGraphic.activate();
- }
- //选择graphic 高亮处理某个选择的扇叶
- var hitClover = new SuperMap.Style.HitClover();
- function onGraphicSelect(result, evt) {
- //console.log(result);
- hitGraphicLayer.removeAllGraphics();
- var image = result.style.image;
- var pixel = map.getPixelFromLonLat(new SuperMap.LonLat(result.geometry.x, result.geometry.y));
- var evtPixel = evt.xy;
- //点击点与中心点的角度
- var angle = (Math.atan2(evtPixel.y - pixel.y, evtPixel.x - pixel.x)) / Math.PI * 180;
- angle = angle > 0 ? angle : 360 + angle;
- //确定扇叶
- var index = Math.ceil(angle / (result.style.image.angle + result.style.image.spaceAngle));
- //扇叶的起始角度
- var sAngle = (index - 1) * (image.angle + image.spaceAngle);
- //渲染参数
- var renderOpt = {
- strokeStyle: new SuperMap.Style.Stroke({
- color: "#ff0000",
- width: 1
- }),
- fillStyle: new SuperMap.Style.Fill({
- color: "#0099ff"
- }),
- size: image.size,
- radius: image.radius,
- angle: image.angle,
- eAngle: sAngle + image.angle,
- sAngle: sAngle
- };
- hitClover.render(renderOpt);
- var hitGraphic = new SuperMap.Graphic(result.geometry);
- hitGraphic.style = {
- image: hitClover
- };
- hitGraphicLayer.addGraphics([hitGraphic]);
- }
- //没有选中
- function onGraphicUnSelect() {
- // to do
- }
- //clover 符号
- var radius = [10, 14, 18];
- var styles = [{angle: 60, count: 3}, {angle: 45, count: 4}, {angle: 30, count: 6}];
- var sybolCount = radius.length * styles.length;
- var clovers = [];
- for (var i = 0; i < radius.length; i++) {
- for (var j = 0; j < styles.length; j++) {
- clovers.push(new SuperMap.Style.Clover({
- radius: radius[i],
- angle: styles[j].angle,
- count: styles[j].count,
- fill: new SuperMap.Style.Fill({
- color: "rgba(0,200,0,0.6)"
- }),
- stroke: new SuperMap.Style.Stroke({
- color: "rgba(0,166,0,1)",
- width: 1
- })
- }));
- }
- }
- //消耗时间计算 t2-t1
- var t1, t2;
- var e = 10000000;
- function drawClovers(graphicLayer) {
- graphicLayer.removeAllGraphics();
- var total = document.getElementById("total").value;
- t1 = new Date().getTime();
- var points = [];
- for (var i = 0; i < total; i++) {
- var point = new SuperMap.Geometry.Point(2 * e * Math.random() - e, 2 * e * Math.random() - e);
- var pointVector = new SuperMap.Graphic(point);
- pointVector.style = {
- image: clovers[i % sybolCount]
- };
- points.push(pointVector)
- }
- graphicLayer.addGraphics(points);
- t2 = new Date().getTime();
- //console.info(total + "个总时间为:" + (t2-t1) + "ms");
- widgets.alert.showAlert(resources.msg_totalTime1 + total + resources.msg_totalTime2 + (t2 - t1) + "ms", true);
- }
- //绘制不可选中符号
- function addData1() {
- widgets.alert.clearAlert();
- graphicLayer2.removeAllGraphics();
- hitGraphicLayer.removeAllGraphics();
- drawClovers(graphicLayer1);
- }
- //绘制可选中符号
- function addData2() {
- widgets.alert.clearAlert();
- graphicLayer1.removeAllGraphics();
- hitGraphicLayer.removeAllGraphics();
- drawClovers(graphicLayer2);
- }
- </script>
- </body>
- </html>
|