Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
948690c
map-feature development
yhy0217 Mar 15, 2023
8bdf983
add comments for intended zoom attribute behaviors
yhy0217 Mar 16, 2023
61e7d15
fix bug of the click() method
yhy0217 Mar 16, 2023
f0d9c91
handle focus, modify default click() and focus() methods and tests
yhy0217 Mar 17, 2023
b1c77fa
fix bugs, make layer element reload if the src attribute is changed
yhy0217 Mar 21, 2023
0f1c37d
small fix, make focus not toggled and remove the current focus state …
yhy0217 Mar 22, 2023
99963c5
Change context menu to copy location as a map-feature.
Mar 22, 2023
778ccac
make elements in mapml file migrate at loading stage
yhy0217 Mar 23, 2023
82e044c
small fix, add comments
yhy0217 Mar 23, 2023
e826e7a
fix issue 803
yhy0217 Mar 23, 2023
2cb95d7
map-feature development
yhy0217 Mar 15, 2023
fc9abfe
add comments for intended zoom attribute behaviors
yhy0217 Mar 16, 2023
35f290e
fix bug of the click() method
yhy0217 Mar 16, 2023
750207c
handle focus, modify default click() and focus() methods and tests
yhy0217 Mar 17, 2023
799897d
fix bugs, make layer element reload if the src attribute is changed
yhy0217 Mar 21, 2023
afba2db
small fix, make focus not toggled and remove the current focus state …
yhy0217 Mar 22, 2023
b71a648
make elements in mapml file migrate at loading stage
yhy0217 Mar 23, 2023
5137840
small fix, add comments
yhy0217 Mar 23, 2023
a9f50c5
fix issue 803
yhy0217 Mar 23, 2023
6afc79d
Add states and cors support for development needs
prushforth Mar 23, 2023
15335a6
Merge branch 'mapFeatureDev' of https://github.com/yhy0217/Web-Map-Cu…
prushforth Mar 23, 2023
e327ec3
fix bug: err is thrown if making changes on <map-feature> when templa…
yhy0217 Mar 24, 2023
671d76c
fix bug when projection is changed: XHR twice and multiple copies of …
yhy0217 Mar 24, 2023
e017d83
make map-properties can be interactively removed and added, change ge…
yhy0217 Mar 27, 2023
0ecda30
modify tests
yhy0217 Mar 27, 2023
9b65ea1
rename get geojson method for consistency, add tests
yhy0217 Mar 27, 2023
11f6535
simplify focus method
yhy0217 Mar 28, 2023
2442da5
Revert "Add states and cors support for development needs"
prushforth Mar 28, 2023
fe40ef3
Revert "Change context menu to copy location as a map-feature. Chan…
prushforth Mar 28, 2023
1b11858
rename _featureLayer to _featureGroup for consistency
yhy0217 Mar 29, 2023
6213105
Merge branch 'mapFeatureDev' of https://github.com/yhy0217/Web-Map-Cu…
yhy0217 Mar 29, 2023
a934b42
create private methods that imply layer- element is removed and conne…
yhy0217 Mar 29, 2023
40b5d9a
continue renaming
yhy0217 Mar 29, 2023
0d1bb7a
add getMaxZoom() method
yhy0217 Mar 30, 2023
0f0e467
zoomTo, paste, remove feature
yhy0217 Apr 3, 2023
052757e
add support for setting event handlers via HTML and Script
yhy0217 Apr 4, 2023
9e30cdb
small fix
yhy0217 Apr 4, 2023
82f7be3
Update src/map-feature.js
yhy0217 Apr 4, 2023
ff7f71a
Update src/map-feature.js
yhy0217 Apr 4, 2023
22d0f42
bug fixing, refactoring, support for mapFeature.addEventListener
yhy0217 Apr 5, 2023
2d538a5
fix bug that map-coordinates cannot be changed twice
yhy0217 Apr 5, 2023
7ef8ea0
add zoom to link in popup, make a connection that allows the Leaflet …
yhy0217 Apr 11, 2023
f9d4147
resolve failing tests
yhy0217 Apr 11, 2023
b5c53fd
zoomTo link bug fixing 1
yhy0217 Apr 14, 2023
466ed4d
add min and max attributes, modify zoomTo method
yhy0217 Apr 17, 2023
fd8049d
add 'options' parameter to focus() method
yhy0217 Apr 17, 2023
d0f0c66
close 821, localize zoom to here link in popup
yhy0217 Apr 17, 2023
9cc2293
Merge branch 'main' into mapFeatureDev
yhy0217 Apr 17, 2023
4c509b5
Add Man With Two Hats to index.html
prushforth Apr 18, 2023
8d92323
update outdated comment for mapml2geojson method
AliyanH Apr 18, 2023
bcbf897
Merge branch 'mapFeatureDev' of https://github.com/yhy0217/Web-Map-Cu…
AliyanH Apr 18, 2023
c558dce
bug fixing, add comments
yhy0217 Apr 18, 2023
22b15ad
make _handlefocus only handle keyboardEvent
yhy0217 Apr 19, 2023
853d399
make _handlefocus only handle keyboardEvent, cont.
yhy0217 Apr 19, 2023
004b439
remove unnecessary _clampZoom in FeatureLayer.js
yhy0217 Apr 19, 2023
66d7b3b
Merge branch 'mapFeatureDev' of https://github.com/yhy0217/Web-Map-Cu…
yhy0217 Apr 19, 2023
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
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = function(grunt) {
'dist/mapml-viewer.js': ['src/mapml-viewer.js'],
'dist/DOMTokenList.js': ['src/mapml/utils/DOMTokenList.js'],
'dist/map-caption.js': ['src/map-caption.js'],
'dist/map-feature.js': ['src/map-feature.js'],
'dist/map-area.js': ['src/map-area.js'],
'dist/layer.js': ['src/layer.js'],
'dist/leaflet.js': ['dist/leaflet-src.js',
Expand Down
49 changes: 49 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,55 @@
<mapml-viewer projection="CBMTILE" zoom="2" lat="45" lon="-90" controls controlslist="geolocation">
<map-caption>A pleasing map of Canada</map-caption>
<layer- label="CBMT" src="https://geogratis.gc.ca/mapml/en/cbmtile/cbmt/" checked></layer->
<layer- label="Hat Guy" checked>
<map-meta name="projection" content="CBMTILE"></map-meta>
<map-feature id="twohats" zoom="15" class="twohats">
<map-properties>
<table>
<tr>
<th>code</th>
<td>1200020</td>
</tr>
<tr>
<th>accuracy</th>
<td>26</td>
</tr>
<tr>
<th>valdate</th>
<td>1995</td>
</tr>
<tr>
<th>image</th>
<td><a href="https://www.veterans.gc.ca/eng/remembrance/memorials/national-inventory-canadian-memorials/details/9304">
<img src="https://www.veterans.gc.ca/images/remembrance/memorials/national-inventory-canadian-memorials/mem/35059-173a.jpg" width="60" height="60"/>
</a>
</td>
</tr>
<tr>
<th>theme</th>
<td>FO</td>
</tr>
<tr>
<th>type</th>
<td>2</td>
</tr>
<tr>
<th>elevation</th>
<td>61</td>
</tr>
<tr>
<th>altiaccu</th>
<td>5</td>
</tr>
</table>
</map-properties>
<map-geometry cs="gcrs">
<map-point>
<map-coordinates>-75.705278 45.397778</map-coordinates>
</map-point>
</map-geometry>
</map-feature>
</layer->
</mapml-viewer>
</body>
</html>
106 changes: 55 additions & 51 deletions src/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@ export class MapLayer extends HTMLElement {
set src(val) {
if (val) {
this.setAttribute('src', val);
if (this._layer) {
let oldOpacity = this.opacity;
// go through the same sequence as if the layer had been removed from
// the DOM and re-attached with a new URL source.
this.disconnectedCallback();
var base = this.baseURI ? this.baseURI : document.baseURI;
this._layer = M.mapMLLayer(val ? (new URL(val, base)).href: null, this);
this._layer.on('extentload', this._onLayerExtentLoad, this);
this._setUpEvents();
if (this.parentNode) {
this.connectedCallback();
}
this.opacity = oldOpacity;
}
}
}
get label() {
Expand Down Expand Up @@ -82,6 +68,10 @@ export class MapLayer extends HTMLElement {
// to the layer being removed with the _onLayerChange execution
// that is set up in _attached:
if(this.hasAttribute("data-moving")) return;
this._onRemove();
}

_onRemove() {
this._removeEvents();
if (this._layer._map) {
this._layer._map.removeLayer(this._layer);
Expand All @@ -90,11 +80,23 @@ export class MapLayer extends HTMLElement {
if (this._layerControl && !this.hidden) {
this._layerControl.removeLayer(this._layer);
}

if (this.shadowRoot) {
this.shadowRoot.innerHTML = '';
}
}

connectedCallback() {
//creates listener that waits for createmap event, this allows for delayed builds of maps
//this allows a safeguard for the case where loading a custom TCRS takes longer than loading mapml-viewer.js/web-map.js
if(this.hasAttribute("data-moving")) return;
this._onAdd();
}

_onAdd() {
if(this.getAttribute('src') && !this.shadowRoot) {
this.attachShadow({mode: 'open'});
}
this.parentNode.addEventListener('createmap', ()=>{
this._ready();
// if the map has been attached, set this layer up wrt Leaflet map
Expand All @@ -108,6 +110,7 @@ export class MapLayer extends HTMLElement {
//if map is already created then dispatch createmap event, allowing layer to be built
if(this.parentNode._map)this.parentNode.dispatchEvent(new CustomEvent('createmap'));
}

adoptedCallback() {
// console.log('Custom map element moved to new page.');
}
Expand Down Expand Up @@ -148,7 +151,24 @@ export class MapLayer extends HTMLElement {
this.opacity = newValue;
}
break;
case 'src':
if (oldValue !== newValue && this._layer) {
this._reload();
// the original inline content will not be removed
// but has NO EFFECT and works as a fallback
}
}
}
// re-load the layer element when the src attribute is changed
_reload() {
let oldOpacity = this.opacity;
// go through the same sequence as if the layer had been removed from
// the DOM and re-attached with a new URL source.
this._onRemove();
if (this.isConnected) {
this._onAdd();
}
this.opacity = oldOpacity;
}
_onLayerExtentLoad(e) {
// the mapml document associated to this layer can in theory contain many
Expand Down Expand Up @@ -327,46 +347,30 @@ export class MapLayer extends HTMLElement {
zoomTo() {
if(!this.extent) return;
let map = this._layer._map,
tL = this.extent.topLeft.pcrs,
bR = this.extent.bottomRight.pcrs,
layerBounds = L.bounds(L.point(tL.horizontal, tL.vertical), L.point(bR.horizontal, bR.vertical)),
center = map.options.crs.unproject(layerBounds.getCenter(true)),
newZoom = map.getZoom();
tL = this.extent.topLeft.pcrs,
bR = this.extent.bottomRight.pcrs,
layerBounds = L.bounds(L.point(tL.horizontal, tL.vertical), L.point(bR.horizontal, bR.vertical)),
center = map.options.crs.unproject(layerBounds.getCenter(true));

let maxZoom = this.extent.zoom.maxZoom, minZoom = this.extent.zoom.minZoom;

let scale = map.options.crs.scale(newZoom),
mapCenterTCRS = map.options.crs.transformation.transform(layerBounds.getCenter(true), scale);

let mapHalf = map.getSize().divideBy(2),
mapTlNew = mapCenterTCRS.subtract(mapHalf).round(),
mapBrNew = mapCenterTCRS.add(mapHalf).round();

let mapTlPCRSNew = M.pixelToPCRSPoint(mapTlNew, newZoom, map.options.projection),
mapBrPCRSNew = M.pixelToPCRSPoint(mapBrNew, newZoom, map.options.projection);

let mapPCRS = L.bounds(mapTlPCRSNew, mapBrPCRSNew);

let zOffset = mapPCRS.contains(layerBounds) ? 1 : -1;

while((zOffset === -1 && !(mapPCRS.contains(layerBounds)) && (newZoom - 1) >= minZoom) ||
(zOffset === 1 && mapPCRS.contains(layerBounds) && (newZoom + 1) <= maxZoom)) {
newZoom += zOffset;

scale = map.options.crs.scale(newZoom);
mapCenterTCRS = map.options.crs.transformation.transform(layerBounds.getCenter(true), scale);

mapTlNew = mapCenterTCRS.subtract(mapHalf).round();
mapBrNew = mapCenterTCRS.add(mapHalf).round();
mapTlPCRSNew = M.pixelToPCRSPoint(mapTlNew, newZoom, map.options.projection);
mapBrPCRSNew = M.pixelToPCRSPoint(mapBrNew, newZoom, map.options.projection);

mapPCRS = L.bounds(mapTlPCRSNew, mapBrPCRSNew);
}
if(zOffset === 1 && newZoom - 1 >= 0) newZoom--;
map.setView(center, newZoom, {animate: false});
let maxZoom = this.extent.zoom.maxZoom,
minZoom = this.extent.zoom.minZoom;
map.setView(center, M.getMaxZoom(layerBounds, map, minZoom, maxZoom), {animate: false});
}
mapml2geojson(options = {}){
return M.mapml2geojson(this, options);
}
pasteFeature(feature) {
switch(typeof feature) {
case "string":
feature.trim();
if (feature.slice(0,12) === "<map-feature" && feature.slice(-14) === "</map-feature>") {
this.insertAdjacentHTML("beforeend", feature);
}
break;
case "object":
if (feature.nodeName.toUpperCase() === 'MAP-FEATURE') {
this.appendChild(feature);
}
}
}
}
Loading