0
私はLatLongブログ与えられ、それはoffsetXとoffsetYを考慮Googleマップを中心され、この機能を使用していた。Googleマップ.fitBounds()とカスタムoffsetCenter?
self.customCenter (marker.position, $('aside').width(), 0);
しかし、今、彼ら:私は、のようなので、を使用してい
customCenter: function (latlng, offsetx, offsety) {
// latlng is the apparent centre-point
// offsetx is the distance you want that point to move to the right, in pixels
// offsety is the distance you want that point to move upwards, in pixels
var self = this;
var scale = Math.pow(2, self.map.getZoom());
google.maps.event.addListenerOnce(self.map,"projection_changed", function() {
var worldCoordinateCenter = self.map.getProjection().fromLatLngToPoint(latlng);
var pixelOffset = new google.maps.Point((offsetx/scale) || 0,(offsety/scale) ||0)
var worldCoordinateNewCenter = new google.maps.Point(
worldCoordinateCenter.x - pixelOffset.x,
worldCoordinateCenter.y + pixelOffset.y
);
var newCenter = self.map.getProjection().fromPointToLatLng(worldCoordinateNewCenter);
self.map.setCenter(newCenter);
});
}
マーカーのオフセット(これなしでfitboundsに私を求めている」ビューの外にある
は(通常はこれと同じように使用:)var bounds = new google.maps.LatLngBounds();
bounds.extend(myPlace);
bounds.extend(Item_1);
bounds.extend(Item_2);
bounds.extend(Item_3);
self.map.fitBounds(bounds);
しかし、私はこの2つの機能
を結合する方法が表示されない(私はさておき、フローティング(POS持っているので、これは次のとおりです。
:ちょうど私がオンラインで見つけるこの画像のように、Googleマップ上で絶対的に))
任意のアイデア?
customCenterWithBounds: function (offsetx, offsety) {
// offsetx is the distance you want that point to move to the right, in pixels
// offsety is the distance you want that point to move upwards, in pixels
var self = this;
self.map.fitBounds(self.bounds);
var mapCenter = self.map.getCenter();
var latlng = new google.maps.LatLng (mapCenter.lat(), mapCenter.lng());
var scale = Math.pow(2, self.map.getZoom());
google.maps.event.addListenerOnce(self.map,"projection_changed", function() {
var worldCoordinateCenter = self.map.getProjection().fromLatLngToPoint(latlng);
var pixelOffset = new google.maps.Point((offsetx/scale) || 0,(offsety/scale) ||0)
var worldCoordinateNewCenter = new google.maps.Point(
worldCoordinateCenter.x - pixelOffset.x,
worldCoordinateCenter.y + pixelOffset.y
);
var newCenter = self.map.getProjection().fromPointToLatLng(worldCoordinateNewCenter);
self.map.setCenter(newCenter);
});
}
をしかし、マップがover-ズーム...ともない、私がやってしまった
あなたはこのSOの質問をチェックアウトしましたか? https://developers.google.com/maps/documentation/javascript/reference#Map私は最高の答えが好きではありませんが、その下のものはあなたを助けることができます: 'fitBoundsWithPadding'。 – shotor
提案していただきありがとうございますが、正しいリンクだとお考えですか?ドキュメントページ –
が表示されます。ご迷惑をおかけいたします。https://stackoverflow.com/questions/10339365/google-maps-api-3-fitbounds-padding-ensure-markers-are-not-obscured-by-overlai – shotor