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

added a way to exclude some points from the map bounds #9

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.markdown
Expand Up @@ -54,6 +54,12 @@ Make sure your HTML has a `div` element for the Google map, and there is a conta
<p>Example Text.</p> <p>Example Text.</p>
</div> </div>
</div> </div>
<div class="map-location" data-jmapping="{id: 8, point: {lat: 35.845, lng: -79.139}, category: 'Beer', bounded: false}">
<a href="#" class="map-link">A Place outside the bounds of the map</a>
<div class="info-box">
<p>You might have to pan/zoom to see this location.</p>
</div>
</div>
</div> </div>


Then just call the `jMapping` function on the map element: Then just call the `jMapping` function on the map element:
Expand Down Expand Up @@ -105,7 +111,7 @@ These are options that can be passed to the `jMapping` function to change specif
* *Default*: `{lat: 0.0, lng: 0.0}` * *Default*: `{lat: 0.0, lng: 0.0}`
* This point determines the Google Maps location if there are no location elements inside the specified `location_selector`. * This point determines the Google Maps location if there are no location elements inside the specified `location_selector`.
* `metadata_options`: * `metadata_options`:
* *Default*: `{type: "attr", name: "data"}` * *Default*: `{type: "attr", name: "data-jmapping"}`
* This is the set of options passed to the jQuery metadata function. It defines how the necessary * This is the set of options passed to the jQuery metadata function. It defines how the necessary
metadata for each location will be searched for. metadata for each location will be searched for.
See the [metadata plugins docs](http://docs.jquery.com/Plugins/Metadata/metadata#toptions) for more info. See the [metadata plugins docs](http://docs.jquery.com/Plugins/Metadata/metadata#toptions) for more info.
Expand Down
26 changes: 16 additions & 10 deletions jquery.jmapping.js
Expand Up @@ -103,17 +103,23 @@


var getBounds = function(doUpdate){ var getBounds = function(doUpdate){
var places_data = getPlacesData(doUpdate), var places_data = getPlacesData(doUpdate),
newBounds, initialPoint; newBounds = null, point;

if (places_data.length){
initialPoint = $.jMapping.makeGLatLng(places_data[0].point);
}else{
initialPoint = $.jMapping.makeGLatLng(settings.default_point);
}
newBounds = new google.maps.LatLngBounds(initialPoint, initialPoint);


for (var i=1, len = places_data.length; i<len; i++) { for (var i=0, len = places_data.length; i<len; i++) {
newBounds.extend($.jMapping.makeGLatLng(places_data[i].point)); // if 'bounded' specified AND it's false, don't add it to the bounds
if (places_data[i].bounded != false) {
point = $.jMapping.makeGLatLng(places_data[i].point);
if (newBounds == null) {
newBounds = new google.maps.LatLngBounds(point, point);
} else {
newBounds.extend(point);
}
}
}
// if newBounds not set, just use the default_point from settings
if (newBounds == null) {
point = $.jMapping.makeGLatLng(settings.default_point);
newBounds = new google.maps.LatLngBounds(point, point);
} }
return newBounds; return newBounds;
}; };
Expand Down