Openlayers 2.x load map, openlayers2.x

Source: Internet
Author: User

Openlayers 2.x load map, openlayers2.x

Overview:

In the previous section, we talked about how Arcgis for js loads a map of heaven and earth, how to load a map of heaven and earth in Openlayers 2. X, and how to add your own wms service.


Effect:


Map


Images


Terrain


Remove local wms

Implementation:

1. Map World Service

On the official website of map, we can see the following:


The url of our callable graph is listed on the page. The website address is http://www.tianditu.com/guide/index.html.


2. Load map world

You can use openlayers. Layer. XYZ to load the world map in OpenLayers. Here, I encapsulate it into two functions: getBaseLayer and getAnnoLayer to implement the basemap and annotation layers respectively. The Code is as follows:

            function getBaseLayer(layername, layer){                return new OpenLayers.Layer.XYZ(                        layername,                        [                            "http://t0.tianditu.com/DataServer?T="+layer+"&X=${x}&Y=${y}&L=${z}",                            "http://t0.tianditu.com/DataServer?T="+layer+"&X=${x}&Y=${y}&L=${z}",                            "http://t0.tianditu.com/DataServer?T="+layer+"&X=${x}&Y=${y}&L=${z}",                            "http://t0.tianditu.com/DataServer?T="+layer+"&X=${x}&Y=${y}&L=${z}",                            "http://t0.tianditu.com/DataServer?T="+layer+"&X=${x}&Y=${y}&L=${z}",                            "http://t0.tianditu.com/DataServer?T="+layer+"&X=${x}&Y=${y}&L=${z}",                            "http://t0.tianditu.com/DataServer?T="+layer+"&X=${x}&Y=${y}&L=${z}",                            "http://t0.tianditu.com/DataServer?T="+layer+"&X=${x}&Y=${y}&L=${z}"                        ],                        {                            isBaseLayer: true,                            displayInLayerSwitcher:true                        }                );            };            function getAnnoLayer(layername, layer, visiable){                return new OpenLayers.Layer.XYZ(                        layername,                        [                            "http://t0.tianditu.com/DataServer?T="+layer+"&X=${x}&Y=${y}&L=${z}",                            "http://t0.tianditu.com/DataServer?T="+layer+"&X=${x}&Y=${y}&L=${z}",                            "http://t0.tianditu.com/DataServer?T="+layer+"&X=${x}&Y=${y}&L=${z}",                            "http://t0.tianditu.com/DataServer?T="+layer+"&X=${x}&Y=${y}&L=${z}",                            "http://t0.tianditu.com/DataServer?T="+layer+"&X=${x}&Y=${y}&L=${z}",                            "http://t0.tianditu.com/DataServer?T="+layer+"&X=${x}&Y=${y}&L=${z}",                            "http://t0.tianditu.com/DataServer?T="+layer+"&X=${x}&Y=${y}&L=${z}",                            "http://t0.tianditu.com/DataServer?T="+layer+"&X=${x}&Y=${y}&L=${z}"                        ],                        {                            isBaseLayer: false,                            visibility:visiable,                            displayInLayerSwitcher:false                        }                );            };
The call method is as follows:

Var baseLayers = ["vec_c", "img_c", "ter_c"]; var vecLayer = getBaseLayer ("map", baseLayers [0]); var imgLayer = getBaseLayer ("image", baseLayers [1]); var terLayer = getBaseLayer ("terrain", baseLayers [2]); var vecAnno = getAnnoLayer ("map annotation ", "cva_c", true );

The complete code is as follows:

<! DOCTYPE html> 





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.