MCPcopy Index your code
hub / github.com/Maps4HTML/MapML.js / _memoizeExtent

Method _memoizeExtent

src/map-feature.js:450–544  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

448 // and return cache when feature's extent is repeatedly requested
449 // for .extent
450 _memoizeExtent() {
451 // memoize calculated extent
452 let extentCache;
453 return function () {
454 if (extentCache && this._getFeatureExtent) {
455 // if the extent has already been calculated and is not updated, return stored extent
456 return extentCache;
457 } else {
458 // calculate feature extent
459 let map = this.getMapEl()._map,
460 geometry = this.querySelector('map-geometry'),
461 cs = geometry.getAttribute('cs') || this._getFallbackCS(),
462 // zoom level that the feature rendered at
463 zoom = this.zoom,
464 shapes = geometry.querySelectorAll(
465 'map-point, map-linestring, map-polygon, map-multipoint, map-multilinestring'
466 ),
467 bboxExtent = [
468 Infinity,
469 Infinity,
470 Number.NEGATIVE_INFINITY,
471 Number.NEGATIVE_INFINITY
472 ];
473 for (let shape of shapes) {
474 let coord = shape.querySelectorAll('map-coordinates');
475 for (let i = 0; i < coord.length; ++i) {
476 bboxExtent = _updateExtent(shape, coord[i], bboxExtent);
477 }
478 }
479 let topLeft = point(bboxExtent[0], bboxExtent[1]);
480 let bottomRight = point(bboxExtent[2], bboxExtent[3]);
481 let pcrsBound = Util.boundsToPCRSBounds(
482 bounds(topLeft, bottomRight),
483 zoom,
484 map.options.projection,
485 cs
486 );
487 if (
488 shapes.length === 1 &&
489 shapes[0].tagName.toUpperCase() === 'MAP-POINT'
490 ) {
491 let projection = map.options.projection,
492 maxZoom = this.hasAttribute('max')
493 ? +this.getAttribute('max')
494 : M[projection].options.resolutions.length - 1,
495 tileCenter = M[projection].options.crs.tile.bounds.getCenter(),
496 pixel = M[projection].transformation.transform(
497 pcrsBound.min,
498 M[projection].scale(+this.zoom || maxZoom)
499 );
500 pcrsBound = Util.pixelToPCRSBounds(
501 bounds(pixel.subtract(tileCenter), pixel.add(tileCenter)),
502 this.zoom || maxZoom,
503 projection
504 );
505 }
506 let result = Object.assign(
507 Util._convertAndFormatPCRS(

Callers 1

extentMethod · 0.95

Calls 6

getMapElMethod · 0.95
_getFallbackCSMethod · 0.95
_getZoomBoundsMethod · 0.95
boundsFunction · 0.85
getAttributeMethod · 0.80
addMethod · 0.80

Tested by

no test coverage detected