【NSBD】——My first Map

    Recently,In my project,we have to make a map by using the technology named OpenLayers.So I begin to learn openplayers on the Internet.


        On the Internet ,I find a book namedOpenLayers beginers guide.pdf,and the web sites ——"http://openlayers.org/" ,some API documents aboutOpenLayers.


     In this article , I want to introduce some simple things  about the OpenLayers,it include three questions:what is it ? why we use it ? and how to use it ?


     1、What is OpenLayers?

        OpenLayers is an open source , client side JavaScript library for making interactive web maps, viewable in nearly any web browser.


        (1) Client side 

        If you want to make aOpenLayers,you only need to things, the first thing is the code itself ,and the second thing is a web browser.you can use it on your own computer.


        (2)Library 

        It means that OpenLayers is an API, that provides you with tools to develop your own web maps.

     2、Why we use it ?

     It can help you create powerful web-mapping application very easily.So it's easy ,powerful and fun.


        (1)easy 

         you don't need to have the knowledge of GIS(Geographic Information System).OpenLayers is not tied to any proprietary technology or company, so you don't have to worry so much about your application breaking.



        (2)Powerful

         OpenLayers allows you to build entire mapping applications from the ground up, with the ability to customize every aspect of your map—layers, controls, events, etc. You can use a multitude of different map server backends together, including a powerful vector layer. And on the vector layers,you can also make markers.


     3、How to use it ?

        You only have to use a text editor such as  NotePad++  to  create a HTML file .In this HTML there has three steps to develop your own map easily.


         first ,you should import the css and Javascript about the openlayers.

          

 <link rel="stylesheet" href="http://openlayers.org/en/v3.17.1/css/ol.css" type="text/css">
    <style>
      .map {
        height: 400px;
        width: 100%;
      }
    </style>
    <script src="http://openlayers.org/en/v3.17.1/build/ol.js" type="text/javascript"></script>

        

        second ,you have to create a <div> as  the map container.


 <div id="map" class="map"></div>
<style>
    .map {
      height: 400px;
      width: 100%;
    }
  </style>

          third,write the JavaScript code to create a simple map 

           

 var map = new ol.Map({
    target: 'map',   //To attach the map object to the <div>, the map object takes a target into arguments. The value is the id of the <div>:
    layers: [
      new ol.layer.Tile({
        source: new ol.source.OSM()
      })
    ],
    view: new ol.View({
      center: ol.proj.fromLonLat([37.41, 8.82]),  //initialize the center position and the zoom size
      zoom: 4
    })
  });

         finally ,our  map is created successfully ,look at this picture,are you feel it's so easy? 


         



评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

幸运的梦之星

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值