我希望能够在调用a后将填充添加到地图视图中map.fitBounds(),因此无论地图控件还是打开时覆盖标记的滑动面板之类的东西都可以看到所有标记.Leaftlet可以选择为fitBounds添加填充,但Google Maps没有.
有时,最北端的标记部分隐藏在视口上方.最西侧的标记通常位于缩放滑块下方.使用API 2,可以通过减少地图视口中的给定填充来形成虚拟视口,然后调用该方法showBounds()来计算并基于该虚拟视口执行缩放和居中:
map.showBounds(bounds, {top:30,right:10,left:50});
Run Code Online (Sandbox Code Playgroud)
本作API 2所述的工作实施例中,可以发现这里的showBounds()的例子链接下.
我在API V3中找不到类似的功能,但希望还有另一种方法可以实现.也许我可以抓住东北和西南点,然后添加假坐标以在包括它们之后进一步扩展边界?
(Codepen以防下面的代码不起作用)
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
draggable: true,
streetViewControl: false,
zoomControl: false
});
var marker1 = new google.maps.Marker({
position: {lat: 37, lng: -121},
map: map,
});
var marker2 = new google.maps.Marker({
position: {lat: 39.3, lng: -122},
map: map,
});
var bounds = new google.maps.LatLngBounds();
bounds.extend(marker1.position);
bounds.extend(marker2.position);
map.fitBounds(bounds);
}Run Code Online (Sandbox Code Playgroud)
#map {
height: 640px;
width: 360px;
} …Run Code Online (Sandbox Code Playgroud)我有与此处描述的完全模式相同的多态连接表:http://aaronvb.com/articles/a-polymorphic-join-table.html
class Location < ActiveRecord::Base
has_many :note_joins, as: :notable
has_many :notes, through: :note_joins
end
class Checkpoint < ActiveRecord::Base
has_many :note_joins, as: :notable
has_many :notes, through: :note_joins
end
class NoteJoin < ActiveRecord::Base
belongs_to :notable, polymorphic: true
belongs_to :note
end
class Note < ActiveRecord::Base
attr_accessible :content, :user_id
belongs_to :notable, polymorphic: true
belongs_to :user
has_many :note_joins
end
Run Code Online (Sandbox Code Playgroud)
我希望能够一次创建和更新多种类型的多态关联,而不必执行@note.locations << Location.first或更新@note.checkpoints << Checkpoint.first.
有点像@note.create note_joins_params并且@note.update note_joins_params会很棒的东西.
到目前为止,我能够实现创建部分的方法是将一系列属性传递给@note.note_joins.create,例如:
note_joins_params = [{"notable_id"=>"9225", "notable_type"=>"Location"}, …Run Code Online (Sandbox Code Playgroud) 这与此问题类似,但我无法弄清楚如何将其转换为Mongoid语法:
让我说我有 Customer: {_id: ..., orders: [...]}
我希望能够找到所有拥有现有订单的客户,即orders.size> 0.我尝试过的查询Customer.where(:orders.size.gt => 0)无济于事.可以与exists?运营商合作吗?
我有这样的模型关系:
class User
include Mongoid.Document
has_many :favorite_shows
end
class FavoriteShow
include Mongoid.Document
belongs_to :user
belongs_to :show
end
class Show
include Mongoid.Document
has_many :favorite_shows
end
Run Code Online (Sandbox Code Playgroud)
FavoriteShow是用户之间的联接表,并且使用user_id和show_id作为外键进行显示。尽管这些外键已经存在,但我仍然收到以下错误:
Problem:
When adding a(n) Show to User#favorite_shows, Mongoid could not determine the inverse foreign key to set. The attempted key was 'user_id'.
Summary:
When adding a document to a relation, Mongoid attempts to link the newly added document to the base of the relation in memory, as well as set the foreign key to link …Run Code Online (Sandbox Code Playgroud)