Skip to content

Commit

Permalink
Merge pull request #656 from openlayers/internalize_additionnal_ol_fu…
Browse files Browse the repository at this point in the history
…nctions

Internalize additionnal ol functions
  • Loading branch information
gberaudo authored Sep 25, 2018
2 parents 053de71 + 2cfb926 commit 91ee49d
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 57 deletions.
6 changes: 3 additions & 3 deletions examples/customProj.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import olSourceOSM from 'ol/source/OSM.js';
import olLayerImage from 'ol/layer/Image.js';
import olLayerTile from 'ol/layer/Tile.js';
import olMap from 'ol/Map.js';
import * as olProj from 'ol/proj.js';
import {get as getProjection} from 'ol/proj.js';
import {register as olProj4Register} from 'ol/proj/proj4.js';
import proj4 from 'proj4';

Expand All @@ -30,7 +30,7 @@ const epsg21781extent = [420000, 30000, 900000, 350000];
proj4.defs('EPSG:21781', epsg21781def);

olProj4Register(proj4);
olProj.get('EPSG:21781').setExtent(epsg21781extent);
getProjection('EPSG:21781').setExtent(epsg21781extent);

const customProjSource = new olSourceImageWMS({
attributions: '© <a href="http://www.geo.admin.ch/internet/geoportal/' +
Expand All @@ -41,7 +41,7 @@ const customProjSource = new olSourceImageWMS({
url: 'https://wms.geo.admin.ch/'
});

customProjSource.set('olcs.projection', olProj.get('EPSG:3857'));
customProjSource.set('olcs.projection', getProjection('EPSG:3857'));

Cesium.Ion.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI0MzAyNzUyYi0zY2QxLTQxZDItODRkOS1hNTA3MDU3ZTBiMDUiLCJpZCI6MjU0MSwiaWF0IjoxNTMzNjI1MTYwfQ.oHn1SUWJa12esu7XUUtEoc1BbEbuZpRocLetw6M6_AA';
const ol2d = new olMap({
Expand Down
6 changes: 3 additions & 3 deletions examples/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
const exports = {};
import OLCesium from 'olcs/OLCesium.js';
import * as olProj from 'ol/proj.js';
import {transform} from 'ol/proj.js';
import olView from 'ol/View.js';
import olSourceOSM from 'ol/source/OSM.js';
import olLayerTile from 'ol/layer/Tile.js';
Expand All @@ -18,7 +18,7 @@ const ol2d = new olMap({
],
target: 'map',
view: new olView({
center: olProj.transform([25, 20], 'EPSG:4326', 'EPSG:3857'),
center: transform([25, 20], 'EPSG:4326', 'EPSG:3857'),
zoom: 3
})
});
Expand All @@ -43,6 +43,6 @@ setInterval(printInfo, 100);

document.getElementById('enable').addEventListener('click', () => ol3d.setEnabled(!ol3d.getEnabled()));
window['camera'] = camera;
window['olProjTransform'] = olProj.transform;
window['olProjTransform'] = transform;

export default exports;
4 changes: 2 additions & 2 deletions examples/image-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
const exports = {};
import OLCesium from 'olcs/OLCesium.js';
import * as olProj from 'ol/proj.js';
import {transform} from 'ol/proj.js';
import olView from 'ol/View.js';
import {defaults as olControlDefaults} from 'ol/control.js';
import olSourceOSM from 'ol/source/OSM.js';
Expand Down Expand Up @@ -37,7 +37,7 @@ const ol2d = new olMap({
}),
target: 'map',
view: new olView({
center: olProj.transform(getCenter(imageExtent), 'EPSG:4326', 'EPSG:3857'),
center: transform(getCenter(imageExtent), 'EPSG:4326', 'EPSG:3857'),
zoom: 4,
projection: 'EPSG:3857'
})
Expand Down
4 changes: 2 additions & 2 deletions examples/kml.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
const exports = {};
import OLCesium from 'olcs/OLCesium.js';
import * as olProj from 'ol/proj.js';
import {transform} from 'ol/proj.js';
import olView from 'ol/View.js';
import {defaults as olControlDefaults} from 'ol/control.js';
import olSourceOSM from 'ol/source/OSM.js';
Expand All @@ -24,7 +24,7 @@ const ol2d = new olMap({
}),
target: 'map',
view: new olView({
center: olProj.transform([25, 20], 'EPSG:4326', 'EPSG:3857'),
center: transform([25, 20], 'EPSG:4326', 'EPSG:3857'),
zoom: 3
})
});
Expand Down
4 changes: 2 additions & 2 deletions examples/layer-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import olMap from 'ol/Map.js';
import olView from 'ol/View.js';
import olLayerGroup from 'ol/layer/Group.js';
import olLayerTile from 'ol/layer/Tile.js';
import * as olProj from 'ol/proj.js';
import {fromLonLat} from 'ol/proj.js';
import olSourceOSM from 'ol/source/OSM.js';
import olSourceTileJSON from 'ol/source/TileJSON.js';
import OLCesium from 'olcs/OLCesium.js';
Expand Down Expand Up @@ -40,7 +40,7 @@ const ol2d = new olMap({
layers: [layer0, layer1],
target: 'map2d',
view: new olView({
center: olProj.fromLonLat([37.40570, 8.81566]),
center: fromLonLat([37.40570, 8.81566]),
zoom: 4
})
});
Expand Down
4 changes: 2 additions & 2 deletions examples/lazy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @module examples.lazy
*/
const exports = {};
import * as olProj from 'ol/proj.js';
import {transform} from 'ol/proj.js';
import olView from 'ol/View.js';
import {defaults as olControlDefaults} from 'ol/control.js';
import olSourceOSM from 'ol/source/OSM.js';
Expand All @@ -24,7 +24,7 @@ const ol2d = new olMap({
}),
target: 'map',
view: new olView({
center: olProj.transform([25, 20], 'EPSG:4326', 'EPSG:3857'),
center: transform([25, 20], 'EPSG:4326', 'EPSG:3857'),
zoom: 3
})
});
Expand Down
4 changes: 2 additions & 2 deletions examples/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
const exports = {};
import OLCesium from 'olcs/OLCesium.js';
import * as olProj from 'ol/proj.js';
import {transform} from 'ol/proj.js';
import olView from 'ol/View.js';
import {defaults as olControlDefaults} from 'ol/control.js';
import olSourceOSM from 'ol/source/OSM.js';
Expand All @@ -24,7 +24,7 @@ const ol2d = new olMap({
}),
target: 'map',
view: new olView({
center: olProj.transform([25, 20], 'EPSG:4326', 'EPSG:3857'),
center: transform([25, 20], 'EPSG:4326', 'EPSG:3857'),
zoom: 3
})
});
Expand Down
14 changes: 7 additions & 7 deletions examples/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import OLCesium from 'olcs/OLCesium.js';
import olMap from 'ol/Map.js';
import olSourceOSM from 'ol/source/OSM.js';
import olLayerTile from 'ol/layer/Tile.js';
import * as olProj from 'ol/proj.js';
import {transform, get as getProjection} from 'ol/proj.js';
import olView from 'ol/View.js';
import {defaults as olControlDefaults} from 'ol/control.js';
import olOverlay from 'ol/Overlay.js';
import * as olCoordinate from 'ol/coordinate.js';
import {toStringHDMS} from 'ol/coordinate.js';
/* global $ */

const source = new olSourceOSM();
Expand All @@ -29,7 +29,7 @@ const ol2d = new olMap({
}),
target: 'map',
view: new olView({
center: olProj.transform([-112.2, 36.06], 'EPSG:4326', 'EPSG:3857'),
center: transform([-112.2, 36.06], 'EPSG:4326', 'EPSG:3857'),
zoom: 11
})
});
Expand Down Expand Up @@ -80,8 +80,8 @@ class OverlayHandler {

onClickHandlerOL(event) {
const coordinates = event.coordinate;
const hdms = olCoordinate.toStringHDMS(
olProj.transform(coordinates, 'EPSG:3857', 'EPSG:4326')
const hdms = toStringHDMS(
transform(coordinates, 'EPSG:3857', 'EPSG:4326')
);
const overlay = this.getOverlay();
overlay.setPosition(coordinates);
Expand All @@ -106,8 +106,8 @@ class OverlayHandler {
coords = coords.concat([height]);
}

const transformedCoords = olProj.transform(coords, olProj.get('EPSG:4326'), 'EPSG:3857');
const hdms = olCoordinate.toStringHDMS(coords);
const transformedCoords = transform(coords, getProjection('EPSG:4326'), 'EPSG:3857');
const hdms = toStringHDMS(coords);
const overlay = this.getOverlay();
overlay.setPosition(transformedCoords);
this.setOverlayContent(overlay, hdms);
Expand Down
4 changes: 2 additions & 2 deletions examples/rastersync.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import olMap from 'ol/Map.js';
import olSourceTileJSON from 'ol/source/TileJSON.js';
import olSourceOSM from 'ol/source/OSM.js';
import olLayerTile from 'ol/layer/Tile.js';
import * as olProj from 'ol/proj.js';
import {transform} from 'ol/proj.js';
import olView from 'ol/View.js';


const view = new olView({
center: olProj.transform([-112.2, 36.06], 'EPSG:4326', 'EPSG:3857'),
center: transform([-112.2, 36.06], 'EPSG:4326', 'EPSG:3857'),
zoom: 11
});

Expand Down
4 changes: 2 additions & 2 deletions examples/sidebyside.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import OLCesium from 'olcs/OLCesium.js';
import olSourceOSM from 'ol/source/OSM.js';
import olLayerTile from 'ol/layer/Tile.js';
import olMap from 'ol/Map.js';
import * as olProj from 'ol/proj.js';
import {transform} from 'ol/proj.js';
import olView from 'ol/View.js';


const view = new olView({
center: olProj.transform([25, 20], 'EPSG:4326', 'EPSG:3857'),
center: transform([25, 20], 'EPSG:4326', 'EPSG:3857'),
zoom: 3,
rotation: Math.PI / 6
});
Expand Down
8 changes: 4 additions & 4 deletions examples/vectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import olStyleStyle from 'ol/style/Style.js';
import olGeomPoint from 'ol/geom/Point.js';
import olFeature from 'ol/Feature.js';
import olStyleStroke from 'ol/style/Stroke.js';
import * as olInteraction from 'ol/interaction.js';
import {defaults as interactionDefaults} from 'ol/interaction.js';
import olStyleFill from 'ol/style/Fill.js';
import olMap from 'ol/Map.js';
import olGeomCircle from 'ol/geom/Circle.js';
Expand All @@ -28,7 +28,7 @@ import olGeomPolygon from 'ol/geom/Polygon.js';
import olInteractionDragAndDrop from 'ol/interaction/DragAndDrop.js';
import olGeomMultiPolygon from 'ol/geom/MultiPolygon.js';
import olLayerVector from 'ol/layer/Vector.js';
import * as olProj from 'ol/proj.js';
import {transform} from 'ol/proj.js';
import olcsCore from 'olcs/core.js';


Expand Down Expand Up @@ -119,7 +119,7 @@ modelFeatures.forEach((feature) => {
});
const olcsModelFunction = () => {
const coordinates = feature.getGeometry().getCoordinates();
const center = olProj.transform(coordinates, 'EPSG:3857', 'EPSG:4326');
const center = transform(coordinates, 'EPSG:3857', 'EPSG:4326');
const rotation = /** @type {number} */ (feature.get('rotation'));
return {
cesiumOptions: {
Expand Down Expand Up @@ -297,7 +297,7 @@ const dragAndDropInteraction = new olInteractionDragAndDrop({
});

const map = new olMap({
interactions: olInteraction.defaults().extend([dragAndDropInteraction]),
interactions: interactionDefaults().extend([dragAndDropInteraction]),
layers: [
new olLayerTile({
source: new olSourceOSM()
Expand Down
1 change: 1 addition & 0 deletions src/index.library.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ olcs.core = core.default;
olcs.core.OLImageryProvider = OLImageryProvider;
olcs.core.VectorLayerCounterpart = VectorLayerCounterpart;

olcs.contrib = {};
olcs.contrib.LazyLoader = LazyLoader;
olcs.contrib.Manager = Manager;
6 changes: 3 additions & 3 deletions src/olcs/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import {unByKey as olObservableUnByKey} from 'ol/Observable.js';
import {toRadians, toDegrees} from './math.js';
import * as olProj from 'ol/proj.js';
import {getTransform} from 'ol/proj.js';
import olcsCore from './core.js';

class Camera {
Expand Down Expand Up @@ -118,8 +118,8 @@ class Camera {

this.view_ = view;
if (view) {
const toLonLat = olProj.getTransform(view.getProjection(), 'EPSG:4326');
const fromLonLat = olProj.getTransform('EPSG:4326', view.getProjection());
const toLonLat = getTransform(view.getProjection(), 'EPSG:4326');
const fromLonLat = getTransform('EPSG:4326', view.getProjection());
console.assert(toLonLat && fromLonLat);

this.toLonLat_ = toLonLat;
Expand Down
9 changes: 4 additions & 5 deletions src/olcs/FeatureConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import olStyleIcon from 'ol/style/Icon.js';
import olSourceVector from 'ol/source/Vector.js';
import olSourceCluster from 'ol/source/Cluster.js';
import {circular as olCreateCircularPolygon} from 'ol/geom/Polygon.js';
import * as olEvents from 'ol/events.js';
import * as olExtent from 'ol/extent.js';
import {boundingExtent, getCenter} from 'ol/extent.js';
import olGeomSimpleGeometry from 'ol/geom/SimpleGeometry.js';
import olcsCore from './core.js';
import olcsCoreVectorLayerCounterpart from './core/VectorLayerCounterpart.js';
Expand Down Expand Up @@ -480,7 +479,7 @@ class FeatureConverter {
// Create a rectangle according to the longitude and latitude curves
const coordinates = olGeometry.getCoordinates()[0];
// Extract the West, South, East, North coordinates
const extent = olExtent.boundingExtent(coordinates);
const extent = boundingExtent(coordinates);
const rectangle = Cesium.Rectangle.fromDegrees(extent[0], extent[1],
extent[2], extent[3]);

Expand Down Expand Up @@ -723,7 +722,7 @@ class FeatureConverter {
}
};

olEvents.listenOnce(image, 'load', listener);
image.once('load', listener);
} else {
reallyCreateBillboard();
}
Expand Down Expand Up @@ -870,7 +869,7 @@ class FeatureConverter {
const labels = new Cesium.LabelCollection({scene: this.scene});
// TODO: export and use the text draw position from OpenLayers .
// See src/ol/render/vector.js
const extentCenter = olExtent.getCenter(geometry.getExtent());
const extentCenter = getCenter(geometry.getExtent());
if (geometry instanceof olGeomSimpleGeometry) {
const first = geometry.getFirstCoordinate();
extentCenter[2] = first.length == 3 ? first[2] : 0.0;
Expand Down
4 changes: 2 additions & 2 deletions src/olcs/OLCesium.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @module olcs.OLCesium
*/
import olGeomPoint from 'ol/geom/Point.js';
import * as olProj from 'ol/proj.js';
import {getTransform} from 'ol/proj.js';
import olcsUtil from './util.js';
import olcsCore from './core.js';
import olcsAutoRenderLoop from './AutoRenderLoop.js';
Expand Down Expand Up @@ -43,7 +43,7 @@ class OLCesium {
* No change of the view projection.
* @private
*/
this.to4326Transform_ = olProj.getTransform(this.map_.getView().getProjection(), 'EPSG:4326');
this.to4326Transform_ = getTransform(this.map_.getView().getProjection(), 'EPSG:4326');

/**
* @type {number}
Expand Down
10 changes: 5 additions & 5 deletions src/olcs/SynchronizedOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* @module olcs.SynchronizedOverlay
*/
import olOverlay from 'ol/Overlay.js';
import * as olProj from 'ol/proj.js';
import * as olDom from 'ol/dom.js';
import {transform} from 'ol/proj.js';
import {removeNode, removeChildren} from './util.js';
import {unByKey as olObservableUnByKey} from 'ol/Observable.js';

class SynchronizedOverlay extends olOverlay {
Expand Down Expand Up @@ -136,7 +136,7 @@ class SynchronizedOverlay extends olOverlay {
handleMapChanged() {
if (this.scenePostRenderListenerRemover_) {
this.scenePostRenderListenerRemover_();
olDom.removeNode(this.element);
removeNode(this.element);
}
this.scenePostRenderListenerRemover_ = null;
const scene = this.getScene();
Expand All @@ -161,7 +161,7 @@ class SynchronizedOverlay extends olOverlay {
const position = this.getPosition();
if (position) {
const sourceProjection = this.parent_.getMap().getView().getProjection();
this.positionWGS84_ = olProj.transform(position, sourceProjection, 'EPSG:4326');
this.positionWGS84_ = transform(position, sourceProjection, 'EPSG:4326');
} else {
this.positionWGS84_ = undefined;
}
Expand Down Expand Up @@ -192,7 +192,7 @@ class SynchronizedOverlay extends olOverlay {
}
return clone;
}
olDom.removeChildren(this.element);
removeChildren(this.element);
const element = this.getElement();
if (element) {
if (element.parentNode && element.parentNode.childNodes) {
Expand Down
Loading

0 comments on commit 91ee49d

Please sign in to comment.