@planet/layers
Advanced tools
Comparing version 1.10.5-0 to 1.10.5-1
@@ -23,2 +23,6 @@ 'use strict'; | ||
var _polygon = require('ol/geom/polygon'); | ||
var _polygon2 = _interopRequireDefault(_polygon); | ||
var _createLayer = require('./createLayer'); | ||
@@ -35,4 +39,4 @@ | ||
propTypes: { | ||
bounds: _propTypes2.default.array.isRequired, | ||
crossOrigin: _propTypes2.default.string, | ||
extent: _propTypes2.default.array, | ||
loadFunction: _propTypes2.default.func, | ||
@@ -44,10 +48,33 @@ projection: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.object]), | ||
// Reproject extent from LatLon to Web Mercator or Custom Projection | ||
reprojectExtent: function reprojectExtent(extent, projection) { | ||
return _proj2.default.transformExtent(extent, _constants.GEO_PROJECTION, projection || _constants.WEB_PROJECTION); | ||
// Reproject extent from LatLon to Web Mercator | ||
reprojectExtent: function reprojectExtent(extent) { | ||
return _proj2.default.transformExtent(extent, _constants.GEO_PROJECTION, _constants.WEB_PROJECTION); | ||
}, | ||
// Reproject the bounds' geometry | ||
reprojectGeometry: function reprojectGeometry(geometry, projection) { | ||
return geometry.clone().transform(_constants.GEO_PROJECTION, projection); | ||
}, | ||
getExtentFromBounds: function getExtentFromBounds(bounds, projection) { | ||
// Create a polygon from the bounds | ||
var geometry = new _polygon2.default(bounds); | ||
var extent = void 0; | ||
if (projection) { | ||
// Reproject the geometry and get the extent | ||
// (Resulting extent will be in projection) | ||
extent = this.reprojectGeometry(geometry, projection).getExtent(); | ||
} else { | ||
// Reproject the extent to Web Mercator for map | ||
extent = this.reprojectExtent(geometry.getExtent()); | ||
} | ||
return extent; | ||
}, | ||
componentWillMount: function componentWillMount() { | ||
// Create the image source | ||
var source = new _imagestatic2.default({ | ||
url: this.props.url, | ||
imageExtent: this.reprojectExtent(this.props.extent, this.props.projection), | ||
imageExtent: this.getExtentFromBounds(this.props.bounds, this.props.projection), | ||
imageSize: this.props.size, | ||
@@ -59,2 +86,3 @@ projection: this.props.projection || _constants.WEB_PROJECTION, | ||
// Create the image layer | ||
this.layer = new _image2.default({ | ||
@@ -65,3 +93,3 @@ source: source, | ||
}, | ||
componentWillReceiveProps: function componentWillReceiveProps(nextProps) { | ||
componentWillReceiveProps: function componentWillReceiveProps(nextProps, nextContext) { | ||
if (nextProps.url !== this.props.url) { | ||
@@ -74,3 +102,3 @@ var source = this.layer.getSource(); | ||
url: nextProps.url, | ||
imageExtent: this.reprojectExtent(nextProps.extent, nextProps.projection), | ||
imageExtent: this.getExtentFromBounds(nextProps.bounds, nextProps.projection), | ||
imageSize: nextProps.size, | ||
@@ -77,0 +105,0 @@ projection: nextProps.projection || _constants.WEB_PROJECTION, |
@@ -5,2 +5,3 @@ import PropTypes from 'prop-types'; | ||
import Proj from 'ol/proj'; | ||
import Polygon from 'ol/geom/polygon'; | ||
import createLayer from './createLayer'; | ||
@@ -12,4 +13,4 @@ import { WEB_PROJECTION, GEO_PROJECTION } from './constants'; | ||
propTypes: { | ||
bounds: PropTypes.array.isRequired, | ||
crossOrigin: PropTypes.string, | ||
extent: PropTypes.array, | ||
loadFunction: PropTypes.func, | ||
@@ -21,10 +22,33 @@ projection: PropTypes.oneOfType([PropTypes.string, PropTypes.object]), | ||
// Reproject extent from LatLon to Web Mercator or Custom Projection | ||
reprojectExtent: function reprojectExtent(extent, projection) { | ||
return Proj.transformExtent(extent, GEO_PROJECTION, projection || WEB_PROJECTION); | ||
// Reproject extent from LatLon to Web Mercator | ||
reprojectExtent: function reprojectExtent(extent) { | ||
return Proj.transformExtent(extent, GEO_PROJECTION, WEB_PROJECTION); | ||
}, | ||
// Reproject the bounds' geometry | ||
reprojectGeometry: function reprojectGeometry(geometry, projection) { | ||
return geometry.clone().transform(GEO_PROJECTION, projection); | ||
}, | ||
getExtentFromBounds: function getExtentFromBounds(bounds, projection) { | ||
// Create a polygon from the bounds | ||
var geometry = new Polygon(bounds); | ||
var extent = void 0; | ||
if (projection) { | ||
// Reproject the geometry and get the extent | ||
// (Resulting extent will be in projection) | ||
extent = this.reprojectGeometry(geometry, projection).getExtent(); | ||
} else { | ||
// Reproject the extent to Web Mercator for map | ||
extent = this.reprojectExtent(geometry.getExtent()); | ||
} | ||
return extent; | ||
}, | ||
componentWillMount: function componentWillMount() { | ||
// Create the image source | ||
var source = new ImageStatic({ | ||
url: this.props.url, | ||
imageExtent: this.reprojectExtent(this.props.extent, this.props.projection), | ||
imageExtent: this.getExtentFromBounds(this.props.bounds, this.props.projection), | ||
imageSize: this.props.size, | ||
@@ -36,2 +60,3 @@ projection: this.props.projection || WEB_PROJECTION, | ||
// Create the image layer | ||
this.layer = new StaticImageLayer({ | ||
@@ -42,3 +67,3 @@ source: source, | ||
}, | ||
componentWillReceiveProps: function componentWillReceiveProps(nextProps) { | ||
componentWillReceiveProps: function componentWillReceiveProps(nextProps, nextContext) { | ||
if (nextProps.url !== this.props.url) { | ||
@@ -51,3 +76,3 @@ var source = this.layer.getSource(); | ||
url: nextProps.url, | ||
imageExtent: this.reprojectExtent(nextProps.extent, nextProps.projection), | ||
imageExtent: this.getExtentFromBounds(nextProps.bounds, nextProps.projection), | ||
imageSize: nextProps.size, | ||
@@ -54,0 +79,0 @@ projection: nextProps.projection || WEB_PROJECTION, |
{ | ||
"name": "@planet/layers", | ||
"version": "1.10.5-0", | ||
"version": "1.10.5-1", | ||
"description": "React components for OpenLayers", | ||
@@ -5,0 +5,0 @@ "module": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
435321
12454