Leaflet custom map

(3 posts) (2 voices)

Tags:

No tags yet.

  1. maron, Member

    Hello.

    I have been working with the openstreetmap extension and with some minor change to code managed to apply a custom projection of a map for a limited area using proj4 and proj4leaflet.

    Currently it is a bit of a hack, but could be improved by allowing us to pass an options object to the map object.

    my change to code is the following

    in users/extensions.php


    $proj4 = array(
    Extension::getBaseURL().'user/extensions/proj4leaflet/proj4.js',
    Extension::getBaseURL().'user/extensions/proj4leaflet/proj4leaflet.js',
    Extension::getBaseURL().'user/extensions/proj4leaflet/epsg3057crs.js'
    ); array_splice( $dbr_extensions['openstreetmap']['javascript'], 3, 0, $proj4);

    contents of epsg3057crs.js

    var crs = new L.Proj.CRS('EPSG:3057', '+proj=lcc +lat_1=64.25 +lat_2=65.75 +lat_0=65 +lon_0=-19 +x_0=500000 +y_0=500000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs', { resolutions: [2048,1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25,0.125,0.0625], origin: [0, 0], bounds: L.bounds([0, 0], [1048576, 1048576]) } );

    in extensions/openstreetmap/openstreetmap.js line 35
    this.map = L.map(this.map_id, { crs: crs });

    My report


    select 'dbr.openstreetmap','coordinates','Test',800,600;
    select 'dbr.openstreetmap.tiles','https://secret.map.domain/mapcache/tms/1.0.0/aerial@isn93/{z}/{x}/{y}.jpg',"{ minZoom: 0, maxZoom: 15, tms: true, crossOrigin: null}";
    select 64.14244,-21.927561

    This works great, but no other openstreetmap will now work in the system.

    1. Is there a way to pass the crs object in options in the initial definition of openstreetmap.

    2. The crs option (Projections) can not be added or changed after the map object is initialized. Is there any way we could create a javascript variable (crs) and include the additional javascript libraries in dbr.javascript before the leaflet library is processed - is skipping onload enough here maybe?

    Of course I could copy the openstreetmap extension and create a fully new one, but it feels like a bit of overkill.

  2. myDBR Team, Key Master

    Maron,
    you do not need to override the openstreetmap as you can use the dbr.head-command to include the needed files.

    1. Is there a way to pass the crs object in options in the initial definition of openstreetmap.

    In the most recent build there is a new command dbr.openstreetmap.options that you can use to pass additional options to the L.map.

    select 'dbr.openstreetmap.options', '{crs: crs}';

    2. The crs option (Projections) can not be added or changed after the map object is initialized. Is there any way we could create a javascript variable (crs) and include the additional javascript libraries in dbr.javascript before the leaflet library is processed - is skipping onload enough here maybe?

    if you omit the onload, the command is executed when the scipt is loaded. By placing the JavaScript before the OSM extension call will execute it before the OSM.

    --
    myDBR Team

  3. maron, Member

    Works perfectly - thanks a lot.


Reply

You must log in to post.