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

Fix: Restrict Map Zoom Levels to Supported Range #331

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/load_data_geo_extent/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@
<script type="text/javascript">
const map = new NetJSONGraph("http://localhost:3000/api/data/?page=1", {
render: "map",
maxPointsFetched: 35,
// set map initial state.
maxPointsFetched: 35,
mapOptions: {
center: [46.86764405052012, 19.675998687744144],
zoom: 5,
maxZoom: 18,
zoomControl: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this necessary?

nodeConfig: {
label: {
offset: [0, -10],
Expand Down
5 changes: 4 additions & 1 deletion src/js/netjsongraph.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const NetJSONGraphDefaultConfig = {
svgRender: false,
switchMode: false,
maxPointsFetched: 10000,
maxZoom : 18,
minZoom : 3,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These options are defined 3 times.
Are you sure these are needed here? It seems to me they're not.

loadMoreAtZoomLevel: 9,
clustering: false,
clusteringThreshold: 100,
Expand Down Expand Up @@ -161,6 +163,7 @@ const NetJSONGraphDefaultConfig = {
mapOptions: {
roam: true,
zoomAnimation: false,
maxZoom: 18,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can move the minZoom option here.

nodeConfig: {
type: "scatter",
label: {
Expand Down Expand Up @@ -238,7 +241,7 @@ const NetJSONGraphDefaultConfig = {
"http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
options: {
minZoom: 3,
maxZoom: 32,
maxZoom: 18,
attribution: `&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors,
tiles offered by <a href="https://www.mapbox.com">Mapbox</a>`,
},
Expand Down
15 changes: 14 additions & 1 deletion src/js/netjsongraph.render.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class NetJSONGraphRender {
return {
leaflet: {
tiles: configs.mapTileConfig,
mapOptions: configs.mapOptions,
mapOptions: {...configs.mapOptions , maxZoom : configs.maxZoom },
},
series,
...configs.mapOptions.baseOptions,
Expand Down Expand Up @@ -597,6 +597,19 @@ class NetJSONGraphRender {
}
});


self.leaflet = self.echarts._api.getCoordinateSystems()[0].getLeaflet();
self.leaflet._zoomAnimated = false;

self.leaflet.options.maxZoom = self.config.maxZoomLevel;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where on hearth is maxZoomLevel coming from??


self.leaflet.on("zoomend", () => {
if (self.leaflet.getZoom() > self.config.maxZoomLevel) {
self.leaflet.setZoom(self.config.maxZoomLevel);
}
});


self.leaflet.on("zoomend", () => {
if (self.leaflet.getZoom() < self.config.disableClusteringAtLevel) {
const nodeData = self.utils.makeCluster(self);
Expand Down
Loading