์๋ . ๋ทฐํฌํธ๋ฅผ ๊ธฐ์ค์ผ๋ก ์ง๋์ ์ค์ฌ์ ์คํ์ ํ ์ ์๋ค๋ฉด ์ ๋ง ๋ฉ์ง ๊ฒ์ ๋๋ค. ๋ด ์ฃผ์ ์ฌ์ฉ ์ฌ๋ก๋ ์ผ์ชฝ์ ์ง๋๋ฅผ ์ค๋ฒ๋ ์ดํ๋ ํฐ ์์๊ฐ ์๊ณ ์ง๋ ์ค์์ด ์ค๋ฅธ์ชฝ์ ๋ ์ค๋๋ก ํ๋ ๊ฒ์ ๋๋ค. ์ด๊ฒ์ ๋ด๊ฐ ํฌ์ด๋ ์ผํฐ๋ฅผ ์ํํ ๋ ์ค์ ๋ก ํน์ ์์ ํฝ์ ๋๋ ๋ทฐํฌํธ์ ๋ฐฑ๋ถ์จ์ ์คํ์ ํ๋ค๋ ๊ฒ์ ์๋ฏธํฉ๋๋ค. ์ด๊ฒ์ ์ง๋ ์์ค ์ค์ ์ผ ๊ฒ์ ๋๋ค.
๋ง์ JS ๋งคํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์์ ์ด ๊ธฐ๋ฅ์ ์ํ์ง๋ง ์์ง ์ฐพ์ง ๋ชปํ์ต๋๋ค. ๋ถํํ๋ API์์ ์๋นํ ๋ฎ์ ์์ค์ด์ด์ผ ํฉ๋๋ค.
์ฃ์กํฉ๋๋ค. ์ฝ๋๊ฐ ์๊ณ ๊ทธ๋ฅ ์๊ฐํ๊ณ ์์๋๋ฐ ์ฝ๋๋ฅผ ๋ด๋ ค๋๊ณ ์ถ์์ต๋๋ค.
๋ฉ์ง ํ๋ก์ ํธ์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค!
์ค์ ๋ก Leaflet์์๋ ๋งค์ฐ ์ฝ์ต๋๋ค. ํ์ํ ๊ฒ์ map.containerPointToLatLng ๋ฉ์๋์ ๋๋ค. ์ง๋์ ์ผ์ชฝ ์๋จ ๋ชจ์๋ฆฌ๋ฅผ ๊ธฐ์ค์ผ๋ก ์ผ๋ถ ํฝ์ ์ขํ๋ฅผ ์ง๋ฆฌ์ ์์น๋ก ๋ณํํฉ๋๋ค. ๊ทธ๋์ ๋ค์๊ณผ ๊ฐ์ด ํฉ๋๋ค.
var centerPoint = map.getSize().divideBy(2),
targetPoint = centerPoint.subtract([overlayWidth, 0]),
targetLatLng = map.containerPointToLatLng(centerPoint);
map.panTo(targetLatLng);
์ด๋ ๊ฒ ํ๋ฉด ์ฌ์ฉ ์ฌ๋ก๊ฐ ํด๊ฒฐ๋ฉ๋๊น?
์ด๋ด. ๊ทธ๊ฒ์ ์ผ์ข ์ ์ํ์ด๋ฉฐ ์๋ง๋ ์ถฉ๋ถํ ๊ฒ์ ๋๋ค. ๊ทธ๋ฌ๋ ์ฌ๊ธฐ์์ ๋ฌธ์ ๋ ๋ทฐํฌํธ๊ฐ ์ค์ฌ์ ๋๊ณ ์ถ์ ์์น๋ผ๊ณ ๊ฐ์ ํ ๋ค์ ์คํ์ ํ์ฌ ๋ ๋จ๊ณ ์ด๋์ด ๋ ๊ฒ์ด๋ผ๋ ์ ์ ๋๋ค. ์๋-๊ฒฝ๋๋ฅผ ์ทจํ๋ ๊ฒ๊ณผ๋ ๋ฐ๋๋ก ์คํ์ ํ ๋ค์ ํจ๋ํฉ๋๋ค. ํ๋์ ์์ง์.
์ ์ ๊ณ์ฐ์ด ์ ํํ์ง ์์ต๋๋ค. ์คํ์
์ค์ฌ์ด ๋์ ์ง์ ์ ์๊ณ ์คํ์
์ด overlayWidth / 2
์ ๊ฐ๋๋ก ์ค์ ์ง๋ ์ค์ฌ์ ์ค์ ํด์ผ ํฉ๋๋ค. ๋จ์ผ ๋์์ ๋ํ ์์
์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
var targetPoint = map.project(targetLatLng, targetZoom).subtract([overlayWidth / 2, 0]),
targetLatLng = map.unproject(targetPoint, targetZoom);
map.setView(targetLatLng, targetZoom);
์ด๊ฒ์ ์ฐ๋ฆฌ๊ฐ ๊ฒช์๋ ๊ฒ๊ณผ ๊ฐ์ ๊ฒฝ์ฐ์ ๋๋ค. ์ฝ๊ฐ ๋ถํฌ๋ช ํ ์ฌ์ด๋๋ฐ๊ฐ ์ง๋ ์๋จ์ ์ค๋ฒ๋ ์ด๋์์ต๋๋ค. fitBounds()๋ฅผ ํธ์ถํ ๋๋ง๋ค ์ฝ๊ฐ ๋จ์ด์ ธ ์๊ณ ์ฌ๋ฐ๋ฅด๊ฒ ํ๊ธฐ ์ํด ๋ค๋ฅธ ๋์์ ์ํํด์ผ ํฉ๋๋ค. ์ฐ๋ฆฌ๋ ์ด์ ๋ํ ํ ๋ฆฌํ์คํธ๋ฅผ ๊ณ ๋ คํ๊ณ ์์์ง๋ง ์ฝ๊ฐ์ ์์ ์ด ๋ ์ ์๊ณ ์ถฉ๋ถํ ์ผ๋ฐ์ ์ธ ์ฌ์ฉ ์ฌ๋ก๊ฐ ์๋๋ผ๊ณ ์๊ฐํ๊ธฐ ๋๋ฌธ์ ์ฌ์ด๋๋ฐ๋ฅผ ์ง๋ ์์ผ๋ก ์ฎ๊ธฐ๋ ๊ฒ์ผ๋ก ๋์ด ๋ฌ์ต๋๋ค.
@mourner ๊ทธ๊ฒ์ ๋ง์ ์๋ฏธ๊ฐ ์์ต๋๋ค. project() ๋ฉ์๋๋ฅผ ๋์น ๊ฒ ๊ฐ์ต๋๋ค. ์ด๊ฒ์ ๋๋ถ๋ถ์ ์ฌ์ฉ ์ฌ๋ก๋ฅผ ์ฒ๋ฆฌํฉ๋๋ค. ๊ฐ์ฌํฉ๋๋ค.
@ajbeaven ์ฒ๋ผ (GeoJSON) ๋ ์ด์ด์ ๋ํ ์คํ์ fitBounds๋ ๋งค์ฐ ํ๋ฅญํ์ง๋ง ํจ์ฌ ๋ ๋ณต์กํ ๊ฒ ๊ฐ์ต๋๋ค. ๋ทฐํฌํธ์ ๊ฒฝ๊ณ๊ฐ ํจ๊ณผ์ ์ผ๋ก ๋ณ๊ฒฝ๋๊ณ ์๊ณ ํ ๋ฒ์ ํธ์ถ๋ก ์คํ์ ์ ์ํํ๋ ๋ฐฉ๋ฒ์ ์์ง ๋ชปํ๊ธฐ ๋๋ฌธ์ ์คํ์ ๋ง์ผ๋ก๋ ์ถฉ๋ถํ์ง ์๋ค๊ณ ์๊ฐํฉ๋๋ค.
์ด๋ ์ชฝ์ด๋ , ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์์ฒด์ ์ถ๊ฐํ๋ ๊ฒ์ด ํฉ๋ฆฌ์ ์ด์ง ์๋ค๋ฉด ์์ ๋กญ๊ฒ ๋ซ์ผ์ญ์์ค. ์ ๊ณต๋ ์ฝ๋๋ก ๋ด ํน์ ํ๋ก์ ํธ๋ฅผ ๊ด๋ฆฌํ ์ ์๋ค๊ณ ์๊ฐํฉ๋๋ค. ๊ฐ์ฌ ํด์.
fitBounds
๋ ์ข ๋ ์ฅํฉํ์ง๋ง ์ฝ์ต๋๋ค. ์ด https://github.com/CloudMade/Leaflet/blob/master/src/map/Map.js#L275 ๋ฉ์๋๋ฅผ ๋ณต์ฌํ์ฌ ๋ถ์ฌ๋ฃ๊ณ ์ฌ์ฉํ๋ ํฌ๊ธฐ๋ฅผ ์์ ํ ๋ค์ ์ฌ์ฉํ์ธ์.
var targetZoom = altGetBoundsZoom(map, bounds);
// ... calculate targetLatLng as above
map.setView(targetLatLng, targetZoom);
์๋
. fitBounds
๋ฅผ ๋งค๊ฐ๋ณ์๋ก LatLng[]
์ ํจ๊ป ์ฌ์ฉํ๊ณ ์์ผ๋ฉฐ ์์์ ์ ๊ณตํ ์ฝ๋ ์กฐ๊ฐ์ ์ฌ์ฉํ๋ ค๊ณ ์๋ํ์ง๋ง ์ด์ด ์์์ต๋๋ค.
๋ด ์น์๋ ์ง๋๋ฅผ ์๋์ ํ์ํ๋ ค๋ ์ฌ์ด๋๋ฐ ์ค๋ฒ๋ ์ด๊ฐ ์์ง๋ง ์ด ์ค๋ฒ๋ ์ด ์๋์ ๋ง์ปค๊ฐ ํ์๋์ง ์๋๋ก ํ๊ณ ์ถ์ต๋๋ค. (์ง๋ ์ค์ฌ์ ์คํ์
ํ๋ ๊ฒ๋ ์ข์ง๋ง ์๋์ผ๋ก ์ํํ ์ ์์ต๋๋ค.)
fitBounds
์ ๋ํ ์ ์ฒด ์ฝ๋ ์กฐ๊ฐ์ _offset map_์ ๊ฒ์ํด ์ฃผ์๊ฒ ์ต๋๊น?
์์ ์ฐ์ ๋ด์ฉ์ด ๋ง์ด ํท๊ฐ๋ฆฌ๋ค์. ๋ฌธ์ ๋ ํฌ์ธํธ ๋ฐฐ์ด์ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ targetLatLng
๋ targetPoint
$๊ฐ ์๋ค๋ ๊ฒ์
๋๋ค.
ใ ์ปจํ ์ด๋์ ๊ฐ ๋ฉด์ ์ธ๋ฏธ ์ค๋ฒ๋ ์ด๋ ๊ณต๊ฐ์ ์์ ์ ์ํ๋ ์ต์ ์ด ์์ผ๋ฉด ์ ๋ง ๋ฉ์ง ๊ฒ์ ๋๋ค. ์ฌ๊ธฐ์ ์ฌ์ ํ ์ง๋๋ฅผ ๊ทธ๋ฆด ์ ์์ง๋ง ๋ง์ปค์ ์ปจํธ๋กค์ ๋ฐฐ์นํ์ง ์์ ๊ฒ์ ๋๋ค.
์ฌ๊ธฐ์์ ๋ด๊ฐ ๊ตฌํํ ์ฝ๋๋ฅผ ๋ณผ ์ ์์ต๋๋ค. (์ด๊ฒ์ ๊ฒฐ์ฝ ํ๋ฅญํ ์ฝ๋ ์ธ์คํด์ค๋ ์๋์ง๋ง ์์ด๋์ด๋ ์์ต๋๋ค) ๋ํ Leaflet ๋งต์ธ ๋งต ์์ฑ์ ๋ณด์ ํ๋ ๊ฐ์ฒด์ ๋ด์ฅ๋์ด ์์ต๋๋ค. ๋ค์๊ณผ ๊ฐ์ ๋ฐฉ๋ฒ์ด ์์ต๋๋ค.
์ฑ์
๋ทฐ
appSetBounds
appGetBoundsZoom
https://github.com/MinnPost/minnpost-my-boundaries/blob/master/visualizations/index.html#L556
๋ด์ฅ๋ ์ด ๊ธฐ๋ฅ์ ์ถ๊ฐํ๋ ๊ฒ์ด ์ ์ฉํ ๊ฒ์ด๋ฏ๋ก ๋ค์ ์ฝ๋๋ค.
๋๋ ๊ทธ ๋ค์ ์ง๋์ ํจ๊ป 550px์ ํ๋ฉด ์ผ์ชฝ์ ๋ชฉ๋ก์ด ์์ด์ผ ํ๊ธฐ ๋๋ฌธ์ ์ด ํ ๋ก ์ ์ ํ๊ฒ ๋์์ต๋๋ค. L.Map์ ์ผ๋ถ ๊ธฐ๋ณธ ๊ธฐ๋ฅ์ ์ฌ์ ์ํ๋ ๊ฒ์ด ๋ ์ฌ์ธ ๊ฒ์ด๋ผ๊ณ ๊ฒฐ์ ํ์ต๋๋ค. ๋ชจ๋ ์์ด๋์ด์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
๋ชจ๋ ํด๊ฒฐ๋์์ผ๋ฉด ์ข๊ฒ ์ง๋ง 100% ํ์ ํ ์๋ ์์ต๋๋ค.
MapCenterOffsetMixin = {
UIOffset: [550, 0], // x, y
getBounds: function(){
var a=this.getPixelBounds(),
b=this.unproject(new L.Point(a.min.x+this.UIOffset[0],a.max.y+this.UIOffset[1]), this._zoom,!0),
c=this.unproject(new L.Point(a.max.x,a.min.y),this._zoom,!0);
return new L.LatLngBounds(b,c)
},
_latLngToNewLayerPoint: function (latlng, newZoom, newCenter) {
var targetPoint = this.project(newCenter, newCenter).subtract([this.UIOffset[0]/2, this.UIOffset[1]/2]),
newCenter = this.unproject(targetPoint, newZoom);
var topLeft = this._getNewTopLeftPoint(newCenter, newZoom).add(this._getMapPanePos());
return this.project(latlng, newZoom)._subtract(topLeft);
},
_getCenterLayerPoint: function () {
return this.containerPointToLayerPoint(this.getSize().divideBy(2).add([this.UIOffset[0]/2, this.UIOffset[1]/2]));
},
_resetView: function (a, b, c, d) {
var e = this._zoom !== b;
// Change the center
var targetPoint = this.project(a, b).subtract([this.UIOffset[0] / 2, this.UIOffset[1]/2]),
a = this.unproject(targetPoint, b);
d || (this.fire("movestart"), e && this.fire("zoomstart")), this._zoom = b, this._initialTopLeftPoint = this._getNewTopLeftPoint(a);
if (!c) L.DomUtil.setPosition(this._mapPane, new L.Point(0, 0));
else {
var f = L.DomUtil.getPosition(this._mapPane);
this._initialTopLeftPoint._add(f)
}
this._tileLayersToLoad = this._tileLayersNum, this.fire("viewreset", {
hard: !c
}), this.fire("move"), (e || d) && this.fire("zoomend"), this.fire("moveend"), this._loaded || (this._loaded = !0, this.fire("load"))
}
}
L.Map.include(MapCenterOffsetMixin);
@averrips ์ฌ๋ ค ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค. ๊ทํ์ ์๋ฃจ์ ์ ํ์ฌ ์ ์๋ํ๊ณ ์์ต๋๋ค ... Firefox์์ ํ๋/์ถ์ ์ปจํธ๋กค์ด ์ด์ ๊นจ์ง ๊ฒ์ ์ ์ธํ๊ณ :( ์ผ์ข ์ "catchall"์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. TypeError: t is undefined
๋ค์์ ์ง๋์ ์์ด์ผ ํ๋ fitBoundsPadded์ ๊ตฌํ์
๋๋ค.
fitBounds์ฒ๋ผ ์ฌ์ฉํ์ง๋ง ์ํ๋ ํจ๋ฉ์ ์ ๋ฌํ๋ฏ๋ก ๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉํฉ๋๋ค.
map.fitBoundsPadded(myBounds, new L.Point(0, 0), new L.Point(0, 150));
๊ทธ๋ฆฌ๊ณ ์ฝ๋:
fitBoundsPadded: function (bounds, paddingTopLeft, paddingBottomRight) { //(LatLngBounds, Point, Point)
var zoom = this.getBoundsZoom(bounds);
var zoomToTry = zoom;
while (true) {
var newTopLeft = this.unproject(this.project(bounds.getNorthEast(), zoomToTry).add(paddingTopLeft), zoomToTry);
var newBottomRight = this.unproject(this.project(bounds.getSouthWest(), zoomToTry).add(paddingBottomRight), zoomToTry);
var paddedBounds = new L.LatLngBounds([bounds.getSouthWest(), bounds.getNorthEast(), newTopLeft, newBottomRight]);
var zoom2 = this.getBoundsZoom(paddedBounds);
if (zoom2 == zoomToTry) {
return this.fitBounds(paddedBounds);
} else {
zoomToTry--;
}
}
},
๋ง์คํฐ์์ ๊ตฌํ! ๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉํ์ญ์์ค.
map.fitBounds(bounds, [20, 30], [40, 50]); // bounds, topLeftPadding, bottomRightPadding
๋๋ ๋ ๋ฒ์งธ ์ธ์๋ง ์ ๋ฌํ๋ฉด ์ค๋ฅธ์ชฝ ํ๋จ ํจ๋ฉ์ด ๊ธฐ๋ณธ์ ์ผ๋ก ์ผ์ชฝ ์๋จ๊ณผ ๋์ผํ๊ฒ ์ค์ ๋ฉ๋๋ค.
์๋ช ์ด ์กฐ๊ธ ๋ฐ๋์์ต๋๋ค. ์ด์ ๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉํฉ๋๋ค.
map.fitBounds(bounds, {
padding: [20, 30]
});
map.fitBounds(bounds, {
paddingTopLeft: [20, 30],
paddingbottomRight: [40, 50]
});
๋ค๋ฅธ ๊ธฐ๋ฅ์ ํจ๋ฉ์ ์ถ๊ฐํ๋ ์์ ์ด ๊ณํ๋์ด ์์ต๋๊น?
์๋ง๋, ์. setView
๋ฐ panTo
์ด์.
๋ชจ๋ ๋ฉด์ ๋์ผํ ํจ๋ฉ์ ์ ์ฉํ๊ธฐ ์ํ ๋ฐ๋ก ๊ฐ๊ธฐ๊ฐ ์์ด์ผ ํฉ๋๋ค. ์ด ๊ฐ์.
map.fitBounds(bounds, { padding: 20 });
ํ์ฌ ๋์ ...
map.fitBounds(bounds, { padding: [20, 20] });
@averrips Mixin์ด ๋ง์ ๋์์ด ๋์์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค.
์์ง ์๋ฃจ์ ์ ์ฐพ์ ์ ์์ผ๋ฏ๋ก ์ฌ๊ธฐ๋ก ์ด๋ํฉ๋๋ค(์ ๋ง ์ฝ์ต๋๋ค).
๊ธฐ๋ฅ ์ค์ฌ(์ง๋, ์๋, ์คํ์ , ์คํ์ ) { var ์ผํฐ = map.project(latlng); ์ค์ฌ = ์๋ก์ด L.point(center.x+offsetx,center.y+offsety); var ๋์ = map.unproject(์ค์); map.panTo(๋์); }
"setView" ๋ฐ "panTo"์๋ ๋์ผํ ๊ธฐ๋ฅ์ ์ถ๊ฐํ์ญ์์ค.
๊ฐ์ฌ ํด์!
๋ํ ์ผ์ชฝ | ์ค๋ฅธ์ชฝ ์ปจํธ๋กค๋ ํจ๋ฉํ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
๋ค์์ ํ์ฌ https://github.com/codeforamerica/lv-trucks-map(http://clvfoodtrucks.com/ ์ ๋ผ์ด๋ธ ์ฌ์ดํธ)์ ์๋ ํ๋ก์ ํธ์์ ์คํ์ ์ ์ฌ์ฉํ์ฌ panTo๋ฅผ ๊ตฌํํ ๋ฐฉ๋ฒ์ ๋๋ค. L.map ํ๋กํ ํ์ ๊ฐ์ฒด๋ฅผ ์์ ํ์ฌ ์ด ๋ฉ์๋๋ฅผ ์ง๋ ๊ฐ์ฒด์์ "๊ธฐ๋ณธ์ ์ผ๋ก" ์ฌ์ฉํ ์ ์์ผ๋ฉฐ ์ง๋๋ฅผ ์์ฑํ๊ธฐ ์ ์ JavaScript ์ฝ๋์ ์ถ๊ฐํด์ผ ํฉ๋๋ค.
L.Map.prototype.panToOffset = function (latlng, offset, options) {
var x = this.latLngToContainerPoint(latlng).x - offset[0]
var y = this.latLngToContainerPoint(latlng).y - offset[1]
var point = this.containerPointToLatLng([x, y])
return this.setView(point, this._zoom, { pan: options })
}
panTo() ์ ๋์ผํ๊ฒ ์๋ํ์ง๋ง [xOffset, yOffset]
ํ์์ ๋ฐฐ์ด์ธ ์ถ๊ฐ ๋งค๊ฐ๋ณ์ offset
๊ฐ ์์ต๋๋ค. ์ด๊ฒ์ ์์ ํ์ฌ setViewOffset() ๋ฉ์๋๋ ๋ง๋ค ์ ์์ต๋๋ค.
๊ณ ๋ง์, ๋ฃจ!
์ฐธ๊ณ ๋ก ์ด ๊ตฌ์ฑ์ Foursquare ํํ์ด์ง์์ ๋ณผ ์ ์๋ ์ํ ์คํ์
์ ์๋ฎฌ๋ ์ดํธํ๋ ๋ฐ ์ ํฉํฉ๋๋ค.
https://gist.github.com/missinglink/7620340
@louh๋ ๊ฐ์ฌํฉ๋๋ค!
@missinglink ๊ฐ์ฌํฉ๋๋ค. ์ฝ๋๊ฐ ์๋ํฉ๋๋ค!
ํ๋/์ถ์ ์์ ์๋ ์๋ฃจ์ ์ด ์์ต๋๊น?
๋๋ ๋ค์๊ณผ ๊ฐ์ ๊ฒ์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
var MapCenterOffsetMixin = {
getMapOffset: function() {
console.log('getMapOffset');
return [$('#left-panel').offset().left, 0];
},
getBounds: function(){
console.log('getBounds');
var offset = this.getMapOffset(),
bounds = this.getPixelBounds(),
sw = this.unproject(new L.Point(bounds.min.x + offset[0], bounds.max.y + offset[1]), this._zoom, !0),
ne = this.unproject(new L.Point(bounds.max.x, bounds.min.y), this._zoom, !0);
return new L.LatLngBounds(sw, ne)
},
_oldLatLngToNewLayerPoint: L.Map.prototype._latLngToNewLayerPoint,
_latLngToNewLayerPoint: function (latlng, newZoom, newCenter) {
console.log('_latLngToNewLayerPoint');
var offset = this.getMapOffset(),
targetPoint = this.project(newCenter, newCenter).subtract([offset[0] / 2, offset[1] / 2]);
newCenter = this.unproject(targetPoint, newZoom);
return this._oldLatLngToNewLayerPoint(latlng, newZoom, newCenter);
},
_getCenterLayerPoint: function () {
console.log('_getCenterLayerPoint');
var offset = this.getMapOffset();
return this.containerPointToLayerPoint(this.getSize().divideBy(2).add([offset[0] / 2, offset[1] / 2]));
},
_oldResetView: L.Map.prototype._resetView,
_resetView: function (center, zoom, preserveMapOffset, afterZoomAnim) {
console.log('_resetView');
var offset = this.getMapOffset(),
targetPoint = this.project(center, zoom).subtract([offset[0] / 2, offset[1] / 2]);
center = this.unproject(targetPoint, zoom);
this._oldResetView(center, zoom, preserveMapOffset, afterZoomAnim);
}
};
L.Map.include(MapCenterOffsetMixin);
ํ์ง๋ง ํ๋/์ถ์์ ์คํจํฉ๋๋ค.
ํด๊ฒฐ์ฑ ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. https://github.com/Mappy/Leaflet-active-area. ๋ฉ์ง! :)
'map.fitBounds(bounds, topLeftPadding, bottomRightPadding)' ํจ์๋ ํฝ์ ์ด ์๋ ์๋๋ฅผ ์กฐ์ ํ๊ธฐ ์ํด ๊ฐ์ ์ฌ์ฉํ๋ ๊ฒ ๊ฐ์ต๋๋ค. ๋ฐ๋ผ์ ํ๋/์ถ์ ์์ค์ ๋ฐ๋ผ ์ง๋๊ฐ ์กฐ์ ๋๋ ์ ๋์ ๋ฐ๋ผ ๋ค๋ฅธ ๊ฒฐ๊ณผ๊ฐ ๋ํ๋ฉ๋๋ค. ๋๋ ์ด๊ฒ์ ๋ํ ์ฌ์ฉ ์ฌ๋ก๊ฐ ์๋ค๊ณ ํ์ ํ์ง๋ง, ์กฐ์ ์ด ํ๋/์ถ์ ์์ค์ ์์กดํด์๋ ์ ๋๋ค๋ ์ค์ ํฌ๊ธฐ ์ฌ์ด๋ ๋ฐ ๋๋ ์์ ๋ฉ๋ด์ ๊ฐ์ด ๋ชจ๋ ์ฌ๋์ด ์ ๊ธฐํ๋ ๋ฌธ์ ์ธ ๊ฒ ๊ฐ์ต๋๋ค. ์ขํ๊ฐ ์๋ ํฝ์ ์ ๊ธฐ๋ฐ์ผ๋ก ํจ๋ฉ์ ์ถ๊ฐํ๋ ๋ด์ฅ ์ ๋จ์ง ๊ธฐ๋ฅ์ด ์์ต๋๊น?
topLeftPadding
๋ฐ bottomRightPadding
์์ ๊ฐ(ํฝ์
): http://leafletjs.com/reference.html#map -fitboundsoptions
์ด๋ค ์ด์ ์์์ธ์ง ์ ์๊ฒ๋ ๊ทธ๋ ์ง ์์ ๊ฒ ๊ฐ์ต๋๋ค. ์ด๊ฒ์ ํ
์คํธํ๊ธฐ ์ํด 15์ ํ๋/์ถ์ ์์ค์์ ๋ง์ปค๋ฅผ ์ค์์ ๋์ ๋ค์ ์ด ๋ช
๋ น์ ์คํํฉ๋๋ค...
map.fitBounds(pointsArray, {paddingTopLeft: [0,0], paddingBottomRight: [800,0], maxZoom: map.getZoom()});
๊ทธ๋ฐ ๋ค์ 19์ ํ๋/์ถ์ ์์ค์์ ๋ง์ปค๋ฅผ ์ค์์ ๋๊ณ ๋ค์ ์คํํฉ๋๋ค. ๋ ๋ฒจ 15์์๋ ์ด๋ํ๋ ์์ด ๊ฑฐ์ ๋์ ๋์ง ์์ต๋๋ค. ๊ทธ๋ฌ๋ ๋ ๋ฒจ 19์์๋ ํ์ด์ง์ ์ ๋ฐ ์ ๋๋ฅผ ์ด๋ํฉ๋๋ค. ๋ด ํจ์ ํธ์ถ์์ ๋ญ๊ฐ ์๋ชปํ๊ณ ์์ต๋๊น?
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋ค์์ ํ์ฌ https://github.com/codeforamerica/lv-trucks-map(http://clvfoodtrucks.com/ ์ ๋ผ์ด๋ธ ์ฌ์ดํธ)์ ์๋ ํ๋ก์ ํธ์์ ์คํ์ ์ ์ฌ์ฉํ์ฌ panTo๋ฅผ ๊ตฌํํ ๋ฐฉ๋ฒ์ ๋๋ค. L.map ํ๋กํ ํ์ ๊ฐ์ฒด๋ฅผ ์์ ํ์ฌ ์ด ๋ฉ์๋๋ฅผ ์ง๋ ๊ฐ์ฒด์์ "๊ธฐ๋ณธ์ ์ผ๋ก" ์ฌ์ฉํ ์ ์์ผ๋ฉฐ ์ง๋๋ฅผ ์์ฑํ๊ธฐ ์ ์ JavaScript ์ฝ๋์ ์ถ๊ฐํด์ผ ํฉ๋๋ค.
panTo() ์ ๋์ผํ๊ฒ ์๋ํ์ง๋ง
[xOffset, yOffset]
ํ์์ ๋ฐฐ์ด์ธ ์ถ๊ฐ ๋งค๊ฐ๋ณ์offset
๊ฐ ์์ต๋๋ค. ์ด๊ฒ์ ์์ ํ์ฌ setViewOffset() ๋ฉ์๋๋ ๋ง๋ค ์ ์์ต๋๋ค.