• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

298
Views
¿Es posible bloquear el centro de un mapa de capas abiertas?

Quiero bloquear el centro de mi mapa de capas abiertas. Entonces, en la inicialización, centro el mapa, pero después de eso quiero que el mapa permanezca centrado pero permita el zoom. Deshabilité la interacción dragPan pero al hacer zoom en los mapas se acerca a la posición del mouse en lugar del centro del mapa. ¿Es posible cambiar este comportamiento?

about 3 years ago · Santiago Trujillo
1 answers
Answer question

0

Se puede hacer usando una restricción de extensión central de ancho y alto cero:

 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.9.0/css/ol.css" type="text/css"> <style> html, body, .map { margin: 0; padding: 0; width: 100%; height: 100%; } </style> <script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.9.0/build/ol.js"></script> <title>OpenLayers example</title> </head> <body> <div id="map" class="map"></div> <script type="text/javascript"> var center = ol.proj.fromLonLat([37.41, 8.82]); var map = new ol.Map({ target: 'map', layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }) ], view: new ol.View({ center: center, zoom: 4, extent: center.concat(center), constrainOnlyCenter: true, smoothExtentConstraint: false }) }); </script> </body> </html>

about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error