Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
static prepProjection() {
// define the projection for this application and reproject defaults
Ol_Proj.setProj4(proj4js);
proj4js.defs(appConfig.DEFAULT_PROJECTION.code, appConfig.DEFAULT_PROJECTION.proj4Def);
// Ol3 doesn't properly handle the "urn:ogc:def:crs:OGC:1.3:CRS84"
// string in getCapabilities and parses it into "OGC:CRS84". This
// hopefully adds that as an equivalent projection
let epsg4326Proj = Ol_Proj.get("EPSG:4326");
let ogcCrs84Proj = new Ol_Proj_Projection({
code: "OGC:CRS84",
units: epsg4326Proj.getUnits(),
extent: epsg4326Proj.getExtent(),
global: epsg4326Proj.isGlobal(),
metersPerUnit: epsg4326Proj.getMetersPerUnit(),
worldExtent: epsg4326Proj.getWorldExtent(),
getPointResolution: function(res, point) {
return Ol_Proj.getPointResolution("EPSG:4326", res, point);
}
});
Ol_Proj.addProjection(ogcCrs84Proj);
Ol_Proj.addEquivalentProjections([ogcCrs84Proj, epsg4326Proj]);
let mapProjection = Ol_Proj.get(appConfig.DEFAULT_PROJECTION.code);
mapProjection.setExtent(appConfig.DEFAULT_PROJECTION.extent);
uicreated: () => {
this._lizmap3 = lizMap;
// Register projection if unknown
if (!getProjection(this.projection)) {
const proj = this.config.options.projection;
proj4.defs(proj.ref, proj.proj4);
register(proj4);
}
// Create Lizmap modules
this.map = new Map();
this.edition = new Edition();
this.geolocation = new Geolocation();
this.geolocationSurvey = new GeolocationSurvey();
this.selectionTool = new SelectionTool();
this.digitizing = new Digitizing();
this.snapping = new Snapping();
}
});
getSegmentInfo(geom) {
// convert the first point of the line to 4326
// so a UTM zone can be determined.
let point0 = new olPoint(geom.coordinates[0]);
point0 = point0.transform(this.props.mapProjection, 'EPSG:4326');
// determine an appropriate utm zone for measurement.
const utm_zone = proj.get(util.getUtmZone(point0.getCoordinates()));
const coords = [].concat(geom.coordinates);
// ensure the last point is the current cursor.
// only when there is an active sketch!
if(this.props.cursor.sketchGeometry !== null) {
coords[coords.length - 1] = this.props.cursor.coords;
}
const segments = [];
for(let i = 1, ii = coords.length; i < ii; i++) {
const seg_len = this.calculateLength(coords[i - 1], coords[i], utm_zone);
const bearing = this.getBearing(coords[i - 1], coords[i]);
segments.push({
if (typeof proj4Def === "undefined") {
proj4js.defs(projection.code, projection.proj4Def);
Ol_Proj4_register(proj4js); // catch registry updates
Ol_Proj.get(projection.code).setExtent(projection.extent);
}
// load aliases
if (typeof projection.aliases !== "undefined") {
for (let i = 0; i < projection.aliases.length; ++i) {
proj4js.defs(projection.aliases[i], proj4js.defs(projection.code));
Ol_Proj4_register(proj4js); // catch registry updates
}
}
}
return Ol_Proj.get(appConfig.DEFAULT_PROJECTION.code);
}
var margin = this.get('margin');
// Limit max line draw
var ds = (xmax-xmin)/step*spacing;
if (ds>w)
{ var dt = Math.round((xmax-xmin)/w*spacing /step);
step *= dt;
if (step>this.fac) step = Math.round(step/this.fac)*this.fac;
}
xmin = (Math.floor(xmin/step))*step -step;
ymin = (Math.floor(ymin/step))*step -step;
xmax = (Math.floor(xmax/step))*step +2*step;
ymax = (Math.floor(ymax/step))*step +2*step;
var extent = ol_proj_get(proj).getExtent();
if (extent)
{ if (xmin < extent[0]) xmin = extent[0];
if (ymin < extent[1]) ymin = extent[1];
if (xmax > extent[2]) xmax = extent[2]+step;
if (ymax > extent[3]) ymax = extent[3]+step;
}
var hasLines = this.getStyle().getStroke() && this.get("stroke");
var hasText = this.getStyle().getText();
var hasBorder = this.getStyle().getFill();
ctx.save();
ctx.scale(ratio,ratio);
ctx.beginPath();
ctx.rect(margin, margin, w-2*margin, h-2*margin);
export function createExtentFromProjection (projection) {
projection = getProj(projection)
let extent = projection.getExtent()
if (!extent) {
let half = 180 * METERS_PER_UNIT[PROJ_UNIT.DEGREES] /
projection.getMetersPerUnit()
extent = createOrUpdateExtent(-half, -half, half, half)
}
return extent
}
$scope.getExtentFromBoundingBoxAttribute = function (layer) {
var extent = null;
var bbox = layer.get("BoundingBox");
if (angular.isArray(bbox) && bbox.length == 4) {
extent = transformExtent(bbox, 'EPSG:4326', hsMap.map.getView().getProjection());
} else {
for (var ix = 0; ix < bbox.length; ix++) {
if (angular.isDefined(getProj(bbox[ix].crs)) || angular.isDefined(layer.getSource().getParams().FROMCRS)) {
var crs = bbox[ix].crs || layer.getSource().getParams().FROMCRS;
var b = bbox[ix].extent;
var first_pair = [b[0], b[1]]
var second_pair = [b[2], b[3]];
first_pair = transform(first_pair, crs, hsMap.map.getView().getProjection());
second_pair = transform(second_pair, crs, hsMap.map.getView().getProjection());
extent = [first_pair[0], first_pair[1], second_pair[0], second_pair[1]];
break;
}
}
}
return extent;
},
registerProjection(projection: Projection) {
proj4.defs(projection.code, projection.def);
olproj4.register(proj4);
if (projection.extent) {
olproj.get(projection.code).setExtent(projection.extent);
}
}
update: (layer, newOptions, oldOptions, map) => {
if (oldOptions.securityToken !== newOptions.securityToken
|| oldOptions.srs !== newOptions.srs
|| oldOptions.format !== newOptions.format
|| oldOptions._v_ !== newOptions._v_
|| oldOptions.style !== newOptions.style) {
return createLayer(newOptions, map);
}
if (get(oldOptions, 'vectorStyle.body') !== get(newOptions, 'vectorStyle.body')
|| get(oldOptions, 'vectorStyle.url') !== get(newOptions, 'vectorStyle.url')) {
applyStyle(newOptions.vectorStyle, layer);
}
return null;
},
render: () => {