Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix PolygonCoordinatesType #2456

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix center point calculation error in Map.fitExtent
xiarx authored and xiarx committed Nov 6, 2024
commit 831c7278091d79e9c9f78a4b9a0e5c496821d586
13 changes: 7 additions & 6 deletions src/map/Map.ts
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ import Handlerable from '../handler/Handlerable';
import Point from '../geo/Point';
import Size from '../geo/Size';
import PointExtent from '../geo/PointExtent';
import Extent from '../geo/Extent';
import Extent, { ExtentLike } from '../geo/Extent';
import Coordinate from '../geo/Coordinate';
import Layer from '../layer/Layer';
import Renderable from '../renderer/Renderable';
@@ -1152,7 +1152,7 @@ export class Map extends Handlerable(Eventable(Renderable(Class))) {

/**
* Set the map to be fit for the given extent with the max zoom level possible.
* @param {Extent} extent - extent
* @param {ExtentLike} extent - extent
* @param {Number} zoomOffset - zoom offset
* @param {Object} [options={}] - options
* @param {Object} [options.animation]
@@ -1167,14 +1167,15 @@ export class Map extends Handlerable(Eventable(Renderable(Class))) {
* @param {Function} step - step function for animation
* @return {Map | player} - this
*/
fitExtent(extent: Extent, zoomOffset?: number, options?: MapFitType, step?: (frame) => void) {
fitExtent(extent: ExtentLike, zoomOffset?: number, options?: MapFitType, step?: (frame) => void) {
options = (options || {} as any);
if (!extent) {
return this;
}
extent = new Extent(extent, this.getProjection());
const zoom = this.getFitZoom(extent, options.isFraction || false, options) + (zoomOffset || 0);
let center = extent.getCenter();
const syncExtent = new Extent(extent);
const zoom = this.getFitZoom(syncExtent, options.isFraction || false, options) + (zoomOffset || 0);
const containerExtent = syncExtent.convertTo(p => this.coordToPoint(p));
let center = this.pointToCoord(containerExtent.getCenter() as Point);
if (this._getPaddingSize(options)) {
center = this._getCenterByPadding(center, zoom, options);
}
12 changes: 12 additions & 0 deletions test/map/MapSpec.js
Original file line number Diff line number Diff line change
@@ -366,6 +366,18 @@ describe('Map.Spec', function () {
map.fitExtent(extent.toJSON());
});

it('fit to china extent', function (done) {
const chinaExtent = [73.499013,3.397894,135.087377,53.561308];
map.fitExtent(chinaExtent, 0, { 'animation': false });
const [lon, lat] = map.getCenter().toArray();
const lonDiff = Math.abs(lon - 104.293195);
const latDiff = Math.abs(lat - 31.76872613);
const delta = Math.pow(10,-10);
expect(lonDiff).to.be.below(delta);
expect(latDiff).to.be.below(delta);
done();
});

it('update zoom', function (done) {
map.once('zoomend', function () {
map.once('zoomend', function () {