|
| 1 | +<!DOCTYPE html> |
| 2 | +<html xmlns="http://www.w3.org/1999/xhtml"> |
| 3 | +<head> |
| 4 | + <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
| 5 | + <title>绘制军标(箭头)</title> |
| 6 | + <script include="draw,milstdbyleaflet" |
| 7 | + src="../../libs/zondyclient/include-leaflet-local.js"></script> |
| 8 | + <style> |
| 9 | + body { |
| 10 | + height: 700px; |
| 11 | + } |
| 12 | + </style> |
| 13 | + <script type="text/javascript"> |
| 14 | + var map; |
| 15 | + var layer; |
| 16 | + function init() { |
| 17 | + map = L.map('leaf_map', { |
| 18 | + //参考坐标系,默认是墨卡托坐标系(EPSG3857),EPSG4326为经纬度坐标系 |
| 19 | + crs: L.CRS.EPSG4326, |
| 20 | + //显示中心 |
| 21 | + center: [0, 0], |
| 22 | + //最小显示等级 |
| 23 | + minZoom: 1, |
| 24 | + //最大显示等级 |
| 25 | + maxZoom: 10, |
| 26 | + //当前显示等级 |
| 27 | + zoom: 1, |
| 28 | + //不显示放大缩小按钮 |
| 29 | + zoomControl: false, |
| 30 | + //限制显示地理范围 |
| 31 | + maxBounds: L.latLngBounds(L.latLng(-180, -180), L.latLng(180, 0)) |
| 32 | + }); |
| 33 | + |
| 34 | + //显示OSM地图 |
| 35 | + layer = L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", { |
| 36 | + //最小显示等级 |
| 37 | + minZoom: 1, |
| 38 | + //最大显示等级 |
| 39 | + maxZoom: 15, |
| 40 | + //设置地图不连续显示 |
| 41 | + noWrap: true |
| 42 | + }).addTo(map); |
| 43 | + } |
| 44 | + |
| 45 | + var feature = null; |
| 46 | + //定义绘制图标 |
| 47 | + function add() { |
| 48 | + if (feature !== null) { |
| 49 | + //清空地图 |
| 50 | + feature.remove(); |
| 51 | + } |
| 52 | + |
| 53 | + var vertices = [[60, -40], [60, -20], [47, -30]]; |
| 54 | + |
| 55 | + var milStdType = document.getElementById("typeSelect").value; |
| 56 | + |
| 57 | + //根据选中的军标类型(箭头)绘制图形 |
| 58 | + switch (milStdType) { |
| 59 | + case "SimpleArrow": |
| 60 | + var milParam = new MilStd.MilstdParams({ |
| 61 | + headHeightFactor: 0.15, |
| 62 | + headWidthFactor: 0.4, |
| 63 | + neckHeightFactor: 0.75, |
| 64 | + neckWidthFactor: 0.1, |
| 65 | + tailWidthFactor: 0.1, |
| 66 | + hasSwallowTail: true, |
| 67 | + swallowTailFactor: 0.5 |
| 68 | + }); |
| 69 | + break; |
| 70 | + case "DoubleArrow": |
| 71 | + var milParam = new MilStd.MilstdParams({ |
| 72 | + headHeightFactor: 0.15, |
| 73 | + headWidthFactor: 0.8, |
| 74 | + neckHeightFactor: 0.7, |
| 75 | + neckWidthFactor: 0.4 |
| 76 | + }); |
| 77 | + vertices = [[90, -60], [60, -60], [90, -30], [60, -30]]; |
| 78 | + break; |
| 79 | + case "StraightArrow": |
| 80 | + var milParam = new MilStd.MilstdParams({ |
| 81 | + headHeightFactor: 0.1, |
| 82 | + headWidthFactor: 1.3, |
| 83 | + neckHeightFactor: 1.0, |
| 84 | + neckWidthFactor: 0.7, |
| 85 | + tailWidthFactor: 0.07, |
| 86 | + hasSwallowTail: false, |
| 87 | + swallowTailFactor: 0 |
| 88 | + }); |
| 89 | + break; |
| 90 | + case "SingleLineArrow": |
| 91 | + var milParam = new MilStd.MilstdParams({ |
| 92 | + headHeightFactor: 0.1, |
| 93 | + headWidthFactor: 1.3 |
| 94 | + }); |
| 95 | + break; |
| 96 | + } |
| 97 | + //根据选择类型,用算法绘制相应的图形 |
| 98 | + var parseDots = MilStd.Arrow.getArrowFromVert(vertices, milStdType, milParam); |
| 99 | + //根据最新的算法坐标点绘制几何图形(SingleLineArrow画线,其余三个箭头画多边形) |
| 100 | + var tempPoly = null; //图形或线 |
| 101 | + if (milStdType === "SingleLineArrow") { |
| 102 | + tempPoly = L.polyline(parseDots); |
| 103 | + } else { |
| 104 | + tempPoly = L.polygon(parseDots); |
| 105 | + } |
| 106 | + //将绘制的多边形添加到地图中(为箭头) |
| 107 | + this._PolygonLayer = new L.LayerGroup(); |
| 108 | + map.addLayer(this._PolygonLayer); |
| 109 | + tempPoly.addTo(this._PolygonLayer); |
| 110 | + feature = this._PolygonLayer; |
| 111 | + } |
| 112 | + |
| 113 | + </script> |
| 114 | +</head> |
| 115 | +<body onload="init()"> |
| 116 | +<div id="menu"> |
| 117 | + <label style="font-weight: bold;"> |
| 118 | + 要添加的箭头类型: |
| 119 | + </label> |
| 120 | + <select name="type" id="typeSelect"> |
| 121 | + <option value="SimpleArrow">简单箭头</option> |
| 122 | + <option value="DoubleArrow">双箭头</option> |
| 123 | + <option value="StraightArrow">直箭头</option> |
| 124 | + <option value="SingleLineArrow">单线箭头</option> |
| 125 | + </select> |
| 126 | + <button onclick="add()"> |
| 127 | + 开始添加 |
| 128 | + </button> |
| 129 | +</div> |
| 130 | +<div id="leaf_map" style="width: 100%; height: 95%; z-index: 1"> |
| 131 | +</div> |
| 132 | +</body> |
| 133 | +</html> |
0 commit comments