openlayers修改样式_在OpenLayers中更改切片的外观(使用OSM贴图)

本文介绍如何使用OpenLayers更改OSM地图的样式,包括背景颜色、建筑物颜色、街道轮廓和隐藏特定元素。示例代码展示了创建带有标记和弹出窗口的地图,并探讨了如何直接在地图样式中实现视觉调整。
摘要由CSDN通过智能技术生成

我想使用OSM地图,我决定使用OpenLayers。

我能够得到如下结果:

但我希望我的地图看起来更像这个:

我的意思是风格,颜色和细节,不是控件(我知道如何添加自己的控件,标记等)。

我想做出如下变化:让背景变绿,建筑物在另一个灰色阴影中,1px黑色轮廓,从主要街道上移除黄色,隐藏火车轨道和停车位等。

如何实现?所有这些变化都必须通过样式化OSM地图来实现,而不能在"后处理" (例如,在获取地图后,可以将整个地图更改为灰度)。

我的示例代码(基于OpenLayers示例之一):

var map;

function init() {

// The overlay layer for our marker, with a simple diamond as symbol

var overlay = new OpenLayers.Layer.Vector('Overlay', {

styleMap: new OpenLayers.StyleMap({

externalGraphic: 'img/marker.png',

graphicWidth: 20, graphicHeight: 24, graphicYOffset: -24,

title: '${tooltip}'

})

});

// The location of our marker and popup. We usually think in geographic

// coordinates ('EPSG:4326'), but the map is projected ('EPSG:3857').

var myLocation = new OpenLayers.Geometry.Point(19.41166, 51.75047)

.transform('EPSG:4326', 'EPSG:3857');

// We add the marker with a tooltip text to the overlay

overlay.addFeatures([

new OpenLayers.Feature.Vector(myLocation, {tooltip: 'OpenLayers'})

]);

// A popup with some information about our location

var popup = new OpenLayers.Popup.FramedCloud("Popup",

myLocation.getBounds().getCenterLonLat(), null,

'We ' +

'could be here.
Or elsewhere.', null,

true //

);

//alert(myLocation.getBounds().getCenterLonLat());

var layer = new OpenLayers.Layer.OSM();

// Finally we create the map

map = new OpenLayers.Map({

div: "map", projection: "EPSG:3857",

layers: [layer, overlay],

center: myLocation.getBounds().getCenterLonLat(), zoom: 18

});

// and add the popup to it.

map.addPopup(popup);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值