void NSRPopplerDocument::renderPage(int page) { double dpix, dpiy; if (_doc == NULL || page > getNumberOfPages() || page < 1) return; _page = _catalog->getPage(page); if (isTextOnly()) { PDFRectangle *rect; GooString *text; TextOutputDev *dev; dev = new TextOutputDev (0, gFalse, gFalse, gFalse); _doc->displayPageSlice(dev, _page->getNum(), 72, 72, 0, gFalse, gTrue, gFalse, -1, -1, -1, -1); rect = _page->getCropBox(); text = dev->getText(rect->x1, rect->y1, rect->x2, rect->y2); _text = processText(QString::fromUtf8(text->getCString())); delete text; delete dev; _readyForLoad = true; return; } if (isZoomToWidth()) { double wZoom = ((double) getScreenWidth() / (double) _page->getCropWidth() * 100.0); setZoomSilent((int) wZoom); } if (getZoom() > getMaxZoom()) setZoomSilent (getMaxZoom()); else if (getZoom() < getMinZoom()) setZoomSilent (getMinZoom()); if (_readyForLoad) _dev->startPage(0, NULL); dpix = _dpix * getZoom() / 100.0; dpiy = _dpiy * getZoom() / 100.0; _page->display(_dev, dpix, dpiy, getRotation(), gFalse, gFalse, gTrue, _catalog); _readyForLoad = true; }
CameraOptions Map::cameraForLatLngs(const std::vector<LatLng>& latLngs, const EdgeInsets& padding) { CameraOptions options; if (latLngs.empty()) { return options; } // Calculate the bounds of the possibly rotated shape with respect to the viewport. PrecisionPoint nePixel = {-INFINITY, -INFINITY}; PrecisionPoint swPixel = {INFINITY, INFINITY}; for (LatLng latLng : latLngs) { PrecisionPoint pixel = pixelForLatLng(latLng); swPixel.x = std::min(swPixel.x, pixel.x); nePixel.x = std::max(nePixel.x, pixel.x); swPixel.y = std::min(swPixel.y, pixel.y); nePixel.y = std::max(nePixel.y, pixel.y); } double width = nePixel.x - swPixel.x; double height = nePixel.y - swPixel.y; // Calculate the zoom level. double scaleX = (getWidth() - padding.left - padding.right) / width; double scaleY = (getHeight() - padding.top - padding.bottom) / height; double minScale = ::fmin(scaleX, scaleY); double zoom = ::log2(getScale() * minScale); zoom = ::fmax(::fmin(zoom, getMaxZoom()), getMinZoom()); // Calculate the center point of a virtual bounds that is extended in all directions by padding. PrecisionPoint paddedNEPixel = { nePixel.x + padding.right / minScale, nePixel.y + padding.top / minScale, }; PrecisionPoint paddedSWPixel = { swPixel.x - padding.left / minScale, swPixel.y - padding.bottom / minScale, }; PrecisionPoint centerPixel = { (paddedNEPixel.x + paddedSWPixel.x) / 2, (paddedNEPixel.y + paddedSWPixel.y) / 2, }; options.center = latLngForPixel(centerPixel); options.zoom = zoom; return options; }
bool OsmAnd::ImageMapLayerProvider::obtainData( const IMapDataProvider::Request& request_, std::shared_ptr<IMapDataProvider::Data>& outData, std::shared_ptr<Metric>* const pOutMetric /*= nullptr*/) { const auto& request = MapDataProviderHelpers::castRequest<Request>(request_); if (pOutMetric) pOutMetric->reset(); // Check provider can supply this zoom level if (request.zoom > getMaxZoom() || request.zoom < getMinZoom()) { outData.reset(); return true; } if (!supportsNaturalObtainData()) return MapDataProviderHelpers::nonNaturalObtainData(this, request, outData, pOutMetric); // Obtain image data const auto image = obtainImage(request); if (image.isNull()) { outData.reset(); return true; } // Decode image data std::shared_ptr<SkBitmap> bitmap(new SkBitmap()); SkMemoryStream imageStream(image.constData(), image.length(), false); if (!SkImageDecoder::DecodeStream(&imageStream, bitmap.get(), SkColorType::kUnknown_SkColorType, SkImageDecoder::kDecodePixels_Mode)) return false; // Return tile outData.reset(new IRasterMapLayerProvider::Data( request.tileId, request.zoom, getAlphaChannelPresence(), getTileDensityFactor(), bitmap)); return true; }
CameraOptions Map::cameraForLatLngs(std::vector<LatLng> latLngs, EdgeInsets padding) { CameraOptions options; if (latLngs.empty()) { return options; } // Calculate the bounds of the possibly rotated shape with respect to the viewport. vec2<> nePixel = {-INFINITY, -INFINITY}; vec2<> swPixel = {INFINITY, INFINITY}; for (LatLng latLng : latLngs) { vec2<> pixel = pixelForLatLng(latLng); swPixel.x = std::min(swPixel.x, pixel.x); nePixel.x = std::max(nePixel.x, pixel.x); swPixel.y = std::min(swPixel.y, pixel.y); nePixel.y = std::max(nePixel.y, pixel.y); } vec2<> size = nePixel - swPixel; // Calculate the zoom level. double scaleX = (getWidth() - padding.left - padding.right) / size.x; double scaleY = (getHeight() - padding.top - padding.bottom) / size.y; double minScale = ::fmin(scaleX, scaleY); double zoom = ::log2(getScale() * minScale); zoom = ::fmax(::fmin(zoom, getMaxZoom()), getMinZoom()); // Calculate the center point of a virtual bounds that is extended in all directions by padding. vec2<> paddedNEPixel = { nePixel.x + padding.right / minScale, nePixel.y + padding.top / minScale, }; vec2<> paddedSWPixel = { swPixel.x - padding.left / minScale, swPixel.y - padding.bottom / minScale, }; vec2<> centerPixel = (paddedNEPixel + paddedSWPixel) * 0.5; LatLng centerLatLng = latLngForPixel(centerPixel); options.center = centerLatLng; options.zoom = zoom; return options; }
void Map::fitBounds(AnnotationSegment segment, EdgeInsets padding, Duration duration) { if (segment.empty()) { return; } // Calculate the bounds of the possibly rotated shape with respect to the viewport. vec2<> nePixel = {-INFINITY, -INFINITY}; vec2<> swPixel = {INFINITY, INFINITY}; for (LatLng latLng : segment) { vec2<> pixel = pixelForLatLng(latLng); swPixel.x = std::min(swPixel.x, pixel.x); nePixel.x = std::max(nePixel.x, pixel.x); swPixel.y = std::min(swPixel.y, pixel.y); nePixel.y = std::max(nePixel.y, pixel.y); } vec2<> size = nePixel - swPixel; // Calculate the zoom level. double scaleX = (getWidth() - padding.left - padding.right) / size.x; double scaleY = (getHeight() - padding.top - padding.bottom) / size.y; double minScale = std::fmin(scaleX, scaleY); double zoom = std::log2(getScale() * minScale); zoom = std::fmax(std::fmin(zoom, getMaxZoom()), getMinZoom()); // Calculate the center point of a virtual bounds that is extended in all directions by padding. vec2<> paddedNEPixel = { nePixel.x + padding.right / minScale, nePixel.y + padding.top / minScale, }; vec2<> paddedSWPixel = { swPixel.x - padding.left / minScale, swPixel.y - padding.bottom / minScale, }; vec2<> centerPixel = (paddedNEPixel + paddedSWPixel) * 0.5; LatLng centerLatLng = latLngForPixel(centerPixel); setLatLngZoom(centerLatLng, zoom, duration); }
void TransformState::setMaxZoom(const double maxZoom) { if (maxZoom >= getMinZoom()) { max_scale = zoomScale(util::clamp(maxZoom, util::MIN_ZOOM, util::MAX_ZOOM)); } }