TileVectorTopic.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
  6. <meta name="apple-mobile-web-app-capable" content="yes"/>
  7. <title>矢量分块专题</title>
  8. <link href='./css/bootstrap.min.css' rel='stylesheet'/>
  9. <link href='./css/bootstrap-responsive.min.css' rel='stylesheet'/>
  10. <link href='./css/sm-extend.css' rel='stylesheet'/>
  11. <link href='./css/sm-doc.css' rel='stylesheet'/>
  12. <style type="text/css">
  13. .table{
  14. display: inline-block;
  15. float: left;
  16. vertical-align: top;
  17. width:450px;
  18. margin: 2px;
  19. }
  20. .CDescriptionList {
  21. margin: .5em 5ex 0 5ex
  22. }
  23. .CDLEntry {
  24. color: #808080;
  25. font: 10pt "Courier New",Courier,monospace;
  26. padding-bottom: 0.25em;
  27. white-space: nowrap;
  28. }
  29. .CDLDescription {
  30. font-size: 10pt;
  31. padding-bottom: 0.5em;
  32. padding-left: 5ex;
  33. }
  34. table {
  35. background-color: transparent;
  36. border-collapse: collapse;
  37. border-spacing: 0;
  38. max-width: 100%;
  39. width: 700px;
  40. }
  41. td {
  42. border: 1px solid #ddd;
  43. vertical-align: top;
  44. }
  45. .img{
  46. width:450px;
  47. height:310px;
  48. }
  49. </style>
  50. </head>
  51. <body data-spy="scroll" data-target=".subnav" data-offset="50">
  52. <!--导航条-->
  53. <div class="navbar navbar-fixed-top" id="navbar"></div>
  54. <script src="js/navbar.js"></script>
  55. <div id='container' class='container'>
  56. <div class='page-header'>
  57. <h1>矢量分块专题</h1>
  58. <hr/>
  59. <h2>一、背景</h2>
  60. <p>自从谷歌地图以来,很多地图服务商都根据谷歌地图的金字塔模型,实现了一套切图系统。这种方式在客户端只需要根据地理范围以及缩放级别,就可以请求相应的地图瓦片,
  61. 然后再把瓦片拼接起来,就完成了地图在客户端的地图的展示。这种方式很好的避免了网络带宽以及客户端渲染能力弱的问题,这在当时也是WebGIS出图的一个好的解决方案。</p>
  62. <p>但是,当需要修改地图的显示风格时,必须关闭服务器,然后用对地图数据进行重新处理并重新配图,然后再打开服务器重新切图,最后才能在客户端进行新地图的展示。
  63. 这样就带来了一些不必要的维护问题。随着网络带宽的日益增长,以及客户端渲染能力的增强,我们可以考虑利用客户端对地图进行实时的渲染,让用户可以直接在客户端完成地图的风格的定制,
  64. 方便人们通过互联网轻松地完成地图配图工作,从而免去一些服务器维护工作。矢量分块就是客户端矢量地图实时渲染的一个实现。</p>
  65. <h2>二、简介</h2>
  66. <p>矢量分块属于客户端的矢量地图,地图的渲染全部都在客户端完成。服务器提供地图矢量数据,以及地图的渲染风格属性信息,这样客户端就可以将地图渲染出来。
  67. 矢量分块的实现也类似于金字塔模型,只不过这些切片都是一块一块的矢量切片数据,每个矢量切片数据都是按照瓦片的范围进行裁剪得到。
  68. 客户端根据瓦片的位置以及比例尺向服务器请求矢量切片。每个矢量切片都包含多个数据集,一个数据集相当于一个图层,每个数据集都包含了多个要素,包括点、线、面和文本要素。
  69. 此外,服务器上还包含有每个图层的渲染风格信息,比如线宽,面的颜色等等信息。客户端根据这些信息就可以将矢量切片数据渲染成地图。</p>
  70. <p>矢量分块除了提供根据服务端的渲染风格信息对地图进行渲染之外,还提供了用户自定义的渲染风格信息的渲染接口。这种渲染风格信息就是一种类CSS的地图风格样式表——
  71. <a href="https://www.mapbox.com/tilemill/docs/manual/carto/">CartoCSS</a>。其中,矢量分块只实现了CartoCSS标准中的一部分,除外,
  72. 还对标准的CartoCSS进行了相应的扩展。利用CartoCSS,用户可以方便地定义地图的渲染方式,从而定制属于自己的个性地图。
  73. </p>
  74. <h2>三、地图样式表的实现</h2>
  75. <h3>CartoCSS的变量:</h3><p> 在CartoCSS中,用户可以定义一个变量,然后在CartoCSS代码中使用,例如:</p>
  76. <pre class="prettyprint">@color:#000;
  77. @width:2;
  78. #China_Road_L___China400{
  79. line-color:@color;
  80. line-width:@width;
  81. }</pre>
  82. <h3>CartoCSS的选择器: </h3>
  83. <h4>ID选择器:</h4>
  84. <p>图层ID默认为将图层名中的"@"与"#"符号替换为"___"双划线,例如:图层名为:"China_Road_L@China400#1"会替换为:"China_Road_L___China400___1"</p>
  85. <pre class="prettyprint">#China_Road_L___China400{
  86. }</pre>
  87. <h4>类选择器:</h4>
  88. <p>图层类名默认为与图层ID保持一致</p>
  89. <pre class="prettyprint">.China_Road_L___China400{
  90. }</pre>
  91. <h4>要素ID属性选择器:</h4>
  92. <p>目前只支持featureID要素属性</p>
  93. <pre class="prettyprint">#China_Road_L___China400{
  94. [featureID=1]{
  95. line-width:3;
  96. }
  97. }</pre>
  98. <h4>缩放级别控制: </h4>
  99. <p>可以通过zoom来控制图层在不同缩放级别下的样式符号</p>
  100. <pre class="prettyprint">#China_Road_L___China400{
  101. [zoom&gt;4]{
  102. line-width:2;
  103. }
  104. }</pre>
  105. <h4>高亮显示: </h4>
  106. <p>点击高亮以及鼠标移动高亮</p>
  107. <pre class="prettyprint">#China_Road_L___China400{
  108. ::click{
  109. line-color:#f00;
  110. }
  111. ::hover{
  112. line-color:#0f0;
  113. }
  114. }</pre>
  115. <h4>伪类: </h4>
  116. <p>当要素对同一图层定义不同的样式时可用到,如下,就定义了一根边框为红色,中间为黑色的线</p>
  117. <pre class="prettyprint">#China_Road_L___China400::one{
  118. line-color:#f00;
  119. line-width:10;
  120. }
  121. #China_Road_L___China400::tow{
  122. line-color:#000;
  123. line-width:2;
  124. }</pre>
  125. <h4>效果如下</h4>
  126. <div class="pageImage"><img style="width: 80%;height:400px;" src="./images/lineSymbol.png"/></div>
  127. <br>
  128. <h3 class="CHeading">CartoCSS实现的属性</h3>
  129. <p>其中的Color类型可为十六进行字符串:#000,也可为rgb:rgb(0,0,0)或者rgba:rgba(0,0,0,1)类型,和hsl类型:hsl(0.5,0.5,0.5)。 而point-comp-op的值可为以下几种:src-over、dst-over、src-in、dst-in、src-out、dst-atop、xor、plus、lighten。</p>
  130. <h4 class="CHeading">点图层属性:</h4>
  131. <table border="0" cellspacing="0" cellpadding="0" class="CDescriptionList">
  132. <tbody>
  133. <tr>
  134. <td class="CDLEntry">point-file</td>
  135. <td class="CDLDescription">{URL} 点符号的文件url,格式为:url(“./examples/images/marker.png”)。</td>
  136. </tr>
  137. <tr>
  138. <td class="CDLEntry">point-fill</td>
  139. <td class="CDLDescription">{Color} 矢量点符号的颜色值,只有当point-file为空时点才会被渲染成矢量点,格式为:#000。</td>
  140. </tr>
  141. <tr>
  142. <td class="CDLEntry">point-dx</td>
  143. <td class="CDLDescription">{Number} 点在x轴上的偏移值,单位为px,正值为右移,负值为左移。</td>
  144. </tr>
  145. <tr>
  146. <td class="CDLEntry">point-dy</td>
  147. <td class="CDLDescription">{Number} 点在y轴上的偏移值,单位为px,正值为下移,负值为上移。</td>
  148. </tr>
  149. <tr>
  150. <td class="CDLEntry">point-opacity</td>
  151. <td class="CDLDescription">{Number} 点的透明度,值的范围为0~1。</td>
  152. </tr>
  153. <tr>
  154. <td class="CDLEntry">point-comp-op</td>
  155. <td class="CDLDescription">{String} 属性设置或返回如何将一个源(新的)图像绘制到目标(已有)的图像上,其中源图像是指您打算放置到地图上的绘图,而目标图像则指您已经放置在地图上的绘图。</td>
  156. </tr>
  157. </tbody>
  158. </table>
  159. <h4 class="CHeading">线图层属性:</h4>
  160. <table border="0" cellspacing="0" cellpadding="0" class="CDescriptionList">
  161. <tbody>
  162. <tr>
  163. <td class="CDLEntry">line-color</td>
  164. <td class="CDLDescription">{Color} 线的颜色值,格式为:#000。</td>
  165. </tr>
  166. <tr>
  167. <td class="CDLEntry">line-width</td>
  168. <td class="CDLDescription">{Number} 线宽度,单位为px。</td>
  169. </tr>
  170. <tr>
  171. <td class="CDLEntry">line-cap</td>
  172. <td class="CDLDescription">{String} 线端点的样式,值可为:平头”butt”、圆头”round”、方头”square”。</td>
  173. </tr>
  174. <tr>
  175. <td class="CDLEntry">line-join</td>
  176. <td class="CDLDescription">{String} 线的拐角处的样式,值可为:泄角”bevel”、圆角”round”、尖角”miter”。</td>
  177. </tr>
  178. <tr>
  179. <td class="CDLEntry">line-miterlimit</td>
  180. <td class="CDLDescription">{Number} 线的最大斜接长度。</td>
  181. </tr>
  182. <tr>
  183. <td class="CDLEntry">line-dash-offset</td>
  184. <td class="CDLDescription">{Number} 虚线模式的偏移值,即虚线从偏移值处才开始虚线的绘制,被偏移掉的一段为实线。</td>
  185. </tr>
  186. <tr>
  187. <td class="CDLEntry">line-opacity</td>
  188. <td class="CDLDescription">{Number} 线的透明度,值为0~1。</td>
  189. </tr>
  190. <tr>
  191. <td class="CDLEntry">line-dasharray</td>
  192. <td class="CDLDescription">{Array} 虚线的模式,格式为:10,10,其中第0个值为第一段实线的长度,第1个值为第一段空线的长度,后面的虚线按照这个模式重复。</td>
  193. </tr>
  194. <tr>
  195. <td class="CDLEntry">line-offset</td>
  196. <td class="CDLDescription">{Number} 线的偏移,单位为px,正值为向左偏移,负值为向右偏移。</td>
  197. </tr>
  198. <tr>
  199. <td class="CDLEntry">line-comp-op</td>
  200. <td class="CDLDescription">{String} 同point-comp-op。</td>
  201. </tr>
  202. </tbody>
  203. </table>
  204. <h4 class="CHeading">面图层属性(面支持除了line-offset、line-comp-op和line-opacity之外的所有线属性):</h4>
  205. <table border="0" cellspacing="0" cellpadding="0" class="CDescriptionList">
  206. <tbody>
  207. <tr>
  208. <td class="CDLEntry">polygon-fill</td>
  209. <td class="CDLDescription">{Color} 面填充的颜色,格式为:#000。</td>
  210. </tr>
  211. <tr>
  212. <td class="CDLEntry">polygon-dx</td>
  213. <td class="CDLDescription">{Number} 面在x轴上的偏移值,单位为px,正值为向右偏移,负值为向左偏移。</td>
  214. </tr>
  215. <tr>
  216. <td class="CDLEntry">polygon-dy</td>
  217. <td class="CDLDescription">{Number} 面在y轴上的偏移值,单位为px,正值为向下偏移,负值为向上偏移。</td>
  218. </tr>
  219. <tr>
  220. <td class="CDLEntry">polygon-comp-op</td>
  221. <td class="CDLDescription">{String} 同point-comp-op。</td>
  222. </tr>
  223. </tbody>
  224. </table>
  225. <h4 class="CHeading">文本图层属性:</h4>
  226. <table border="0" cellspacing="0" cellpadding="0" class="CDescriptionList">
  227. <tbody>
  228. <tr>
  229. <td class="CDLEntry">text-size</td>
  230. <td class="CDLDescription">{Number} 文本的尺寸,单位为px。</td>
  231. </tr>
  232. <tr>
  233. <td class="CDLEntry">text-face-name</td>
  234. <td class="CDLDescription">{String} 文本的字体名称,如:Times New Roman。</td>
  235. </tr>
  236. <tr>
  237. <td class="CDLEntry">text-align</td>
  238. <td class="CDLDescription">{String} 文本在水平方向的对齐方式,值可为:center、left、right。</td>
  239. </tr>
  240. <tr>
  241. <td class="CDLEntry">text-vertical-alignment</td>
  242. <td class="CDLDescription">{String} 文本在垂直方向上的对齐方式,值可为:top、middle、baseLine、bottom。</td>
  243. </tr>
  244. <tr>
  245. <td class="CDLEntry">text-halo-radius</td>
  246. <td class="CDLDescription">{Number} 文本外围边框的宽度。</td>
  247. </tr>
  248. <tr>
  249. <td class="CDLEntry">text-fill</td>
  250. <td class="CDLDescription">{Color} 文本的颜色。</td>
  251. </tr>
  252. <tr>
  253. <td class="CDLEntry">text-opacity</td>
  254. <td class="CDLDescription">{Number} 文本的透明度,值为0~1。</td>
  255. </tr>
  256. <tr>
  257. <td class="CDLEntry">text-dx</td>
  258. <td class="CDLDescription">{Number} 文本在x轴上的偏移值,单位为px,正值为向右偏移,负值为向左偏移。</td>
  259. </tr>
  260. <tr>
  261. <td class="CDLEntry">text-dy</td>
  262. <td class="CDLDescription">{Number} 文本在y轴上的偏移值,单位为px,正值为向下偏移,负值为向上偏移。</td>
  263. </tr>
  264. <tr>
  265. <td class="CDLEntry">text-comp-op</td>
  266. <td class="CDLDescription">{String} 同point-comp-op。</td>
  267. </tr>
  268. </tbody>
  269. </table>
  270. <h2>四、使用说明</h2>
  271. <p>使用矢量分块进行客户端地图的配图非常容易上手,只需要创建一个矢量分块图层,然后编辑地图样式表就可以配出一幅好地图了,但是要配好一幅地图对用户对地图样式表——CartoCSS
  272. 的掌握程度要求比较高,因此,想在客户端配出一幅好地图,必须掌握好CartoCSS。以下为矢量分块客户端配图的详细步骤:</p>
  273. <h4>1、创建TiledVectorLayer图层</h4>
  274. <p>要使用矢量分块功能,必须先创建一个TiledVectorLayer图层并添加到地图中,例如:</p>
  275. <pre>
  276. layer = new SuperMap.Layer.TiledVectorLayer("China", url,{cacheEnabled:true}});
  277. layer.events.on({"layerInitialized": addLayer});
  278. function addLayer() {
  279. map.addLayers([layer]);
  280. var center = new SuperMap.LonLat(0,0);
  281. map.setCenter(center, 0);
  282. }</pre>
  283. <h4>2、编辑CartoCSS样式表</h4>
  284. <pre>
  285. var cartoCss=["#World_Continent___China400{",
  286. "polygon-fill:rgb(245,243,240);",
  287. "line-width:1;",
  288. "line-color:#ddd;",
  289. "::hover[featureID=73]{",
  290. "polygon-fill:#f00;",
  291. "}",
  292. "}"].join("\n");</pre>
  293. <h4>3、应用CartoCSS</h4>
  294. <pre>
  295. layer.setCartoCSS(cartoCss);</pre>
  296. <h4>4、其他用法</h4>
  297. <p>其中的CartoCSS样式文件也可以在创建TiledVectorLayer图层时传递进去,例如:</p>
  298. <pre>
  299. layer = new SuperMap.Layer.TiledVectorLayer("China", url,{cacheEnabled:true},{cartoCss:cartoCss});</pre>
  300. <p>也可以将cartoCSS样式保存在一个script标签里(把标签的type属性设置为"text"),然后获取下来,并设置到TiledVectorLayer上,例如:</p>
  301. <pre>
  302. &lt;script type="text" id="cartoCssStr"&gt;
  303. @color:#111;
  304. #China_Railway_L___China400::one{
  305. line-color:@color;
  306. line-width:2;
  307. }
  308. #China_Railway_L___China400::two{
  309. line-dasharray:15,15;
  310. line-color:#DDDDDD;
  311. line-width:1.5;
  312. }
  313. &lt;/script&gt;
  314. &lt;script&gt;
  315. var cartoCss=document.getElementById("cartoCssStr").text;
  316. layer.setCartoCSS(cartoCss);
  317. &lt;/script&gt;</pre>
  318. <h4>效果如下</h4>
  319. <div class="pageImage"><img style="width: 80%;height:400px;" src="./images/tileVector.png"/></div>
  320. <br>
  321. <p>此完整范例请见 示范程序-&gt;可视化-&gt;矢量分块-&gt;线符号。</p>
  322. <h2>三、其他示例</h2>
  323. <br>
  324. <p>利用矢量分块地图,通过精心地对地图进行配色,以及其他地图风格的调整,我们可以配出一些精美的地图,以下即是利用矢量分块的客户端配图功能配出来的几种不同风格地图</p>
  325. <div style="width: 100%;height: 380px" >
  326. <div class="table">
  327. <h4>&nbsp&nbsp1、淡雅绿风格</h4>
  328. <div> <img class="img" src="./images/greenStyle.png"/></div>
  329. <br>
  330. <p>此完整范例请见 示范程序-&gt;可视化-&gt;矢量分块-&gt;淡雅绿风格。</p>
  331. </div>
  332. <div class="table">
  333. <h4>&nbsp&nbsp2、月夜风格</h4>
  334. <div> <img class="img" src="./images/blackStyle.png"/> </div>
  335. <br>
  336. <p>此完整范例请见 示范程序-&gt;可视化-&gt;矢量分块-&gt;月夜风格。</p>
  337. </div>
  338. </div>
  339. <div style="width: 100%;height: 380px">
  340. <div class="table">
  341. <h4>&nbsp&nbsp3、深夜蓝黑风格</h4>
  342. <div> <img class="img" src="./images/darkblueStyle.png"/> </div>
  343. <br>
  344. <p>此完整范例请见 示范程序-&gt;可视化-&gt;矢量分块-&gt;深夜蓝黑风格。</p>
  345. </div>
  346. <div class="table">
  347. <h4>&nbsp&nbsp4、强边界风格</h4>
  348. <div> <img class="img" src="./images/boundryStyle.png"/> </div>
  349. <br>
  350. <p>此完整范例请见 示范程序-&gt;可视化-&gt;矢量分块-&gt;强边界风格。</p>
  351. </div>
  352. </div>
  353. </div>
  354. </div>
  355. <div class='footer'>
  356. <p>版权所有&nbsp;&copy; 2000-2016 &nbsp;北京超图软件股份有限公司</p>
  357. </div>
  358. </div>
  359. <script src='./js/jquery.js'></script>
  360. <script src='./js/bootstrap.js'></script>
  361. <script src="./js/navbar.js"></script>
  362. <script src="./js/GoTop.js" id="js_gotop"></script>
  363. </body>
  364. </html>