简体   繁体   中英

OpenLayers with map starting in Australia

I'm very new to OpenLayers and I'm trying to show a map on my home page, which shows only Australia, and then later add some points on the map. The important thing right now, is to just open the map to Australia.

I'm using the example found on OpenLayers home page, with:

var map = new OpenLayers.Map('map');
var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
        "http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} );
....

I'm guessing that I have to pass something to the constructor to have it display only a specific region?

Thanks,

Sam

Found this on another stackoverflow question:

var bounds = new OpenLayers.Bounds(-125, 25, -65, 50);
var map = new OpenLayers.Map('map', {restrictedExtent: bounds  });

Open Layers uses projection to accommodate a 2D map of a 3D world. Projection is a mathematical way of saying that on a 3D sphere (the world) the coordinates x,y are actually x,y somewhere else on a 2D map. In openlayers this involves changing the view, you can use the fromLonLat() method. More information on projection here: https://openlayers.org/en/latest/doc/faq.html

 mapOfAustralia = new ol.Map({ layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }) ], target: targetElement, controls: ol.control.defaults({ attributionOptions: { collapsible: false } }), view: new ol.View({ center: ol.proj.fromLonLat([133.7751, -23.2744]), zoom: 4 }) }); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM