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

add mapbox token and map center location for new asset pages #27

Merged
merged 1 commit into from Feb 18, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions flexmeasures/ui/crud/assets.py
Expand Up @@ -10,13 +10,14 @@
from wtforms.validators import DataRequired
from sqlalchemy.exc import IntegrityError

from flexmeasures.data.config import db
from flexmeasures.data.auth_setup import unauthorized_handler
from flexmeasures.data.services.users import (
get_users,
create_user,
InvalidFlexMeasuresUser,
)
from flexmeasures.data.services.resources import get_markets
from flexmeasures.data.services.resources import get_markets, get_center_location
from flexmeasures.data.models.assets import AssetType, Asset
from flexmeasures.data.models.user import User
from flexmeasures.data.models.markets import Market
Expand Down Expand Up @@ -188,7 +189,11 @@ def get(self, id: str):

asset_form = with_options(NewAssetForm())
return render_flexmeasures_template(
"crud/asset_new.html", asset_form=asset_form, msg=""
"crud/asset_new.html",
asset_form=asset_form,
msg="",
map_center=get_center_location(db, user=current_user),
mapboxAccessToken=current_app.config.get("MAPBOX_ACCESS_TOKEN", ""),
)

get_asset_response = InternalApi().get(
Expand Down Expand Up @@ -268,7 +273,11 @@ def post(self, id: str):
if asset is None:
msg = "Cannot create asset. " + error_msg
return render_flexmeasures_template(
"crud/asset_new.html", asset_form=asset_form, msg=msg
"crud/asset_new.html",
asset_form=asset_form,
msg=msg,
map_center=get_center_location(db, user=current_user),
mapboxAccessToken=current_app.config.get("MAPBOX_ACCESS_TOKEN", ""),
)

else:
Expand All @@ -278,6 +287,8 @@ def post(self, id: str):
"crud/asset_new.html",
asset_form=asset_form,
msg="Cannot edit asset.",
map_center=get_center_location(db, user=current_user),
mapboxAccessToken=current_app.config.get("MAPBOX_ACCESS_TOKEN", ""),
)
patch_asset_response = InternalApi().patch(
url_for("flexmeasures_api_v2_0.patch_asset", id=id),
Expand Down
5 changes: 3 additions & 2 deletions flexmeasures/ui/templates/crud/asset_new.html
Expand Up @@ -167,13 +167,14 @@ <h3>Location</h3>

// create map
var assetMap = L
.map('mapid', { center: [33.37, 126.57], zoom: 10 })
.map('mapid', { center: [{{ map_center[0] }}, {{ map_center[1] }}], zoom: 10})
.on('popupopen', function () {
$(function () {
$('[data-toggle="tooltip"]').tooltip();
});
});
tileLayer.addTo(assetMap);
addTileLayer(assetMap, '{{ mapboxAccessToken }}');


var location_icon = new L.DivIcon({
className: 'map-icon',
Expand Down