Remove ol.source.TileVector
This commit is contained in:
@@ -42,6 +42,10 @@ but with additional css:
|
||||
}
|
||||
```
|
||||
|
||||
#### Removal of `ol.source.TileVector`
|
||||
|
||||
With the introduction of true vector tile support, `ol.source.TileVector` becomes obsolete. Change your code to use `ol.layer.VectorTile` and `ol.source.VectorTile` instead of `ol.layer.Vector` and `ol.source.TileVector`.
|
||||
|
||||
### v3.10.0
|
||||
|
||||
#### `ol.layer.Layer` changes
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
#map {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
---
|
||||
template: example.html
|
||||
title: Tile vector example
|
||||
shortdesc: Example of vector tiles from openstreetmap.us.
|
||||
docs: >
|
||||
Example of vector tiles from openstreetmap.us.
|
||||
tags: "custom, control"
|
||||
---
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
<div id="map" class="map" style="background: white;"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="alert">
|
||||
<strong>Warning</strong> Map is becoming unresponsive with too many layers.
|
||||
</div>
|
||||
<fieldset>
|
||||
<legend>Layers</legend>
|
||||
<label class="checkbox"><input type="checkbox" id="landuse"/> Landuse</label>
|
||||
<label class="checkbox"><input type="checkbox" id="buildings"/> Buildings</label>
|
||||
<label class="checkbox"><input type="checkbox" id="water" checked/> Water</label>
|
||||
<label class="checkbox"><input type="checkbox" id="roads" checked/> Roads</label>
|
||||
</fieldset>
|
||||
@@ -1,168 +0,0 @@
|
||||
goog.require('ol.Map');
|
||||
goog.require('ol.View');
|
||||
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');
|
||||
|
||||
var waterLayer = new ol.layer.Vector({
|
||||
source: new ol.source.TileVector({
|
||||
format: new ol.format.TopoJSON(),
|
||||
projection: 'EPSG:3857',
|
||||
tileGrid: ol.tilegrid.createXYZ({
|
||||
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(),
|
||||
projection: 'EPSG:3857',
|
||||
tileGrid: ol.tilegrid.createXYZ({
|
||||
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 buildingStyle = [
|
||||
new ol.style.Style({
|
||||
fill: new ol.style.Fill({
|
||||
color: '#666',
|
||||
opacity: 0.4
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#444',
|
||||
width: 1
|
||||
})
|
||||
})
|
||||
];
|
||||
var buildingLayer = new ol.layer.Vector({
|
||||
source: new ol.source.TileVector({
|
||||
format: new ol.format.TopoJSON({
|
||||
defaultProjection: 'EPSG:4326'
|
||||
}),
|
||||
projection: 'EPSG:3857',
|
||||
tileGrid: ol.tilegrid.createXYZ({
|
||||
maxZoom: 19
|
||||
}),
|
||||
url: 'http://{a-c}.tile.openstreetmap.us/' +
|
||||
'vectiles-buildings/{z}/{x}/{y}.topojson'
|
||||
}),
|
||||
visible: false,
|
||||
style: function(f, resolution) {
|
||||
return (resolution < 10) ? buildingStyle : [];
|
||||
}
|
||||
});
|
||||
|
||||
var landuseStyleCache = {};
|
||||
var landuseLayer = new ol.layer.Vector({
|
||||
source: new ol.source.TileVector({
|
||||
format: new ol.format.TopoJSON({
|
||||
defaultProjection: 'EPSG:4326'
|
||||
}),
|
||||
projection: 'EPSG:3857',
|
||||
tileGrid: ol.tilegrid.createXYZ({
|
||||
maxZoom: 19
|
||||
}),
|
||||
url: 'http://{a-c}.tile.openstreetmap.us/' +
|
||||
'vectiles-land-usages/{z}/{x}/{y}.topojson'
|
||||
}),
|
||||
visible: false,
|
||||
style: function(feature, resolution) {
|
||||
var kind = feature.get('kind');
|
||||
var styleKey = kind;
|
||||
var styleArray = landuseStyleCache[styleKey];
|
||||
if (!styleArray) {
|
||||
var color, width;
|
||||
color = {
|
||||
'parking': '#ddd',
|
||||
'industrial': '#aaa',
|
||||
'urban area': '#aaa',
|
||||
'park': '#76C759',
|
||||
'school': '#DA10E7',
|
||||
'garden': '#76C759',
|
||||
'pitch': '#D58F8D',
|
||||
'scrub': '#3E7D28',
|
||||
'residential': '#4C9ED9'
|
||||
}[kind];
|
||||
width = kind == 'highway' ? 1.5 : 1;
|
||||
styleArray = [new ol.style.Style({
|
||||
stroke: new ol.style.Stroke({
|
||||
color: color,
|
||||
width: width
|
||||
}),
|
||||
fill: new ol.style.Fill({
|
||||
color: color,
|
||||
opacity: 0.5
|
||||
})
|
||||
})];
|
||||
landuseStyleCache[styleKey] = styleArray;
|
||||
}
|
||||
return styleArray;
|
||||
}
|
||||
});
|
||||
|
||||
var map = new ol.Map({
|
||||
layers: [landuseLayer, buildingLayer, waterLayer, roadLayer],
|
||||
renderer: 'canvas',
|
||||
target: document.getElementById('map'),
|
||||
view: new ol.View({
|
||||
center: ol.proj.fromLonLat([-74.0064, 40.7142]),
|
||||
maxZoom: 19,
|
||||
zoom: 15
|
||||
})
|
||||
});
|
||||
|
||||
$('input[type=checkbox]').on('change', function() {
|
||||
var layer = {
|
||||
landuse: landuseLayer,
|
||||
buildings: buildingLayer,
|
||||
water: waterLayer,
|
||||
roads: roadLayer
|
||||
}[$(this).attr('id')];
|
||||
layer.setVisible(!layer.getVisible());
|
||||
});
|
||||
@@ -4263,98 +4263,6 @@ olx.source.VectorTileOptions.prototype.urls;
|
||||
olx.source.VectorTileOptions.prototype.wrapX;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{attributions: (Array.<ol.Attribution>|undefined),
|
||||
* format: (ol.format.Feature|undefined),
|
||||
* logo: (string|olx.LogoOptions|undefined),
|
||||
* tileGrid: ol.tilegrid.TileGrid,
|
||||
* tileUrlFunction: (ol.TileUrlFunctionType|undefined),
|
||||
* tileLoadFunction: (ol.TileVectorLoadFunctionType|undefined),
|
||||
* url: (string|undefined),
|
||||
* urls: (Array.<string>|undefined),
|
||||
* wrapX: (boolean|undefined)}}
|
||||
* @api
|
||||
*/
|
||||
olx.source.TileVectorOptions;
|
||||
|
||||
|
||||
/**
|
||||
* Attributions.
|
||||
* @type {Array.<ol.Attribution>|undefined}
|
||||
* @api
|
||||
*/
|
||||
olx.source.TileVectorOptions.prototype.attributions;
|
||||
|
||||
|
||||
/**
|
||||
* Format. Required unless tileLoadFunction is used.
|
||||
* @type {ol.format.Feature|undefined}
|
||||
* @api
|
||||
*/
|
||||
olx.source.TileVectorOptions.prototype.format;
|
||||
|
||||
|
||||
/**
|
||||
* Logo.
|
||||
* @type {string|olx.LogoOptions|undefined}
|
||||
* @api
|
||||
*/
|
||||
olx.source.TileVectorOptions.prototype.logo;
|
||||
|
||||
|
||||
/**
|
||||
* Tile grid.
|
||||
* @type {ol.tilegrid.TileGrid}
|
||||
* @api
|
||||
*/
|
||||
olx.source.TileVectorOptions.prototype.tileGrid;
|
||||
|
||||
|
||||
/**
|
||||
* Optional function to get tile URL given a tile coordinate and the projection.
|
||||
* Required if url or urls are not provided.
|
||||
* @type {ol.TileUrlFunctionType|undefined}
|
||||
* @api
|
||||
*/
|
||||
olx.source.TileVectorOptions.prototype.tileUrlFunction;
|
||||
|
||||
|
||||
/**
|
||||
* Optional function to override the default loading and format parsing behaviour.
|
||||
* If this option is used format is ignored and the provided function will be
|
||||
* responsible for data retrieval and transformation into features.
|
||||
* @type {ol.TileVectorLoadFunctionType|undefined}
|
||||
* @api
|
||||
*/
|
||||
olx.source.TileVectorOptions.prototype.tileLoadFunction;
|
||||
|
||||
|
||||
/**
|
||||
* URL template. Must include `{x}`, `{y}` or `{-y}`, and `{z}` placeholders.
|
||||
* @type {string|undefined}
|
||||
* @api
|
||||
*/
|
||||
olx.source.TileVectorOptions.prototype.url;
|
||||
|
||||
|
||||
/**
|
||||
* An array of URL templates.
|
||||
* @type {Array.<string>|undefined}
|
||||
* @api
|
||||
*/
|
||||
olx.source.TileVectorOptions.prototype.urls;
|
||||
|
||||
|
||||
/**
|
||||
* Wrap the world horizontally. Default is `true`. For vector editing across the
|
||||
* -180° and 180° meridians to work properly, this should be set to `false`. The
|
||||
* resulting geometry coordinates will then exceed the world bounds.
|
||||
* @type {boolean|undefined}
|
||||
* @api
|
||||
*/
|
||||
olx.source.TileVectorOptions.prototype.wrapX;
|
||||
|
||||
|
||||
/**
|
||||
* @typedef {{url: (string|undefined),
|
||||
* displayDpi: (number|undefined),
|
||||
|
||||
@@ -293,7 +293,7 @@ ol.renderer.canvas.VectorLayer.prototype.prepareFrame =
|
||||
if (vectorLayerRenderOrder) {
|
||||
/** @type {Array.<ol.Feature>} */
|
||||
var features = [];
|
||||
vectorSource.forEachFeatureInExtentAtResolution(extent, resolution,
|
||||
vectorSource.forEachFeatureInExtent(extent,
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
*/
|
||||
@@ -303,8 +303,7 @@ ol.renderer.canvas.VectorLayer.prototype.prepareFrame =
|
||||
goog.array.sort(features, vectorLayerRenderOrder);
|
||||
features.forEach(renderFeature, this);
|
||||
} else {
|
||||
vectorSource.forEachFeatureInExtentAtResolution(
|
||||
extent, resolution, renderFeature, this);
|
||||
vectorSource.forEachFeatureInExtent(extent, renderFeature, this);
|
||||
}
|
||||
replayGroup.finish();
|
||||
|
||||
|
||||
@@ -247,6 +247,8 @@ ol.renderer.canvas.VectorTileLayer.prototype.forEachFeatureAtCoordinate =
|
||||
|
||||
var replayables = this.renderedTiles_;
|
||||
var source = layer.getSource();
|
||||
goog.asserts.assertInstanceof(source, ol.source.VectorTile,
|
||||
'Source is an ol.source.VectorTile');
|
||||
var tileGrid = source.getTileGrid();
|
||||
var found, tileSpaceCoordinate;
|
||||
var i, ii, origin, replayGroup;
|
||||
@@ -254,8 +256,6 @@ ol.renderer.canvas.VectorTileLayer.prototype.forEachFeatureAtCoordinate =
|
||||
for (i = 0, ii = replayables.length; i < ii; ++i) {
|
||||
tile = replayables[i];
|
||||
tileCoord = tile.getTileCoord();
|
||||
goog.asserts.assertInstanceof(source, ol.source.VectorTile,
|
||||
'Source is an ol.source.VectorTile');
|
||||
tileExtent = source.getTileGrid().getTileCoordExtent(tileCoord,
|
||||
this.tmpExtent_);
|
||||
if (!ol.extent.containsCoordinate(tileExtent, coordinate)) {
|
||||
|
||||
@@ -301,7 +301,7 @@ ol.renderer.dom.VectorLayer.prototype.prepareFrame =
|
||||
if (vectorLayerRenderOrder) {
|
||||
/** @type {Array.<ol.Feature>} */
|
||||
var features = [];
|
||||
vectorSource.forEachFeatureInExtentAtResolution(extent, resolution,
|
||||
vectorSource.forEachFeatureInExtent(extent,
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
*/
|
||||
@@ -311,8 +311,7 @@ ol.renderer.dom.VectorLayer.prototype.prepareFrame =
|
||||
goog.array.sort(features, vectorLayerRenderOrder);
|
||||
features.forEach(renderFeature, this);
|
||||
} else {
|
||||
vectorSource.forEachFeatureInExtentAtResolution(
|
||||
extent, resolution, renderFeature, this);
|
||||
vectorSource.forEachFeatureInExtent(extent, renderFeature, this);
|
||||
}
|
||||
replayGroup.finish();
|
||||
|
||||
|
||||
@@ -269,7 +269,7 @@ ol.renderer.webgl.VectorLayer.prototype.prepareFrame =
|
||||
if (vectorLayerRenderOrder) {
|
||||
/** @type {Array.<ol.Feature>} */
|
||||
var features = [];
|
||||
vectorSource.forEachFeatureInExtentAtResolution(extent, resolution,
|
||||
vectorSource.forEachFeatureInExtent(extent,
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
*/
|
||||
@@ -279,8 +279,7 @@ ol.renderer.webgl.VectorLayer.prototype.prepareFrame =
|
||||
goog.array.sort(features, vectorLayerRenderOrder);
|
||||
features.forEach(renderFeature, this);
|
||||
} else {
|
||||
vectorSource.forEachFeatureInExtentAtResolution(
|
||||
extent, resolution, renderFeature, this);
|
||||
vectorSource.forEachFeatureInExtent(extent, renderFeature, this);
|
||||
}
|
||||
replayGroup.finish(context);
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ ol.source.ImageVector.prototype.canvasFunctionInternal_ =
|
||||
this.source_.loadFeatures(extent, resolution, projection);
|
||||
|
||||
var loading = false;
|
||||
this.source_.forEachFeatureInExtentAtResolution(extent, resolution,
|
||||
this.source_.forEachFeatureInExtent(extent,
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
*/
|
||||
|
||||
@@ -1,354 +0,0 @@
|
||||
goog.provide('ol.source.TileVector');
|
||||
|
||||
goog.require('goog.array');
|
||||
goog.require('goog.asserts');
|
||||
goog.require('goog.object');
|
||||
goog.require('ol.TileUrlFunction');
|
||||
goog.require('ol.featureloader');
|
||||
goog.require('ol.source.State');
|
||||
goog.require('ol.source.Vector');
|
||||
goog.require('ol.tilecoord');
|
||||
goog.require('ol.tilegrid.TileGrid');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A vector source in one of the supported formats, where the data is divided
|
||||
* into tiles in a fixed grid pattern.
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.source.Vector}
|
||||
* @param {olx.source.TileVectorOptions} options Options.
|
||||
* @api
|
||||
*/
|
||||
ol.source.TileVector = function(options) {
|
||||
|
||||
goog.base(this, {
|
||||
attributions: options.attributions,
|
||||
logo: options.logo,
|
||||
projection: undefined,
|
||||
state: ol.source.State.READY,
|
||||
wrapX: options.wrapX
|
||||
});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.format.Feature|undefined}
|
||||
*/
|
||||
this.format_ = options.format !== undefined ? options.format : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.tilegrid.TileGrid}
|
||||
*/
|
||||
this.tileGrid_ = options.tileGrid;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.TileUrlFunctionType}
|
||||
*/
|
||||
this.tileUrlFunction_ = ol.TileUrlFunction.nullTileUrlFunction;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {?ol.TileVectorLoadFunctionType}
|
||||
*/
|
||||
this.tileLoadFunction_ = options.tileLoadFunction !== undefined ?
|
||||
options.tileLoadFunction : null;
|
||||
|
||||
goog.asserts.assert(this.format_ || this.tileLoadFunction_,
|
||||
'Either format or tileLoadFunction are required');
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object.<string, Array.<ol.Feature>>}
|
||||
*/
|
||||
this.tiles_ = {};
|
||||
|
||||
if (options.tileUrlFunction !== undefined) {
|
||||
this.setTileUrlFunction(options.tileUrlFunction);
|
||||
} else if (options.urls !== undefined) {
|
||||
this.setUrls(options.urls);
|
||||
} else if (options.url !== undefined) {
|
||||
this.setUrl(options.url);
|
||||
}
|
||||
|
||||
};
|
||||
goog.inherits(ol.source.TileVector, ol.source.Vector);
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.TileVector.prototype.addFeature = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.TileVector.prototype.addFeatures = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.TileVector.prototype.clear = function() {
|
||||
goog.object.clear(this.tiles_);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.TileVector.prototype.forEachFeature = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* Iterate through all features whose geometries contain the provided
|
||||
* coordinate at the provided resolution, calling the callback with each
|
||||
* feature. If the callback returns a "truthy" value, iteration will stop and
|
||||
* the function will return the same value.
|
||||
*
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {function(this: T, ol.Feature): S} callback Called with each feature
|
||||
* whose goemetry contains the provided coordinate.
|
||||
* @param {T=} opt_this The object to use as `this` in the callback.
|
||||
* @return {S|undefined} The return value from the last call to the callback.
|
||||
* @template T,S
|
||||
*/
|
||||
ol.source.TileVector.prototype.forEachFeatureAtCoordinateAndResolution =
|
||||
function(coordinate, resolution, callback, opt_this) {
|
||||
|
||||
var tileGrid = this.tileGrid_;
|
||||
var tiles = this.tiles_;
|
||||
var tileCoord = tileGrid.getTileCoordForCoordAndResolution(coordinate,
|
||||
resolution);
|
||||
|
||||
var tileKey = this.getTileKeyZXY_(tileCoord[0], tileCoord[1], tileCoord[2]);
|
||||
var features = tiles[tileKey];
|
||||
if (features !== undefined) {
|
||||
var i, ii;
|
||||
for (i = 0, ii = features.length; i < ii; ++i) {
|
||||
var feature = features[i];
|
||||
var geometry = feature.getGeometry();
|
||||
goog.asserts.assert(geometry, 'feature geometry is defined and not null');
|
||||
if (geometry.containsCoordinate(coordinate)) {
|
||||
var result = callback.call(opt_this, feature);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.TileVector.prototype.forEachFeatureInExtent = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.TileVector.prototype.forEachFeatureInExtentAtResolution =
|
||||
function(extent, resolution, f, opt_this) {
|
||||
var tileGrid = this.tileGrid_;
|
||||
var tiles = this.tiles_;
|
||||
var z = tileGrid.getZForResolution(resolution);
|
||||
var tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z);
|
||||
var x, y;
|
||||
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
|
||||
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
|
||||
var tileKey = this.getTileKeyZXY_(z, x, y);
|
||||
var features = tiles[tileKey];
|
||||
if (features !== undefined) {
|
||||
var i, ii;
|
||||
for (i = 0, ii = features.length; i < ii; ++i) {
|
||||
var result = f.call(opt_this, features[i]);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.TileVector.prototype.getClosestFeatureToCoordinate =
|
||||
goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.TileVector.prototype.getExtent = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* Return the features of the TileVector source.
|
||||
* @inheritDoc
|
||||
* @api
|
||||
*/
|
||||
ol.source.TileVector.prototype.getFeatures = function() {
|
||||
var tiles = this.tiles_;
|
||||
var features = [];
|
||||
var tileKey;
|
||||
for (tileKey in tiles) {
|
||||
goog.array.extend(features, tiles[tileKey]);
|
||||
}
|
||||
return features;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Get all features whose geometry intersects the provided coordinate for the
|
||||
* provided resolution.
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @param {number} resolution Resolution.
|
||||
* @return {Array.<ol.Feature>} Features.
|
||||
* @api
|
||||
*/
|
||||
ol.source.TileVector.prototype.getFeaturesAtCoordinateAndResolution =
|
||||
function(coordinate, resolution) {
|
||||
var features = [];
|
||||
this.forEachFeatureAtCoordinateAndResolution(coordinate, resolution,
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
*/
|
||||
function(feature) {
|
||||
features.push(feature);
|
||||
});
|
||||
return features;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.TileVector.prototype.getFeaturesInExtent = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* Handles x-axis wrapping and returns a tile coordinate transformed from the
|
||||
* internal tile scheme to the tile grid's tile scheme. When the tile coordinate
|
||||
* is outside the resolution and extent range of the tile grid, `null` will be
|
||||
* returned.
|
||||
* @param {ol.TileCoord} tileCoord Tile coordinate.
|
||||
* @param {ol.proj.Projection} projection Projection.
|
||||
* @return {ol.TileCoord} Tile coordinate to be passed to the tileUrlFunction or
|
||||
* null if no tile URL should be created for the passed `tileCoord`.
|
||||
*/
|
||||
ol.source.TileVector.prototype.getTileCoordForTileUrlFunction =
|
||||
function(tileCoord, projection) {
|
||||
var tileGrid = this.tileGrid_;
|
||||
goog.asserts.assert(tileGrid, 'tile grid needed');
|
||||
if (this.getWrapX() && projection.isGlobal()) {
|
||||
tileCoord = ol.tilecoord.wrapX(tileCoord, tileGrid, projection);
|
||||
}
|
||||
return ol.tilecoord.withinExtentAndZ(tileCoord, tileGrid) ?
|
||||
tileCoord : null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {number} z Z.
|
||||
* @param {number} x X.
|
||||
* @param {number} y Y.
|
||||
* @private
|
||||
* @return {string} Tile key.
|
||||
*/
|
||||
ol.source.TileVector.prototype.getTileKeyZXY_ = function(z, x, y) {
|
||||
return z + '/' + x + '/' + y;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.TileVector.prototype.loadFeatures =
|
||||
function(extent, resolution, projection) {
|
||||
var tileGrid = this.tileGrid_;
|
||||
var tileUrlFunction = this.tileUrlFunction_;
|
||||
var tiles = this.tiles_;
|
||||
var z = tileGrid.getZForResolution(resolution);
|
||||
var tileRange = tileGrid.getTileRangeForExtentAndZ(extent, z);
|
||||
var tileCoord = [z, 0, 0];
|
||||
var x, y;
|
||||
/**
|
||||
* @param {string} tileKey Tile key.
|
||||
* @param {Array.<ol.Feature>} features Features.
|
||||
* @this {ol.source.TileVector}
|
||||
*/
|
||||
function success(tileKey, features) {
|
||||
tiles[tileKey] = features;
|
||||
this.changed();
|
||||
}
|
||||
for (x = tileRange.minX; x <= tileRange.maxX; ++x) {
|
||||
for (y = tileRange.minY; y <= tileRange.maxY; ++y) {
|
||||
var tileKey = this.getTileKeyZXY_(z, x, y);
|
||||
if (!(tileKey in tiles)) {
|
||||
tileCoord[1] = x;
|
||||
tileCoord[2] = y;
|
||||
var urlTileCoord = this.getTileCoordForTileUrlFunction(
|
||||
tileCoord, projection);
|
||||
var url = !urlTileCoord ? undefined :
|
||||
tileUrlFunction(urlTileCoord, 1, projection);
|
||||
if (url !== undefined) {
|
||||
tiles[tileKey] = [];
|
||||
var tileSuccess = goog.partial(success, tileKey);
|
||||
if (this.tileLoadFunction_) {
|
||||
this.tileLoadFunction_(url, goog.bind(tileSuccess, this));
|
||||
} else {
|
||||
var loader = ol.featureloader.loadFeaturesXhr(url,
|
||||
/** @type {ol.format.Feature} */ (this.format_), tileSuccess,
|
||||
goog.nullFunction);
|
||||
loader.call(this, extent, resolution, projection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
ol.source.TileVector.prototype.removeFeature = goog.abstractMethod;
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.TileUrlFunctionType} tileUrlFunction Tile URL function.
|
||||
*/
|
||||
ol.source.TileVector.prototype.setTileUrlFunction = function(tileUrlFunction) {
|
||||
this.tileUrlFunction_ = tileUrlFunction;
|
||||
this.changed();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {string} url URL.
|
||||
*/
|
||||
ol.source.TileVector.prototype.setUrl = function(url) {
|
||||
this.setTileUrlFunction(ol.TileUrlFunction.createFromTemplates(
|
||||
ol.TileUrlFunction.expandUrl(url), this.tileGrid_));
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {Array.<string>} urls URLs.
|
||||
*/
|
||||
ol.source.TileVector.prototype.setUrls = function(urls) {
|
||||
this.setTileUrlFunction(
|
||||
ol.TileUrlFunction.createFromTemplates(urls, this.tileGrid_));
|
||||
};
|
||||
@@ -493,20 +493,6 @@ ol.source.Vector.prototype.forEachFeatureInExtent =
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Extent} extent Extent.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {function(this: T, ol.Feature): S} f Callback.
|
||||
* @param {T=} opt_this The object to use as `this` in `f`.
|
||||
* @return {S|undefined}
|
||||
* @template T,S
|
||||
*/
|
||||
ol.source.Vector.prototype.forEachFeatureInExtentAtResolution =
|
||||
function(extent, resolution, f, opt_this) {
|
||||
return this.forEachFeatureInExtent(extent, f, opt_this);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Iterate through all features whose geometry intersects the provided extent,
|
||||
* calling the callback with each feature. If the callback returns a "truthy"
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
goog.provide('ol.test.source.TileVector');
|
||||
|
||||
|
||||
describe('ol.source.TileVector', function() {
|
||||
|
||||
describe('#loadFeatures()', function() {
|
||||
|
||||
it('calls tileUrlFunction with correct tile coords', function() {
|
||||
var tileCoords = [];
|
||||
var source = new ol.source.TileVector({
|
||||
format: new ol.format.TopoJSON(),
|
||||
tileGrid: ol.tilegrid.createXYZ({
|
||||
maxZoom: 19
|
||||
}),
|
||||
tileUrlFunction: function(tileCoord) {
|
||||
tileCoords.push(tileCoord.slice());
|
||||
return null;
|
||||
}
|
||||
});
|
||||
var projection = ol.proj.get('EPSG:3857');
|
||||
source.loadFeatures(
|
||||
[-8238854, 4969777, -8237854, 4970777], 4.8, projection);
|
||||
expect(tileCoords[0]).to.eql([15, 9647, -12321]);
|
||||
expect(tileCoords[1]).to.eql([15, 9647, -12320]);
|
||||
expect(tileCoords[2]).to.eql([15, 9648, -12321]);
|
||||
expect(tileCoords[3]).to.eql([15, 9648, -12320]);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getTileCoordForTileUrlFunction()', function() {
|
||||
|
||||
it('returns the expected tile coordinate - {wrapX: true}', function() {
|
||||
var tileSource = new ol.source.TileVector({
|
||||
format: new ol.format.TopoJSON(),
|
||||
tileGrid: ol.tilegrid.createXYZ({
|
||||
maxZoom: 19
|
||||
}),
|
||||
wrapX: true
|
||||
});
|
||||
var projection = ol.proj.get('EPSG:3857');
|
||||
|
||||
var tileCoord = tileSource.getTileCoordForTileUrlFunction(
|
||||
[6, -31, -23], projection);
|
||||
expect(tileCoord).to.eql([6, 33, -23]);
|
||||
|
||||
tileCoord = tileSource.getTileCoordForTileUrlFunction(
|
||||
[6, 33, -23], projection);
|
||||
expect(tileCoord).to.eql([6, 33, -23]);
|
||||
|
||||
tileCoord = tileSource.getTileCoordForTileUrlFunction(
|
||||
[6, 97, -23], projection);
|
||||
expect(tileCoord).to.eql([6, 33, -23]);
|
||||
});
|
||||
|
||||
it('returns the expected tile coordinate - {wrapX: false}', function() {
|
||||
var tileSource = new ol.source.TileVector({
|
||||
format: new ol.format.TopoJSON(),
|
||||
tileGrid: ol.tilegrid.createXYZ({
|
||||
maxZoom: 19
|
||||
}),
|
||||
wrapX: false
|
||||
});
|
||||
var projection = ol.proj.get('EPSG:3857');
|
||||
|
||||
var tileCoord = tileSource.getTileCoordForTileUrlFunction(
|
||||
[6, -31, -23], projection);
|
||||
expect(tileCoord).to.eql(null);
|
||||
|
||||
tileCoord = tileSource.getTileCoordForTileUrlFunction(
|
||||
[6, 33, -23], projection);
|
||||
expect(tileCoord).to.eql([6, 33, -23]);
|
||||
|
||||
tileCoord = tileSource.getTileCoordForTileUrlFunction(
|
||||
[6, 97, -23], projection);
|
||||
expect(tileCoord).to.eql(null);
|
||||
});
|
||||
|
||||
it('works with wrapX and custom projection without extent', function() {
|
||||
var tileSource = new ol.source.TileVector({
|
||||
format: new ol.format.TopoJSON(),
|
||||
tileGrid: ol.tilegrid.createXYZ({
|
||||
maxZoom: 19
|
||||
}),
|
||||
wrapX: true
|
||||
});
|
||||
var projection = new ol.proj.Projection({
|
||||
code: 'foo',
|
||||
global: true,
|
||||
units: 'm'
|
||||
});
|
||||
|
||||
var tileCoord = tileSource.getTileCoordForTileUrlFunction(
|
||||
[6, -31, -23], projection);
|
||||
expect(tileCoord).to.eql([6, 33, -23]);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
goog.require('ol.format.TopoJSON');
|
||||
goog.require('ol.proj');
|
||||
goog.require('ol.proj.Projection');
|
||||
goog.require('ol.source.TileVector');
|
||||
@@ -62,6 +62,17 @@ describe('ol.source.Vector', function() {
|
||||
expect(listener).to.be.called();
|
||||
});
|
||||
|
||||
it('adds same id features only once', function() {
|
||||
var source = new ol.source.Vector();
|
||||
var feature1 = new ol.Feature();
|
||||
feature1.setId('1');
|
||||
var feature2 = new ol.Feature();
|
||||
feature2.setId('1');
|
||||
source.addFeature(feature1);
|
||||
source.addFeature(feature2);
|
||||
expect(source.getFeatures().length).to.be(1);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user