关于WEB端实现电子海图之Openlayers加载切片

记笔记,免忘记!

关于WEB端实现电子海图研究之思路

关于WEB端实现电子海图研究二GeoServer

GeoServer完成shp文件切矢量图后,我们需要加载GeoServer切片在web上展示。

vector-tiles-tutorial官方示例

以下示例使用openLayers来加载

D:\software\GeoServer 2.13.1\data_dir\www目录下新建一个文件夹vectortiles新建文件如下图,我为了方便自己使用EPSG编码命名的文件

示例正确显示
正确的地图显示

 

 EPSG:900913下代码:

以下只能900913。如果使用EPSG:4326显示不了。(因为这里我用下面的代码使用EPSG:4326,一直不显示,查了N个页面都不行,费时2天才知道只能EPSG:900913)

<!DOCTYPE html>
<html>

<head>
    <title>Vector tiles</title>
    <script src="./ol3/ol.js"></script>
    <link rel="stylesheet" href="./ol3/ol.css">
    <style>
        html,
        body {
            font-family: sans-serif;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }

        .map {
            height: 100%;
            width: 100%;
            overflow: hidden;
        }
    </style>
</head>

<body>
    <h3>Mapbox Protobuf - vector tiles</h3>
    <div id="map" class="map"></div>
    <script>
        var style_simple = new ol.style.Style({
            fill: new ol.style.Fill({
                color: '#ADD8E6'
            }),
            stroke: new ol.style.Stroke({
                color: '#88eee',
                width: 1
            })
        });

        function simpleStyle(feature) {
            return style_simple;
        }

        var layer = 'cite:COALNE';
        var projection_epsg_no = '900913';
        var map = new ol.Map({
            target: 'map',
            view: new ol.View({
                // center: [0, 0], 
                //如果是世界全部地图可以用0,0,否则需要给个点,不然会显示不了
                center:[12348169, 889341],
                zoom: 6
            }),
            layers: [new ol.layer.VectorTile({
                style: simpleStyle,
                source: new ol.source.VectorTile({
                    tilePixelRatio: 1,
                    tileGrid: ol.tilegrid.createXYZ({
                        maxZoom: 19
                    }),
                    format: new ol.format.MVT(),
                    url: '/geoserver/gwc/service/tms/1.0.0/' + layer +
                        '@EPSG%3A' + projection_epsg_no + '@pbf/{z}/{x}/{-y}.pbf'
                })
            })]
        });
    </script>
</body>

</html>

 页面代码完了后,访问下面链接地址:如果本地直接通过文件打开到浏览器会出现跨域问题(跨域问题后续再写)缩小后,和正确显示的一致

http://localhost:2048/geoserver/www/vectortiles/900913.html

 

EPSG:4326下代码:(js部分,其它参见上面EPSG:900913代码)

        var map = new ol.Map({
            target: 'map',
            view: new ol.View({
                center: [110.478515, 6.811523],
                zoom: 7,
                projection: 'EPSG:4326',
            }),
            layers: [new ol.layer.VectorTile({
                style: simpleStyle,
                projection: "EPSG:4326",
                source: new ol.source.VectorTile({
                    tilePixelRatio: 1, 
                    tileGrid: ol.tilegrid.createXYZ({
                        extent: ol.proj.get('EPSG:4326').getExtent(),
                        maxZoom: 19
                    }),
                    format: new ol.format.MVT(),
                    // 矢量切片服务地址
                    tileUrlFunction: function (tileCoord, pixelRatio, proj) {
                        console.log(
                            tileCoord, pixelRatio, proj,
                        )
                    },
                })
            })]
        });

代码跑后截图如下,说明epgs是4326的

tileUrlFunction函数尝试一:(失败)

tileUrlFunction: function (tileCoord) {
   console.log(tileCoord,(Math.pow(2, tileCoord[0] - 1) - 1 - tileCoord[2]))
   const url =`/geoserver/gwc/service/tms/1.0.0/cite:COALNE@EPSG%3A4326@pbf/${(tileCoord[0] - 1)}/${tileCoord[1]}/${(Math.pow(2, tileCoord[0] - 1) - 1 - tileCoord[2])}.pbf`;
   return url;
}

 截图如下

 然后去\data_dir\gwc\cite_COALNE\EPSG_4326_06中进入子文件夹查看切片,发现确实没有上面截图对应的数字,所以说明y是错误的

tileUrlFunction函数尝试二:(失败)

tileUrlFunction: function (tileCoord) {
   console.log(tileCoord)
   const url =`/geoserver/gwc/service/tms/1.0.0/cite:COALNE@EPSG%3A4326@pbf/${(tileCoord[0] - 1)}/${tileCoord[1]}/${-tileCoord[2]}.pbf`;
   return url;
}

 截图如下:和正确的图对比后,发现下部分跑去上部分了,说明Y值还是不对。

tileUrlFunction函数尝试三:(成功)

tileUrlFunction: function (tileCoord) {
   console.log(tileCoord,(Math.pow(2, tileCoord[0] - 1) + tileCoord[2]))
   const url =`/geoserver/gwc/service/tms/1.0.0/cite:COALNE@EPSG%3A4326@pbf/${(tileCoord[0] - 1)}/${tileCoord[1]}/${(Math.pow(2, tileCoord[0] - 1) + tileCoord[2])}.pbf`;
   return url;
}

截图如下:缩小后对比后和正确显示的图保持一致,说明成功 

报错:

同时在研究中,发现设置 projection: "EPSG:4326" 后会报错如下图:

如果你的报这个错,可能ol版本太高了(都是泪。最开始我用的最新版本7以上的。一直不行)

 

易错点:图层加载不出来的原因大多是因为格网方案的参数设置和坐标系统不匹配导致。

先记录到这,后续有其它再补充!

其它可参考:

Geoserver发布矢量切片服务及使用openlayer调用展示

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
xv Contents Graphical Debugging Tools 299 DDD 299 Eclipse 302 Kernel Debugging 305 Don’t Panic! 306 Making Sense of an oops 307 Using UML for Debugging 309 An Anecdotal Word 312 A Note about In-Kernel Debuggers 313 Summary 313 Chapter 11: The GNOME Developer Platform 315 GNOME Libraries 316 Glib 316 GObject 316 Cairo 316 GDK 317 Pango 317 GTK+ 317 libglade 318 GConf 318 GStreamer 318 Building a Music Player 319 Requirements 319 Getting Started: The Main Window 319 Building the GUI 321 Summary 340 Chapter 12: The FreeDesktop Project 341 D-BUS: The Desktop Bus 341 What Is D-Bus? 342 Under D-Hood of D-Bus 342 D-Bus Methods 346 Hardware Abstraction Layer 350 Making Hardware Just Work 350 Hal Device Objects 353 The Network Manager 358 Other Freedesktop Projects 360 Summary 360 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xv xvi Contents Chapter 13: Graphics and Audio 361 Linux and Graphics 361 X Windows 362 Open Graphics Library 364 OpenGL Utilities Toolkit 365 Simple Directmedia Layer 365 Writing OpenGL Applications 365 Downloading and Installing 366 Programming Environment 367 Using the GLUT Library 368 Writing SDL Applications 382 Downloading and Installing 382 Programming Environment 383 Using the SDL Library 383 Summary 394 Chapter 14: LAMP 395 What Is LAMP? 395 Apache 396 MySQL 396 PHP 397 The Rebel Platform 397 Evaluating the LAMP Platform 397 Apache 399 Virtual Hosting 400 Installation and Configuration of PHP 5 401 Apache Basic Authentication 402 Apache and SSL 402 Integrating SSL with HTTP Authentication 403 MySQL 404 Installing MySQL 404 Configuring and Starting the Database 404 Changing the Default Password 405 The MySQL Client Interface 405 Relational Databases 405 SQL 406 The Relational Model 409 PHP 411 The PHP Language 411 Error Handling 420 Error-Handling Exceptions 421 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xvi xvii Contents Optimization Techniques 422 Installing Additional PHP Software 427 Logging 427 Parameter Handling 428 Session Handling 429 Unit Testing 430 Databases and PHP 432 PHP Frameworks 432 The DVD Library 433 Version 1: The Developer’s Nightmare 433 Version 2: Basic Application with DB-Specific Data Layer 434 Version 3: Rewriting the Data Layer,Adding Logging and Exceptions 437 Version 4: Applying a Templating Framework 441 Summary 442 Index 443 GNU 47 Acknowledgments ix Introduction xix Chapter 1: Working with Linux 1 A Brief History of Linux 2 The GNU Project 2 The Linux Kernel 3 Linux Distributions 4 Free Software vs. Open Source 4 Beginning Development 5 Choosing a Linux Distribution 6 Installing a Linux Distribution 8 Linux Community 15 Linux User Groups 15 Mailing lists 16 IRC 16 Private Communities 16 Key Differences 16 Linux Is Modular 17 Linux Is Portable 17 Linux Is Generic 17 Summary 18 Chapter 2: Toolchains 19 The Linux Development Process 19 Working with Sources 20 Configuring to the Local Environment 21 Building the Sources 22 Components of the GNU Toolchain 23 The GNU Compiler Collection 23 The GNU binutils 34 GNU Make 39 The GNU Debugger 40 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xi xii Contents The Linux Kernel and the GNU Toolchain 44 Inline Assembly 44 Attribute Tags 45 Custom Linker Scripts 45 Cross-Compilation 46 Building the GNU Toolchain 47 Summary 48 Chapter 3: Portability 49 The Need for Portability 50 The Portability of Linux 51 Layers of Abstraction 51 Linux Distributions 52 Building Packages 57 Portable Source Code 70 Internationalization 81 Hardware Portability 88 64-Bit Cleanliness 89 Endian Neutrality 89 Summary 92 Chapter 4: Software Configuration Management 93 The Need for SCM 94 Centralized vs. Decentralized Development 95 Centralized Tools 95 The Concurrent Version System 96 Subversion 104 Decentralized tools 108 Bazaar-NG 109 Linux kernel SCM (git) 112 Integrated SCM Tools 115 Eclipse 115 Summary 117 Chapter 5: Network Programming 119 Linux Socket Programming 119 Sockets 120 Network Addresses 122 Using Connection-Oriented Sockets 123 Using Connectionless Sockets 130 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xii xiii Contents Moving Data 133 Datagrams vs. Streams 133 Marking Message Boundaries 137 Using Network Programming Libraries 140 The libCurl Library 140 Using the libCurl Library 141 Summary 147 Chapter 6: Databases 149 Persistent Data Storage 149 Using a Standard File 150 Using a Database 150 The Berkeley DB Package 152 Downloading and Installing 153 Building Programs 154 Basic Data Handling 154 The PostgreSQL Database Server 165 Downloading and Installing 165 Building Programs 167 Creating an Application Database 167 Connecting to the Server 169 Executing SQL Commands 173 Using Parameters 181 Summary 184 Chapter 7: Kernel Development 185 Starting Out 185 Kernel Concepts 199 A Word of Warning 200 The Task Abstraction 200 Virtual Memory 205 Don’t Panic! 208 Kernel Hacking 208 Loadable Modules 209 Kernel Development Process 211 Git: the “Stupid Content Tracker” 212 The Linux Kernel Mailing List 213 The “mm” Development Tree 215 The Stable Kernel Team 215 LWN: Linux Weekly News 216 Summary 216 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xiii xiv Contents Chapter 8: Kernel Interfaces 217 What Is an Interface? 217 Undefined Interfaces 218 External Kernel Interfaces 219 System Calls 219 The Device File Abstraction 224 Kernel Events 238 Ignoring Kernel Protections 239 Internal Kernel Interfaces 243 The Kernel API 243 The kernel ABI 244 Summary 245 Chapter 9: Linux Kernel Modules 247 How Modules Work 247 Extending the Kernel Namespace 250 No Guaranteed Module Compatibility 251 Finding Good Documentation 251 Linux Kernel Man Pages 251 Writing Linux Kernel Modules 252 Before You Begin 253 Essential Module Requirements 253 Logging 256 Exported Symbols 257 Allocating Memory 259 Locking considerations 267 Deferring work 275 Further Reading 283 Distributing Linux Kernel Modules 284 Going Upstream 284 Shipping Sources 284 Shipping Prebuilt Modules 284 Summary 285 Chapter 10: Debugging 287 Debugging Overview 287 A Word about Memory Management 288 Essential Debugging Tools 289 The GNU Debugger 289 Valgrind 298 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xiv

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值