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

Adding leaflet.map.zoomToGeomtries for bounds behaviour #6

Merged
merged 1 commit into from
Jan 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions geo_file_entity.make
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ projects[features][subdir] = contrib

projects[eck][version] = 2.0-rc3
projects[eck][subdir] = contrib

; Libraries
libraries[leaflet_zoomtogeometries][download][type] = "file"
libraries[leaflet_zoomtogeometries][download][url] = "https://github.com/NuCivic/leaflet.map.zoomToGeometries.js/zipball/master"
23 changes: 23 additions & 0 deletions geo_file_entity.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,26 @@
*/

include_once 'geo_file_entity.features.inc';

/**
* Implements hook_libraries_info().
*/
function geo_file_entity_libraries_info() {
$libraries = array();
$libraries['leaflet_zoomtogeometries'] = array(
'name' => 'Leaflet Map zoomToGeometries',
'vendor url' => 'http://github.com/NuCivic/',
'download url' => 'https://github.com/NuCivic/leaflet.map.zoomToGeometries.js/zipball/master',
'path' => '',
'version arguments' => array(
'file' => 'bower.json',
'pattern' => '/"version": "(\d+\.\d+\.\d+)"/',
),
'files' => array(
'js' => array(
'dist/leaflet.map.zoomToGeometries.min.js',
),
),
);
return $libraries;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,12 @@
var div = $('#geofile-geojson-display .wrapper');
var map = new L.map(div.get(0)).setView([37.8, -96], 4);
var geojson = new L.GeoJSON(settings.geojson);
var bounds = new L.LatLngBounds();

for (var layer in geojson._layers) {
if (geojson._layers.hasOwnProperty(layer)){
var feature = geojson._layers[layer].feature;
for ( var j = 1; j < feature.geometry.coordinates[0].length; j++ ) {
var latlng = feature.geometry.coordinates[0][j];
latlng = new L.LatLng(latlng[1],latlng[0]);
bounds.extend(latlng);
}
}
}

map.fitBounds(bounds);

var mapUrl = "//otile{s}-s.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png";
var osmAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Tiles Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img src="//developer.mapquest.com/content/osm/mq_logo.png">';
var bg = new L.TileLayer(mapUrl, {maxZoom: 18, attribution: osmAttribution, subdomains: '1234'});

map.addLayer(bg);
geojson.addTo(map);
map.zoomToGeometries(geojson);
},
};
})(jQuery);
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function geo_file_entity_geojson_bundle_entity_view_alter(&$build, $type) {

// Add js controller and stylesheets.
$module_path = drupal_get_path('module', 'geo_file_entity_geojson_bundle');
libraries_load('leaflet_zoomtogeometries');
drupal_add_js($module_path . '/geo_file_entity_geojson_bundle.js');
drupal_add_css($module_path . '/geo_file_entity_geojson_bundle.css');
}
Expand Down