[英]OpenLayers: two GeoJSON Layers, one transparent on both
I have a GPX Track (Startpoint == Endpoint) converted to GeoJSON. 我有一个GPX轨迹(起点==终点)转换为GeoJSON。
I now want to display this track on a map where only by the trac enclosed map shown. 现在,我想在仅由追踪包围的地图显示的地图上显示此轨道。 The rest should be white. 其余应为白色。
So far I have the following: 到目前为止,我有以下内容:
<script type="text/javascript">
function init() {
map = new OpenLayers.Map("basicMap");
var mapnik = new OpenLayers.Layer.OSM();
var fromProjection = new OpenLayers.Projection("EPSG:4326");
var toProjection = new OpenLayers.Projection("EPSG:900913");
var position = new OpenLayers.LonLat(13.41,52.52).transform( fromProjection, toProjection);
var zoom = 7;
map.addLayer(mapnik);
map.setCenter(position, zoom );
geojson_layer = new OpenLayers.Layer.Vector("GeoJSON", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "tracks.json",
format: new OpenLayers.Format.GeoJSON()
})
});
map.addLayer(geojson_layer);
}
</script>
tracks.json is the GeoJSON file with the trac. track.json是带有trac的GeoJSON文件。
Basicly now I want a rectangle around the trac. 基本上现在我想要在笔迹周围有一个矩形。 The space between trac and rectangle should be filled white. 笔迹和矩形之间的空间应填充为白色。
Thank you for your help! 谢谢您的帮助!
Actually it was as simple as declaring a Polygon with two coordinate objects. 实际上,这就像声明带有两个坐标对象的多边形一样简单。 One for the rectangle and one for the track: 一个用于矩形,另一个用于轨道:
var border = {
"type": "Feature",
"properties": { },
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
Coordinates of Rectangle
]
],
[
[
Coordinates of the track
]
]
]
}
}
I includes this in my javascript: 我将其包含在我的javascript中:
<script type="text/javascript" src="border.js"></script>
.
.
var geojson_format = new OpenLayers.Format.GeoJSON({
'internalProjection': toProjection,
'externalProjection': fromProjection
});
map.addLayer(vectorLayer);
vectorLayer.addFeatures(geojson_format.read(border));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.