Skip to content

Commit

Permalink
Merge pull request #1744 from twpayne/remote-vector
Browse files Browse the repository at this point in the history
ol.source.RemoteVector
  • Loading branch information
twpayne committed Apr 3, 2014
2 parents e49b395 + c155b70 commit 0de380c
Show file tree
Hide file tree
Showing 30 changed files with 897 additions and 2,442 deletions.
2,223 changes: 0 additions & 2,223 deletions examples/data/osm/map.osm

This file was deleted.

51 changes: 51 additions & 0 deletions examples/tile-vector.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!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>Tile vector 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" style="background: white;"></div>
</div>
</div>

<div class="row-fluid">

<div class="span12">
<h4 id="title">Tile vector example</h4>
<p id="shortdesc">Example of <a href="http://openstreetmap.us/~migurski/vector-datasource/">vector tiles from openstreetmap.us</a>.</p>
<div id="docs">
<p>See the <a href="tile-vector.js" target="_blank">tile-vector.js source</a> to see how this is done.</p>
</div>
<div id="tags">tile-vector, openstreetmap</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=tile-vector" type="text/javascript"></script>

</body>
</html>
85 changes: 85 additions & 0 deletions examples/tile-vector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
goog.require('ol.Map');
goog.require('ol.View2D');
goog.require('ol.format.TopoJSON');
goog.require('ol.layer.Vector');
goog.require('ol.proj');
goog.require('ol.source.TileVector');
goog.require('ol.style.Fill');
goog.require('ol.style.Stroke');
goog.require('ol.style.Style');
goog.require('ol.tilegrid.XYZ');

var waterLayer = new ol.layer.Vector({
source: new ol.source.TileVector({
format: new ol.format.TopoJSON({
defaultProjection: 'EPSG:4326'
}),
projection: 'EPSG:3857',
tileGrid: new ol.tilegrid.XYZ({
maxZoom: 19
}),
url: 'http://{a-c}.tile.openstreetmap.us/' +
'vectiles-water-areas/{z}/{x}/{y}.topojson'
}),
style: new ol.style.Style({
fill: new ol.style.Fill({
color: '#9db9e8'
})
})
});

var roadStyleCache = {};
var roadLayer = new ol.layer.Vector({
source: new ol.source.TileVector({
format: new ol.format.TopoJSON({
defaultProjection: 'EPSG:4326'
}),
projection: 'EPSG:3857',
tileGrid: new ol.tilegrid.XYZ({
maxZoom: 19
}),
url: 'http://{a-c}.tile.openstreetmap.us/' +
'vectiles-highroad/{z}/{x}/{y}.topojson'
}),
style: function(feature, resolution) {
var kind = feature.get('kind');
var railway = feature.get('railway');
var sort_key = feature.get('sort_key');
var styleKey = kind + '/' + railway + '/' + sort_key;
var styleArray = roadStyleCache[styleKey];
if (!styleArray) {
var color, width;
if (railway) {
color = '#7de';
width = 1;
} else {
color = {
'major_road': '#776',
'minor_road': '#ccb',
'highway': '#f39'
}[kind];
width = kind == 'highway' ? 1.5 : 1;
}
styleArray = [new ol.style.Style({
stroke: new ol.style.Stroke({
color: color,
width: width
}),
zIndex: sort_key
})];
roadStyleCache[styleKey] = styleArray;
}
return styleArray;
}
});

var map = new ol.Map({
layers: [waterLayer, roadLayer],
renderer: 'canvas',
target: document.getElementById('map'),
view: new ol.View2D({
center: ol.proj.transform([-74.0064, 40.7142], 'EPSG:4326', 'EPSG:3857'),
maxZoom: 19,
zoom: 14
})
});
4 changes: 2 additions & 2 deletions examples/vector-osm.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@

<div class="span4">
<h4 id="title">OSM XML example</h4>
<p id="shortdesc">Example of using the OSM XML source.</p>
<p id="shortdesc">Example of using the OSM XML source. Vector data is loaded dynamically from a server using a tiling strategy.</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 id="tags">vector, osm, xml, loading, server</div>
</div>
<div class="span4 offset4">
<div id="info" class="alert alert-success">
Expand Down
25 changes: 21 additions & 4 deletions examples/vector-osm.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
goog.require('ol.Map');
goog.require('ol.View2D');
goog.require('ol.format.OSMXML');
goog.require('ol.layer.Tile');
goog.require('ol.layer.Vector');
goog.require('ol.loadingstrategy');
goog.require('ol.proj');
goog.require('ol.source.BingMaps');
goog.require('ol.source.OSMXML');
goog.require('ol.source.ServerVector');
goog.require('ol.style.Circle');
goog.require('ol.style.Fill');
goog.require('ol.style.Stroke');
goog.require('ol.style.Style');
goog.require('ol.tilegrid.XYZ');

var styles = {
'amenity': {
Expand Down Expand Up @@ -83,9 +87,21 @@ var styles = {
}
};

var vectorSource = new ol.source.OSMXML({
projection: 'EPSG:3857',
url: 'data/osm/map.osm'
var vectorSource = new ol.source.ServerVector({
format: new ol.format.OSMXML(),
loader: function(extent, resolution, projection) {
var transform = ol.proj.getTransform(projection, 'EPSG:4326');
var epsg4326Extent = transform(extent, []);
var url = 'http://overpass-api.de/api/xapi?map?bbox=' +
epsg4326Extent.join(',');
$.ajax(url).then(function(response) {
vectorSource.addFeatures(vectorSource.readFeatures(response));
});
},
strategy: ol.loadingstrategy.createTile(new ol.tilegrid.XYZ({
maxZoom: 19
})),
projection: 'EPSG:3857'
});

var vector = new ol.layer.Vector({
Expand Down Expand Up @@ -117,6 +133,7 @@ var map = new ol.Map({
target: document.getElementById('map'),
view: new ol.View2D({
center: [739218, 5906096],
maxZoom: 19,
zoom: 17
})
});
41 changes: 40 additions & 1 deletion src/objectliterals.jsdoc
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,15 @@
* @todo stability experimental
*/

/**
* @typedef {Object} olx.source.FormatVectorOptions
* @property {Array.<ol.Attribution>|undefined} attributions Attributions.
* @property {ol.Extent|undefined} extent Extent.
* @property {ol.format.Feature} format Format.
* @property {string|undefined} logo Logo.
* @property {ol.proj.ProjectionLike} projection Projection.
*/

/**
* @typedef {Object} olx.source.GeoJSONOptions
* @property {Array.<ol.Attribution>|undefined} attributions Attributions.
Expand Down Expand Up @@ -698,6 +707,25 @@
* @property {Array.<string>|undefined} urls URLs.
*/

/**
* @typedef {Object} olx.source.TileVectorOptions
* @property {Array.<ol.Attribution>|undefined} attributions Attributions.
* @property {ol.proj.ProjectionLike} defaultProjection Default projection.
* @property {ol.Extent|undefined} extent Extent.
* @property {string|undefined} logo Logo.
* @property {GeoJSONObject|undefined} object Object.
* @property {ol.proj.ProjectionLike} projection Destination projection. If
* provided, features will be transformed to this projection. If not
* provided, features will not be transformed.
* @property {ol.tilegrid.TileGrid} tileGrid Tile grid.
* @property {ol.TileUrlFunctionType|undefined} tileUrlFunction Optional
* function to get tile URL given a tile coordinate and the projection.
* Required if url or urls are not provided.
* @property {string|undefined} url URL template. Must include `{x}`, `{y}`,
* and `{z}` placeholders.
* @property {Array.<string>|undefined} urls An array of URL templates.
*/

/**
* @typedef {Object} olx.source.TopoJSONOptions
* @property {Array.<ol.Attribution>|undefined} attributions Attributions.
Expand Down Expand Up @@ -895,6 +923,17 @@
* @property {string} url Url.
*/

/**
* @typedef {Object} olx.source.ServerVectorOptions
* @property {Array.<ol.Attribution>|undefined} attributions Attributions.
* @property {ol.Extent|undefined} extent Extent.
* @property {ol.format.Feature} format Format.
* @property {function(this: ol.source.ServerVector, ol.Extent, number, ol.proj.Projection)} loader Loading function.
* @property {function(ol.Extent, number): Array.<ol.Extent>|undefined} strategy Loading strategy. Default is `ol.loadingstrategy.bbox`.
* @property {string|undefined} logo Logo.
* @property {ol.proj.ProjectionLike} projection Projection.
*/

/**
* @typedef {Object} olx.source.TileJSONOptions
* @property {null|string|undefined} crossOrigin crossOrigin setting for image
Expand Down Expand Up @@ -952,7 +991,7 @@
*/

/**
* @typedef {Object} olx.source.VectorFileOptions
* @typedef {Object} olx.source.StaticVectorOptions
* @property {ArrayBuffer|undefined} arrayBuffer Array buffer.
* @property {Array.<ol.Attribution>|undefined} attributions Attributions.
* @property {Document|undefined} doc Document.
Expand Down
11 changes: 11 additions & 0 deletions src/ol/extent.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,17 @@ ol.extent.isEmpty = function(extent) {
};


/**
* @param {ol.Extent} extent Extent.
* @return {boolean} Is infinite.
* @todo stability experimental
*/
ol.extent.isInfinite = function(extent) {
return extent[0] == -Infinity || extent[1] == -Infinity ||
extent[2] == Infinity || extent[3] == Infinity;
};


/**
* @param {ol.Extent} extent Extent.
* @param {ol.Coordinate} coordinate Coordinate.
Expand Down
1 change: 1 addition & 0 deletions src/ol/format/osmxmlformat.exports
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@exportSymbol ol.format.OSMXML
3 changes: 3 additions & 0 deletions src/ol/loadingstrategy.exports
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@exportSymbol ol.loadingstrategy.all
@exportSymbol ol.loadingstrategy.bbox
@exportSymbol ol.loadingstrategy.createTile
52 changes: 52 additions & 0 deletions src/ol/loadingstrategy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
goog.provide('ol.loadingstrategy');

goog.require('ol.TileCoord');


/**
* @param {ol.Extent} extent Extent.
* @param {number} resolution Resolution.
* @return {Array.<ol.Extent>} Extents.
*/
ol.loadingstrategy.all = function(extent, resolution) {
return [[-Infinity, -Infinity, Infinity, Infinity]];
};


/**
* @param {ol.Extent} extent Extent.
* @param {number} resolution Resolution.
* @return {Array.<ol.Extent>} Extents.
*/
ol.loadingstrategy.bbox = function(extent, resolution) {
return [extent];
};


/**
* @param {ol.tilegrid.TileGrid} tileGrid Tile grid.
* @return {function(ol.Extent, number): Array.<ol.Extent>} Loading strategy.
*/
ol.loadingstrategy.createTile = function(tileGrid) {
return (
/**
* @param {ol.Extent} extent Extent.
* @param {number} resolution Resolution.
* @return {Array.<ol.Extent>} Extents.
*/
function(extent, resolution) {
var z = tileGrid.getZForResolution(resolution);
var tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z);
/** @type {Array.<ol.Extent>} */
var extents = [];
var tileCoord = new ol.TileCoord(z, 0, 0);
for (tileCoord.x = tileRange.minX; tileCoord.x <= tileRange.maxX;
++tileCoord.x) {
for (tileCoord.y = tileRange.minY; tileCoord.y <= tileRange.maxY;
++tileCoord.y) {
extents.push(tileGrid.getTileCoordExtent(tileCoord));
}
}
return extents;
});
};
Loading

0 comments on commit 0de380c

Please sign in to comment.