Add ol.format.OSMXML and ol.source.OSMXML

This commit is contained in:
Frederic Junod
2014-01-20 17:16:03 +01:00
parent 35349764d9
commit 6ab3f6e175
7 changed files with 2659 additions and 0 deletions

2223
examples/data/osm/map.osm Normal file

File diff suppressed because it is too large Load Diff

56
examples/vector-osm.html Normal file
View File

@@ -0,0 +1,56 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<link rel="stylesheet" href="../css/ol.css" type="text/css">
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="../resources/layout.css" type="text/css">
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
<title>OSM XML example</title>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="./"><img src="../resources/logo.png"> OpenLayers 3 Examples</a>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div id="map" class="map"></div>
</div>
</div>
<div class="row-fluid">
<div class="span4">
<h4 id="title">OSM XML example</h4>
<p id="shortdesc">Example of using the OSM XML source.</p>
<div id="docs">
<p>See the <a href="vector-osm.js" target="_blank">vector-osm.js source</a> to see how this is done.</p>
</div>
<div id="tags">vector, osm, xml</div>
</div>
<div class="span4 offset4">
<div id="info" class="alert alert-success">
&nbsp;
</div>
</div>
</div>
</div>
<script src="jquery.min.js" type="text/javascript"></script>
<script src="../resources/example-behaviour.js" type="text/javascript"></script>
<script src="loader.js?id=vector-osm" type="text/javascript"></script>
</body>
</html>

123
examples/vector-osm.js Normal file
View File

@@ -0,0 +1,123 @@
goog.require('ol.Map');
goog.require('ol.View2D');
goog.require('ol.layer.Tile');
goog.require('ol.layer.Vector');
goog.require('ol.source.BingMaps');
goog.require('ol.source.OSMXML');
goog.require('ol.style.Circle');
goog.require('ol.style.Fill');
goog.require('ol.style.Stroke');
goog.require('ol.style.Style');
var styles = {
'amenity': {
'parking': [
new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(170, 170, 170, 1.0)',
width: 1
}),
fill: new ol.style.Fill({
color: 'rgba(170, 170, 170, 0.3)'
})
})
]
},
'building': {
'.*': [
new ol.style.Style({
zIndex: 100,
stroke: new ol.style.Stroke({
color: 'rgba(246, 99, 79, 1.0)',
width: 1
}),
fill: new ol.style.Fill({
color: 'rgba(246, 99, 79, 0.3)'
})
})
]
},
'highway': {
'service': [
new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(255, 255, 255, 1.0)',
width: 2
})
})
],
'.*': [
new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(255, 255, 255, 1.0)',
width: 3
})
})
]
},
'landuse': {
'forest|grass|allotments': [
new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(140, 208, 95, 1.0)',
width: 1
}),
fill: new ol.style.Fill({
color: 'rgba(140, 208, 95, 0.3)'
})
})
]
},
'natural': {
'tree': [
new ol.style.Style({
image: new ol.style.Circle({
radius: 2,
fill: new ol.style.Fill({
color: 'rgba(140, 208, 95, 1.0)'
}),
stroke: null
})
})
]
}
};
var vectorSource = new ol.source.OSMXML({
projection: 'EPSG:3857',
url: 'data/osm/map.osm'
});
var vector = new ol.layer.Vector({
source: vectorSource,
style: function(feature, resolution) {
for (var key in styles) {
var value = feature.get(key);
if (value !== undefined) {
for (var regexp in styles[key]) {
if (new RegExp(regexp).test(value)) {
return styles[key][regexp];
}
}
}
}
return null;
}
});
var raster = new ol.layer.Tile({
source: new ol.source.BingMaps({
imagerySet: 'Aerial',
key: 'Ak-dzM4wZjSqTlzveKz5u0d4IQ4bRzVI309GxmkgSVr1ewS6iPSrOvOKhA-CJlm3'
})
});
var map = new ol.Map({
layers: [raster, vector],
renderer: 'canvas',
target: document.getElementById('map'),
view: new ol.View2D({
center: [739218, 5906096],
zoom: 17
})
});