<!DOCTYPE html>
<html>
<head>
<title> OSM </title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://openlayers.org/en/v3.10.1/css/ol.css" type="text/css">
<script src="http://openlayers.org/en/v3.10.1/build/ol.js"></script>
<link rel="stylesheet" href="newcss.css" type="text/css" media="screen" />
</head>
<body>
<h3 ALIGN="CENTER"> Project OSM</h3>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div id="map" class="map"></div>
</div>
</div>
</div>
<script>
var map = new ol.Map({
controls: ol.control.defaults({}).extend([
new ol.control.ZoomToExtent({})
]),
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
new ol.layer.Image({
source: new ol.source.ImageStatic({
url: '...i will put after ...',
imageSize: [1000, 1000],
imageExtent: [0, 0, 1000, 1000]
})
})
],
target: 'map',
view: new ol.View({
center: [261487.4908, 6250012.1599],
zoom: 19
})
});
</script>
</body>
</html>
我想在地图上放置图片,我尝试使用ol.layer.Image
和ol.source.ImageStatic
,我放url
,imagesize
和extent
,但我看不到任何内容,也许我应该输入代码projection
,但对于view
我选择espg 3857
。
祝你好运
答案 0 :(得分:0)
你要问自己的第一件事是:
在官方例子中是否有任何我需要的例子(直到现在 - 134)?
答案可能是:
是
好的,有点OFF主题。所以你有(http://openlayers.org/en/v3.11.0/examples/static-image.html):
// create a projection based on your image
var extent = [0, 0, 1024, 968]; // <--- image extent in pixels
var projection = new ol.proj.Projection({
code: 'xkcd-image',
units: 'pixels',
extent: extent
});
// layer creation
new ol.layer.Image({
source: new ol.source.ImageStatic({
url: 'http://...',
projection: projection,
imageExtent: extent
})
})
// and finally ol.View
new ol.View({
projection: projection,
center: ol.extent.getCenter(extent),
zoom: 2,
maxZoom: 8
})