2013-02-08 58 views
5

正如我從readme文件中得到的紅色,openlayers.js有多種選擇來包含文件和主題。OpenLayers.js要使用哪些文件?

我想要的是使用lightest solution of openlayers.js文件。

我包括我的應用程序的openlayers.light.js,並創建地圖,但不告訴他們,看看這個:

enter image description here

做我忘了,包括一些其他的文件嗎?

我的結構,結構是這樣的:

/vendor 
    /js 
    openlayers.light.js 
    /img 
    /theme 

如何顯示的地圖圖層?

此外openlayers.light.js將在移動設備上工作(一旦解決了這個問題:P)?或者我還需要包含openlayers.mobile.js

這是代碼不openlayers.light.js工作,但與openlayers.js工作(740KB):

var _element = "#map"; 
var map = new OpenLayers.Map (_element, { 
    controls: [ 
    new OpenLayers.Control.Navigation({ 
     dragPanOptions: { 
     enableKinetic: true 
     } 
    }), 
    new OpenLayers.Control.Zoom() 
    ], 
    projection: new OpenLayers.Projection("EPSG:900913"), 
    displayProjection: new OpenLayers.Projection("EPSG:4326") 
    }); 

    var lonLat = new OpenLayers.LonLat(_lon, _lat).transform (
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984 
new OpenLayers.Projection("EPSG:900913") // to Spherical Mercator Projection 
// map.getProjectionObject() doesn't work for unknown reason 
); 
    var markers = new OpenLayers.Layer.Markers("Markers"); 
    map.addLayer(markers); 

    var size = new OpenLayers.Size(21,25); 
    var offset = new OpenLayers.Pixel(-(size.w/2), -size.h); 
    var icon = new OpenLayers.Icon(_img_map_marker, size, offset); 
    markers.addMarker(new OpenLayers.Marker(lonLat, icon.clone())); 

    var mapnik = new OpenLayers.Layer.OSM("Test"); 
    map.addLayer(mapnik); 

    map.setCenter (lonLat,3); 

PS:我的OpenLayers地圖js的init()方法是好的,它的工作原理採用巨大openlayers.js (740KB),但與openlayers.light.js工作作爲我發現上面

HTML

<div id="map"></div> 

CSS

img{max-width:none;} 
#map{ 
width:300px; 
height:300px; 
} 

回答

3

如果你想使用openlayers的移動屬性作爲平移或縮放手,你必須使用openlayers.mobile.js。

您可以將openlayers.light.js用於移動設備,但不支持移動功能。

我想你的結構應該是:

myProject 
    /js 
     openlayers.light.js 
    /img 
    /theme 

,我已經在嘗試http://jsfiddle.net/aragon/ZecJj/和openlayers.light.js是沒有問題的。

我的代碼:

var map = new OpenLayers.Map({ 
    div: "map", 
    minResolution: "auto", 
    maxResolution: "auto", 
}); 

var osm = new OpenLayers.Layer.OSM(); 
var toMercator = OpenLayers.Projection.transforms['EPSG:4326']['EPSG:3857']; 
var center = toMercator({x:-0.05,y:51.5}); 
map.addLayers([osm]); 


map.setCenter(new OpenLayers.LonLat(center.x,center.y), 13); 

,並嘗試讀取Deploying (Shipping OpenLayers in your Application)

的OpenLayers帶有預配置的例子開箱:只需 下載的OpenLayers的版本,你會得到一個全套的易於使用 例子。但是,這些示例旨在用於開發 。當您準備部署應用程序時,您需要一個高度優化的OpenLayers發行版,以限制帶寬和加載時間。

您可以使用此鏈接更改src文件,並可以看到它仍然有效。

<script type="text/javascript" src="http://openlayers.org/dev/OpenLayers.light.debug.js"></script> 

<script type="text/javascript" src="https://view.softwareborsen.dk/Softwareborsen/Vis%20Stedet/trunk/lib/OpenLayers/2.12/OpenLayers.light.js?content-type=text%2Fplain"></script> 

我希望它可以幫助你......

+0

檢查我的問題我請我的代碼更新,還我不能改變的JS文件結構,它是一個標準我所有的內部/供應商不主要根 – sbaaaang 2013-02-11 12:59:51

+0

也嘗試與您的開放源代碼它仍然不工作 – sbaaaang 2013-02-11 13:05:20

+0

我已更新[我的小提琴](http://jsfiddle.net/aragon/ZecJj/)與您的代碼只有一個問題是'dragPanOptions'。我認爲OpenLayers.light.js對於特殊功能沒有那麼詳細。 – Aragon 2013-02-11 13:34:37