MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / limitScale

Method limitScale

src/openlayers/mapping/WebMap.js:776–822  ·  view source on GitHub ↗
(mapInfo, baseLayer)

Source from the content-addressed store, hash-verified

774 }
775
776 limitScale(mapInfo, baseLayer) {
777 if (this.validScale(mapInfo.minScale) && this.validScale(mapInfo.maxScale)) {
778 let visibleScales, minScale, maxScale;
779 if (baseLayer.layerType === 'WMTS') {
780 visibleScales = baseLayer.scales;
781 minScale = +mapInfo.minScale.split(':')[1];
782 maxScale = +mapInfo.maxScale.split(':')[1];
783 } else {
784 const scales = this.scales.map((scale) => {
785 return 1 / scale.split(':')[1];
786 });
787 if (Array.isArray(baseLayer.visibleScales) && baseLayer.visibleScales.length && baseLayer.visibleScales) {
788 visibleScales = baseLayer.visibleScales;
789 } else {
790 visibleScales = scales;
791 }
792 minScale = 1 / +mapInfo.minScale.split(':')[1];
793 maxScale = 1 / +mapInfo.maxScale.split(':')[1];
794 }
795 const minVisibleScale = this.findNearest(visibleScales, minScale);
796 const maxVisibleScale = this.findNearest(visibleScales, maxScale);
797 let minZoom = visibleScales.indexOf(minVisibleScale);
798 let maxZoom = visibleScales.indexOf(maxVisibleScale);
799 if (minZoom > maxZoom) {
800 [minZoom, maxZoom] = [maxZoom, minZoom];
801 }
802 if (minZoom !== 0 || maxZoom !== visibleScales.length - 1) {
803 const oldViewOptions = this.map.getView().options_ || this.map.getView().getProperties();
804 this.map.setView(
805 new View(
806 Object.assign({}, oldViewOptions, {
807 maxResolution: undefined,
808 minResolution: undefined,
809 minZoom,
810 maxZoom,
811 constrainResolution: false
812 })
813 )
814 );
815 this.map.addInteraction(
816 new MouseWheelZoom({
817 constrainResolution: true
818 })
819 );
820 }
821 }
822 }
823
824 parseNumber(scaleStr) {
825 return Number(scaleStr.split(':')[1]);

Callers 1

addBaseMapMethod · 0.95

Calls 6

validScaleMethod · 0.95
findNearestMethod · 0.95
mapMethod · 0.80
indexOfMethod · 0.80
getViewMethod · 0.80
setViewMethod · 0.80

Tested by

no test coverage detected